ljx

FORK: LuaJIT with native 5.2 and 5.3 support
git clone https://git.neptards.moe/neptards/ljx.git
Log | Files | Refs | README

lib_init.c (1588B)


      1 /*
      2 ** Library initialization.
      3 ** Copyright (C) 2005-2016 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 #if LJ_53
     26   { LUA_UTF8LIBNAME,	luaopen_utf8 },
     27 #endif
     28   { LUA_MATHLIBNAME,	luaopen_math },
     29   { LUA_DBLIBNAME,	luaopen_debug },
     30   { LUA_BITLIBNAME,	luaopen_bit },
     31 #if !LJ_51
     32   { LUA_BIT32LIBNAME,	luaopen_bit32 },
     33 #endif
     34   { LUA_JITLIBNAME,	luaopen_jit },
     35   { NULL,		NULL }
     36 };
     37 
     38 static const luaL_Reg lj_lib_preload[] = {
     39 #if LJ_HASFFI
     40   { LUA_FFILIBNAME,	luaopen_ffi },
     41 #endif
     42   { NULL,		NULL }
     43 };
     44 
     45 LUALIB_API void luaL_openlibs(lua_State *L)
     46 {
     47   const luaL_Reg *lib;
     48   for (lib = lj_lib_load; lib->func; lib++) {
     49     luaL_requiref(L, lib->name, lib->func, 1);
     50     lua_pop(L, 1);  /* remove lib */
     51   }
     52   for (lib = lj_lib_preload; lib->func; lib++) {
     53     luaL_requiref(L, lib->name, lib->func, 0);
     54     lua_pop(L, 1);
     55   }
     56 #if 0
     57   luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD",
     58 		 sizeof(lj_lib_preload)/sizeof(lj_lib_preload[0])-1);
     59   for (lib = lj_lib_preload; lib->func; lib++) {
     60     lua_pushcfunction(L, lib->func);
     61     lua_setfield(L, -2, lib->name);
     62   }
     63   lua_pop(L, 1);
     64 #endif
     65 }
     66