Changeset View
Changeset View
Standalone View
Standalone View
contrib/lua/src/lapi.c
/* | /* | ||||
** $Id: lapi.c,v 2.259 2016/02/29 14:27:14 roberto Exp $ | ** $Id: lapi.c,v 2.259.1.2 2017/12/06 18:35:12 roberto Exp $ | ||||
** Lua API | ** Lua API | ||||
** See Copyright Notice in lua.h | ** See Copyright Notice in lua.h | ||||
*/ | */ | ||||
#define lapi_c | #define lapi_c | ||||
#define LUA_CORE | #define LUA_CORE | ||||
#include "lprefix.h" | #include "lprefix.h" | ||||
▲ Show 20 Lines • Show All 517 Lines • ▼ Show 20 Lines | LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) { | ||||
return ret; | return ret; | ||||
} | } | ||||
LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | ||||
lua_lock(L); | lua_lock(L); | ||||
if (n == 0) { | if (n == 0) { | ||||
setfvalue(L->top, fn); | setfvalue(L->top, fn); | ||||
api_incr_top(L); | |||||
} | } | ||||
else { | else { | ||||
CClosure *cl; | CClosure *cl; | ||||
api_checknelems(L, n); | api_checknelems(L, n); | ||||
api_check(L, n <= MAXUPVAL, "upvalue index too large"); | api_check(L, n <= MAXUPVAL, "upvalue index too large"); | ||||
cl = luaF_newCclosure(L, n); | cl = luaF_newCclosure(L, n); | ||||
cl->f = fn; | cl->f = fn; | ||||
L->top -= n; | L->top -= n; | ||||
while (n--) { | while (n--) { | ||||
setobj2n(L, &cl->upvalue[n], L->top + n); | setobj2n(L, &cl->upvalue[n], L->top + n); | ||||
/* does not need barrier because closure is white */ | /* does not need barrier because closure is white */ | ||||
} | } | ||||
setclCvalue(L, L->top, cl); | setclCvalue(L, L->top, cl); | ||||
} | |||||
api_incr_top(L); | api_incr_top(L); | ||||
luaC_checkGC(L); | luaC_checkGC(L); | ||||
} | |||||
lua_unlock(L); | lua_unlock(L); | ||||
} | } | ||||
LUA_API void lua_pushboolean (lua_State *L, int b) { | LUA_API void lua_pushboolean (lua_State *L, int b) { | ||||
lua_lock(L); | lua_lock(L); | ||||
setbvalue(L->top, (b != 0)); /* ensure that true is 1 */ | setbvalue(L->top, (b != 0)); /* ensure that true is 1 */ | ||||
api_incr_top(L); | api_incr_top(L); | ||||
▲ Show 20 Lines • Show All 739 Lines • Show Last 20 Lines |