diff options
author | Mike Pall <mike> | 2013-09-02 01:55:07 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2013-09-02 01:55:07 +0200 |
commit | 8a9519a5f442726bafa954f5beecf67b0df3cf45 (patch) | |
tree | 7c178b8db43eeee2b908a90edd72b2d1b411087e | |
parent | 4dce22c40d38dd7dc3d05cc383ddf004fb1f92c4 (diff) | |
download | luajit-8a9519a5f442726bafa954f5beecf67b0df3cf45.tar.gz luajit-8a9519a5f442726bafa954f5beecf67b0df3cf45.tar.bz2 luajit-8a9519a5f442726bafa954f5beecf67b0df3cf45.zip |
Add internal API to add sub-modules to package.preload.
-rw-r--r-- | src/lj_lib.c | 10 | ||||
-rw-r--r-- | src/lj_lib.h | 2 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/lj_lib.c b/src/lj_lib.c index bdbaba1d..df66ed51 100644 --- a/src/lj_lib.c +++ b/src/lj_lib.c | |||
@@ -148,6 +148,16 @@ void lj_lib_register(lua_State *L, const char *libname, | |||
148 | } | 148 | } |
149 | } | 149 | } |
150 | 150 | ||
151 | void lj_lib_prereg(lua_State *L, const char *name, lua_CFunction f, GCtab *env) | ||
152 | { | ||
153 | luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", 4); | ||
154 | lua_pushcfunction(L, f); | ||
155 | /* NOBARRIER: The function is new (marked white). */ | ||
156 | setgcref(funcV(L->top-1)->c.env, obj2gco(env)); | ||
157 | lua_setfield(L, -2, name); | ||
158 | L->top--; | ||
159 | } | ||
160 | |||
151 | /* -- Type checks --------------------------------------------------------- */ | 161 | /* -- Type checks --------------------------------------------------------- */ |
152 | 162 | ||
153 | TValue *lj_lib_checkany(lua_State *L, int narg) | 163 | TValue *lj_lib_checkany(lua_State *L, int narg) |
diff --git a/src/lj_lib.h b/src/lj_lib.h index 463bfb60..f9377bad 100644 --- a/src/lj_lib.h +++ b/src/lj_lib.h | |||
@@ -89,6 +89,8 @@ static LJ_AINLINE GCfunc *lj_lib_pushcc(lua_State *L, lua_CFunction f, | |||
89 | 89 | ||
90 | LJ_FUNC void lj_lib_register(lua_State *L, const char *libname, | 90 | LJ_FUNC void lj_lib_register(lua_State *L, const char *libname, |
91 | const uint8_t *init, const lua_CFunction *cf); | 91 | const uint8_t *init, const lua_CFunction *cf); |
92 | LJ_FUNC void lj_lib_prereg(lua_State *L, const char *name, lua_CFunction f, | ||
93 | GCtab *env); | ||
92 | 94 | ||
93 | /* Library init data tags. */ | 95 | /* Library init data tags. */ |
94 | #define LIBINIT_LENMASK 0x3f | 96 | #define LIBINIT_LENMASK 0x3f |