mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-08 07:34:07 +00:00
Add support for deferred library loads to lib_init.c.
This commit is contained in:
parent
443c542e26
commit
4ed8a1931b
@ -11,7 +11,7 @@
|
|||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
#include "lualib.h"
|
#include "lualib.h"
|
||||||
|
|
||||||
static const luaL_Reg lualibs[] = {
|
static const luaL_Reg lj_lib_load[] = {
|
||||||
{ "", luaopen_base },
|
{ "", luaopen_base },
|
||||||
{ LUA_LOADLIBNAME, luaopen_package },
|
{ LUA_LOADLIBNAME, luaopen_package },
|
||||||
{ LUA_TABLIBNAME, luaopen_table },
|
{ LUA_TABLIBNAME, luaopen_table },
|
||||||
@ -25,13 +25,24 @@ static const luaL_Reg lualibs[] = {
|
|||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const luaL_Reg lj_lib_preload[] = {
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
LUALIB_API void luaL_openlibs(lua_State *L)
|
LUALIB_API void luaL_openlibs(lua_State *L)
|
||||||
{
|
{
|
||||||
const luaL_Reg *lib = lualibs;
|
const luaL_Reg *lib;
|
||||||
for (; lib->func; lib++) {
|
for (lib = lj_lib_load; lib->func; lib++) {
|
||||||
lua_pushcfunction(L, lib->func);
|
lua_pushcfunction(L, lib->func);
|
||||||
lua_pushstring(L, lib->name);
|
lua_pushstring(L, lib->name);
|
||||||
lua_call(L, 1, 0);
|
lua_call(L, 1, 0);
|
||||||
}
|
}
|
||||||
|
luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD",
|
||||||
|
sizeof(lj_lib_preload)/sizeof(lj_lib_preload[0])-1);
|
||||||
|
for (lib = lj_lib_preload; lib->func; lib++) {
|
||||||
|
lua_pushcfunction(L, lib->func);
|
||||||
|
lua_setfield(L, -2, lib->name);
|
||||||
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,7 +499,7 @@ LUALIB_API int luaopen_package(lua_State *L)
|
|||||||
lua_setfield(L, -2, "config");
|
lua_setfield(L, -2, "config");
|
||||||
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);
|
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);
|
||||||
lua_setfield(L, -2, "loaded");
|
lua_setfield(L, -2, "loaded");
|
||||||
lua_newtable(L);
|
luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", 4);
|
||||||
lua_setfield(L, -2, "preload");
|
lua_setfield(L, -2, "preload");
|
||||||
lua_pushvalue(L, LUA_GLOBALSINDEX);
|
lua_pushvalue(L, LUA_GLOBALSINDEX);
|
||||||
luaL_register(L, NULL, package_global);
|
luaL_register(L, NULL, package_global);
|
||||||
|
Loading…
Reference in New Issue
Block a user