diff options
author | Mike Pall <mike> | 2013-11-25 15:17:44 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2013-11-25 15:17:44 +0100 |
commit | c378f7dbb882068d1ae06edc8e7049fb1907db2d (patch) | |
tree | 2a99541a907ac84a3be740ef67dfadb640832dce /src/lj_lib.c | |
parent | a8c3862d63ad60acf07252304bbfd74bce35371c (diff) | |
download | luajit-c378f7dbb882068d1ae06edc8e7049fb1907db2d.tar.gz luajit-c378f7dbb882068d1ae06edc8e7049fb1907db2d.tar.bz2 luajit-c378f7dbb882068d1ae06edc8e7049fb1907db2d.zip |
Abstract out post-registration handling of pre-registered modules.
Diffstat (limited to 'src/lj_lib.c')
-rw-r--r-- | src/lj_lib.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/lj_lib.c b/src/lj_lib.c index df66ed51..aea96120 100644 --- a/src/lj_lib.c +++ b/src/lj_lib.c | |||
@@ -148,6 +148,17 @@ void lj_lib_register(lua_State *L, const char *libname, | |||
148 | } | 148 | } |
149 | } | 149 | } |
150 | 150 | ||
151 | /* Push internal function on the stack. */ | ||
152 | GCfunc *lj_lib_pushcc(lua_State *L, lua_CFunction f, int id, int n) | ||
153 | { | ||
154 | GCfunc *fn; | ||
155 | lua_pushcclosure(L, f, n); | ||
156 | fn = funcV(L->top-1); | ||
157 | fn->c.ffid = (uint8_t)id; | ||
158 | setmref(fn->c.pc, &G(L)->bc_cfunc_int); | ||
159 | return fn; | ||
160 | } | ||
161 | |||
151 | void lj_lib_prereg(lua_State *L, const char *name, lua_CFunction f, GCtab *env) | 162 | void lj_lib_prereg(lua_State *L, const char *name, lua_CFunction f, GCtab *env) |
152 | { | 163 | { |
153 | luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", 4); | 164 | luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", 4); |
@@ -158,6 +169,16 @@ void lj_lib_prereg(lua_State *L, const char *name, lua_CFunction f, GCtab *env) | |||
158 | L->top--; | 169 | L->top--; |
159 | } | 170 | } |
160 | 171 | ||
172 | int lj_lib_postreg(lua_State *L, lua_CFunction cf, int id, const char *name) | ||
173 | { | ||
174 | GCfunc *fn = lj_lib_pushcf(L, cf, id); | ||
175 | GCtab *t = tabref(curr_func(L)->c.env); /* Reference to parent table. */ | ||
176 | setfuncV(L, lj_tab_setstr(L, t, lj_str_newz(L, name)), fn); | ||
177 | lj_gc_anybarriert(L, t); | ||
178 | setfuncV(L, L->top++, fn); | ||
179 | return 1; | ||
180 | } | ||
181 | |||
161 | /* -- Type checks --------------------------------------------------------- */ | 182 | /* -- Type checks --------------------------------------------------------- */ |
162 | 183 | ||
163 | TValue *lj_lib_checkany(lua_State *L, int narg) | 184 | TValue *lj_lib_checkany(lua_State *L, int narg) |