1/*
2** Library initialization.
3** Copyright (C) 2005-2021 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
18static 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 { NULL, NULL }
30};
31
32static const luaL_Reg lj_lib_preload[] = {
33#if LJ_HASFFI
34 { LUA_FFILIBNAME, luaopen_ffi },
35#endif
36 { NULL, NULL }
37};
38
39LUALIB_API void luaL_openlibs(lua_State *L)
40{
41 const luaL_Reg *lib;
42 for (lib = lj_lib_load; lib->func; lib++) {
43 lua_pushcfunction(L, lib->func);
44 lua_pushstring(L, lib->name);
45 lua_call(L, 1, 0);
46 }
47 luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD",
48 sizeof(lj_lib_preload)/sizeof(lj_lib_preload[0])-1);
49 for (lib = lj_lib_preload; lib->func; lib++) {
50 lua_pushcfunction(L, lib->func);
51 lua_setfield(L, -2, lib->name);
52 }
53 lua_pop(L, 1);
54}
55
56