]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
FFI: Register the FFI library as a loaded module in luaopen_ffi().
authorMike Pall <mike>
Tue, 5 Apr 2011 23:31:21 +0000 (01:31 +0200)
committerMike Pall <mike>
Tue, 5 Apr 2011 23:31:21 +0000 (01:31 +0200)
Allows loading it on startup like other libraries in lib_init.c.

src/lib_ffi.c
src/lj_lex.c

index 674bbf00464fea2db442e112ea03be7ad7a0eea7..cb001ae94d594c8abc5b4847ac190e4ea7d5cb9c 100644 (file)
@@ -576,6 +576,17 @@ static GCtab *ffi_finalizer(lua_State *L)
   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)
 {
   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_ARCH_NAME);
   LJ_LIB_REG(L, NULL, ffi);  /* Note: no global "ffi" created! */
+  ffi_register_module(L);
   return 1;
 }
 
index bc029761331ba873fb1c8fd802361f8248709d44..acfcb921799e135755a721656b6c5ebf5ce3d9cf 100644 (file)
@@ -89,14 +89,7 @@ static void inclinenumber(LexState *ls)
 static void lex_loadffi(lua_State *L)
 {
   ptrdiff_t oldtop = savestack(L, L->top);
-  cTValue *tmp;
   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);
 }