From: Mike Pall Date: Sun, 1 Sep 2013 23:55:07 +0000 (+0200) Subject: Add internal API to add sub-modules to package.preload. X-Git-Tag: v2.1.0-beta1~194 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a9519a5f442726bafa954f5beecf67b0df3cf45;p=thirdparty%2FLuaJIT.git Add internal API to add sub-modules to package.preload. --- 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, } } +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 --------------------------------------------------------- */ 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, LJ_FUNC void lj_lib_register(lua_State *L, const char *libname, 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. */ #define LIBINIT_LENMASK 0x3f