diff options
author | Mike Pall <mike> | 2011-04-06 01:31:21 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2011-04-06 01:31:21 +0200 |
commit | ee644872e3d60852cdb7f73766dc4e303b28e708 (patch) | |
tree | 3b5deadca6bc2eea75b87df6f4e9089b7b38fb28 | |
parent | 734e96fa054912b44cd810ab81ec61320e5dc3d3 (diff) | |
download | luajit-ee644872e3d60852cdb7f73766dc4e303b28e708.tar.gz luajit-ee644872e3d60852cdb7f73766dc4e303b28e708.tar.bz2 luajit-ee644872e3d60852cdb7f73766dc4e303b28e708.zip |
FFI: Register the FFI library as a loaded module in luaopen_ffi().
Allows loading it on startup like other libraries in lib_init.c.
-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 | ||