diff options
| -rw-r--r-- | src/lib_ffi.c | 12 | ||||
| -rw-r--r-- | src/lj_lex.c | 7 |
2 files changed, 12 insertions, 7 deletions
diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 674bbf00..cb001ae9 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c | |||
| @@ -576,6 +576,17 @@ static GCtab *ffi_finalizer(lua_State *L) | |||
| 576 | return t; | 576 | return t; |
| 577 | } | 577 | } |
| 578 | 578 | ||
| 579 | /* Register FFI module as loaded. */ | ||
| 580 | static void ffi_register_module(lua_State *L) | ||
| 581 | { | ||
| 582 | cTValue *tmp = lj_tab_getstr(tabV(registry(L)), lj_str_newlit(L, "_LOADED")); | ||
| 583 | if (tmp && tvistab(tmp)) { | ||
| 584 | GCtab *t = tabV(tmp); | ||
| 585 | copyTV(L, lj_tab_setstr(L, t, lj_str_newlit(L, LUA_FFILIBNAME)), L->top-1); | ||
| 586 | lj_gc_anybarriert(L, t); | ||
| 587 | } | ||
| 588 | } | ||
| 589 | |||
| 579 | LUALIB_API int luaopen_ffi(lua_State *L) | 590 | LUALIB_API int luaopen_ffi(lua_State *L) |
| 580 | { | 591 | { |
| 581 | CTState *cts = lj_ctype_init(L); | 592 | CTState *cts = lj_ctype_init(L); |
| @@ -588,6 +599,7 @@ LUALIB_API int luaopen_ffi(lua_State *L) | |||
| 588 | lua_pushliteral(L, LJ_OS_NAME); | 599 | lua_pushliteral(L, LJ_OS_NAME); |
| 589 | lua_pushliteral(L, LJ_ARCH_NAME); | 600 | lua_pushliteral(L, LJ_ARCH_NAME); |
| 590 | LJ_LIB_REG(L, NULL, ffi); /* Note: no global "ffi" created! */ | 601 | LJ_LIB_REG(L, NULL, ffi); /* Note: no global "ffi" created! */ |
| 602 | ffi_register_module(L); | ||
| 591 | return 1; | 603 | return 1; |
| 592 | } | 604 | } |
| 593 | 605 | ||
diff --git a/src/lj_lex.c b/src/lj_lex.c index bc029761..acfcb921 100644 --- a/src/lj_lex.c +++ b/src/lj_lex.c | |||
| @@ -89,14 +89,7 @@ static void inclinenumber(LexState *ls) | |||
| 89 | static void lex_loadffi(lua_State *L) | 89 | static void lex_loadffi(lua_State *L) |
| 90 | { | 90 | { |
| 91 | ptrdiff_t oldtop = savestack(L, L->top); | 91 | ptrdiff_t oldtop = savestack(L, L->top); |
| 92 | cTValue *tmp; | ||
| 93 | luaopen_ffi(L); | 92 | luaopen_ffi(L); |
| 94 | tmp = lj_tab_getstr(tabV(registry(L)), lj_str_newlit(L, "_LOADED")); | ||
| 95 | if (tmp && tvistab(tmp)) { | ||
| 96 | GCtab *t = tabV(tmp); | ||
| 97 | copyTV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "ffi")), L->top-1); | ||
| 98 | lj_gc_anybarriert(L, t); | ||
| 99 | } | ||
| 100 | L->top = restorestack(L, oldtop); | 93 | L->top = restorestack(L, oldtop); |
| 101 | } | 94 | } |
| 102 | 95 | ||
