| 1 |
/* |
| 2 |
** Library initialization. |
| 3 |
** Copyright (C) 2005-2025 Mike Pall. See Copyright Notice in luajit.h |
| 4 |
** |
| 5 |
** Major parts taken verbatim from the Lua interpreter. |
| 6 |
** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h |
| 7 |
*/ |
| 8 |
|
| 9 |
#define lib_init_c |
| 10 |
#define LUA_LIB |
| 11 |
|
| 12 |
#include "lua.h" |
| 13 |
#include "lauxlib.h" |
| 14 |
#include "lualib.h" |
| 15 |
|
| 16 |
#include "lj_arch.h" |
| 17 |
|
| 18 |
static const luaL_Reg lj_lib_load[] = { |
| 19 |
{ "", luaopen_base }, |
| 20 |
{ LUA_LOADLIBNAME, luaopen_package }, |
| 21 |
{ LUA_TABLIBNAME, luaopen_table }, |
| 22 |
{ LUA_IOLIBNAME, luaopen_io }, |
| 23 |
{ LUA_OSLIBNAME, luaopen_os }, |
| 24 |
{ LUA_STRLIBNAME, luaopen_string }, |
| 25 |
{ LUA_MATHLIBNAME, luaopen_math }, |
| 26 |
{ LUA_DBLIBNAME, luaopen_debug }, |
| 27 |
{ LUA_BITLIBNAME, luaopen_bit }, |
| 28 |
{ LUA_JITLIBNAME, luaopen_jit }, |
| 29 |
{ LUA_BITLIBNAME_32, luaopen_bit32 }, |
| 30 |
{ NULL, NULL } |
| 31 |
}; |
| 32 |
|
| 33 |
static const luaL_Reg lj_lib_preload[] = { |
| 34 |
#if LJ_HASFFI |
| 35 |
{ LUA_FFILIBNAME, luaopen_ffi }, |
| 36 |
#endif |
| 37 |
{ NULL, NULL } |
| 38 |
}; |
| 39 |
|
| 40 |
LUALIB_API void luaL_openlibs(lua_State *L) |
| 41 |
{ |
| 42 |
const luaL_Reg *lib; |
| 43 |
for (lib = lj_lib_load; lib->func; lib++) { |
| 44 |
lua_pushcfunction(L, lib->func); |
| 45 |
lua_pushstring(L, lib->name); |
| 46 |
lua_call(L, 1, 0); |
| 47 |
} |
| 48 |
luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", |
| 49 |
sizeof(lj_lib_preload)/sizeof(lj_lib_preload[0])-1); |
| 50 |
for (lib = lj_lib_preload; lib->func; lib++) { |
| 51 |
lua_pushcfunction(L, lib->func); |
| 52 |
lua_setfield(L, -2, lib->name); |
| 53 |
} |
| 54 |
lua_pop(L, 1); |
| 55 |
} |
| 56 |
|