mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
FFI: Register the FFI library as a loaded module in luaopen_ffi().
Allows loading it on startup like other libraries in lib_init.c.
This commit is contained in:
parent
734e96fa05
commit
ee644872e3
@ -576,6 +576,17 @@ static GCtab *ffi_finalizer(lua_State *L)
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Register FFI module as loaded. */
|
||||||
|
static void ffi_register_module(lua_State *L)
|
||||||
|
{
|
||||||
|
cTValue *tmp = lj_tab_getstr(tabV(registry(L)), lj_str_newlit(L, "_LOADED"));
|
||||||
|
if (tmp && tvistab(tmp)) {
|
||||||
|
GCtab *t = tabV(tmp);
|
||||||
|
copyTV(L, lj_tab_setstr(L, t, lj_str_newlit(L, LUA_FFILIBNAME)), L->top-1);
|
||||||
|
lj_gc_anybarriert(L, t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LUALIB_API int luaopen_ffi(lua_State *L)
|
LUALIB_API int luaopen_ffi(lua_State *L)
|
||||||
{
|
{
|
||||||
CTState *cts = lj_ctype_init(L);
|
CTState *cts = lj_ctype_init(L);
|
||||||
@ -588,6 +599,7 @@ LUALIB_API int luaopen_ffi(lua_State *L)
|
|||||||
lua_pushliteral(L, LJ_OS_NAME);
|
lua_pushliteral(L, LJ_OS_NAME);
|
||||||
lua_pushliteral(L, LJ_ARCH_NAME);
|
lua_pushliteral(L, LJ_ARCH_NAME);
|
||||||
LJ_LIB_REG(L, NULL, ffi); /* Note: no global "ffi" created! */
|
LJ_LIB_REG(L, NULL, ffi); /* Note: no global "ffi" created! */
|
||||||
|
ffi_register_module(L);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,14 +89,7 @@ static void inclinenumber(LexState *ls)
|
|||||||
static void lex_loadffi(lua_State *L)
|
static void lex_loadffi(lua_State *L)
|
||||||
{
|
{
|
||||||
ptrdiff_t oldtop = savestack(L, L->top);
|
ptrdiff_t oldtop = savestack(L, L->top);
|
||||||
cTValue *tmp;
|
|
||||||
luaopen_ffi(L);
|
luaopen_ffi(L);
|
||||||
tmp = lj_tab_getstr(tabV(registry(L)), lj_str_newlit(L, "_LOADED"));
|
|
||||||
if (tmp && tvistab(tmp)) {
|
|
||||||
GCtab *t = tabV(tmp);
|
|
||||||
copyTV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "ffi")), L->top-1);
|
|
||||||
lj_gc_anybarriert(L, t);
|
|
||||||
}
|
|
||||||
L->top = restorestack(L, oldtop);
|
L->top = restorestack(L, oldtop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user