Add internal API to add sub-modules to package.preload.

This commit is contained in:
Mike Pall 2013-09-02 01:55:07 +02:00
parent 4dce22c40d
commit 8a9519a5f4
2 changed files with 12 additions and 0 deletions

View File

@ -148,6 +148,16 @@ void lj_lib_register(lua_State *L, const char *libname,
} }
} }
void lj_lib_prereg(lua_State *L, const char *name, lua_CFunction f, GCtab *env)
{
luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", 4);
lua_pushcfunction(L, f);
/* NOBARRIER: The function is new (marked white). */
setgcref(funcV(L->top-1)->c.env, obj2gco(env));
lua_setfield(L, -2, name);
L->top--;
}
/* -- Type checks --------------------------------------------------------- */ /* -- Type checks --------------------------------------------------------- */
TValue *lj_lib_checkany(lua_State *L, int narg) TValue *lj_lib_checkany(lua_State *L, int narg)

View File

@ -89,6 +89,8 @@ static LJ_AINLINE GCfunc *lj_lib_pushcc(lua_State *L, lua_CFunction f,
LJ_FUNC void lj_lib_register(lua_State *L, const char *libname, LJ_FUNC void lj_lib_register(lua_State *L, const char *libname,
const uint8_t *init, const lua_CFunction *cf); const uint8_t *init, const lua_CFunction *cf);
LJ_FUNC void lj_lib_prereg(lua_State *L, const char *name, lua_CFunction f,
GCtab *env);
/* Library init data tags. */ /* Library init data tags. */
#define LIBINIT_LENMASK 0x3f #define LIBINIT_LENMASK 0x3f