diff options
Diffstat (limited to 'src/state.cpp')
-rw-r--r-- | src/state.cpp | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/src/state.cpp b/src/state.cpp index 9cd7343..b50d135 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
@@ -57,32 +57,37 @@ namespace { | |||
57 | 57 | ||
58 | namespace local { | 58 | namespace local { |
59 | static luaL_Reg const sLibs[] = { | 59 | static luaL_Reg const sLibs[] = { |
60 | { "base", nullptr }, // ignore "base" (already acquired it) | 60 | { "base", nullptr }, // ignore "base" is always valid, but opened separately |
61 | |||
62 | #if LUA_VERSION_NUM == 502 || LUA_VERSION_NUM == 503 | ||
63 | { LUA_BITLIBNAME, luaopen_bit32 }, // active in Lua 5.2, replaced with an error-throwing loader in Lua 5.3, gone after. | ||
64 | #endif // LUA_VERSION_NUM == 502 || LUA_VERSION_NUM == 503 | ||
65 | |||
61 | #if LUA_VERSION_NUM >= 502 | 66 | #if LUA_VERSION_NUM >= 502 |
62 | #ifdef luaopen_bit32 | ||
63 | { LUA_BITLIBNAME, luaopen_bit32 }, | ||
64 | #endif | ||
65 | { LUA_COLIBNAME, luaopen_coroutine }, // Lua 5.2: coroutine is no longer a part of base! | 67 | { LUA_COLIBNAME, luaopen_coroutine }, // Lua 5.2: coroutine is no longer a part of base! |
66 | #else // LUA_VERSION_NUM | ||
67 | { LUA_COLIBNAME, nullptr }, // Lua 5.1: part of base package | ||
68 | #endif // LUA_VERSION_NUM | 68 | #endif // LUA_VERSION_NUM |
69 | |||
69 | { LUA_DBLIBNAME, luaopen_debug }, | 70 | { LUA_DBLIBNAME, luaopen_debug }, |
71 | |||
70 | #ifndef PLATFORM_XBOX // no os/io libs on xbox | 72 | #ifndef PLATFORM_XBOX // no os/io libs on xbox |
71 | { LUA_IOLIBNAME, luaopen_io }, | 73 | { LUA_IOLIBNAME, luaopen_io }, |
72 | { LUA_OSLIBNAME, luaopen_os }, | 74 | { LUA_OSLIBNAME, luaopen_os }, |
73 | #endif // PLATFORM_XBOX | 75 | #endif // PLATFORM_XBOX |
76 | |||
74 | { LUA_LOADLIBNAME, luaopen_package }, | 77 | { LUA_LOADLIBNAME, luaopen_package }, |
75 | { LUA_MATHLIBNAME, luaopen_math }, | 78 | { LUA_MATHLIBNAME, luaopen_math }, |
76 | { LUA_STRLIBNAME, luaopen_string }, | 79 | { LUA_STRLIBNAME, luaopen_string }, |
77 | { LUA_TABLIBNAME, luaopen_table }, | 80 | { LUA_TABLIBNAME, luaopen_table }, |
81 | |||
78 | #if LUA_VERSION_NUM >= 503 | 82 | #if LUA_VERSION_NUM >= 503 |
79 | { LUA_UTF8LIBNAME, luaopen_utf8 }, | 83 | { LUA_UTF8LIBNAME, luaopen_utf8 }, |
80 | #endif | 84 | #endif // LUA_VERSION_NUM >= 503 |
85 | |||
81 | #if LUAJIT_FLAVOR() != 0 // building against LuaJIT headers, add some LuaJIT-specific libs | 86 | #if LUAJIT_FLAVOR() != 0 // building against LuaJIT headers, add some LuaJIT-specific libs |
82 | { LUA_BITLIBNAME, luaopen_bit }, | 87 | { LUA_BITLIBNAME, luaopen_bit }, |
83 | { LUA_FFILIBNAME, luaopen_ffi }, | 88 | { LUA_FFILIBNAME, luaopen_ffi }, |
84 | { LUA_JITLIBNAME, luaopen_jit }, | 89 | { LUA_JITLIBNAME, luaopen_jit }, |
85 | #endif // LUAJIT_FLAVOR() | 90 | #endif // LUAJIT_FLAVOR() != 0 |
86 | 91 | ||
87 | { kLanesCoreLibName, require_lanes_core } // So that we can open it like any base library (possible since we have access to the init function) | 92 | { kLanesCoreLibName, require_lanes_core } // So that we can open it like any base library (possible since we have access to the init function) |
88 | }; | 93 | }; |
@@ -312,6 +317,21 @@ namespace state { | |||
312 | } | 317 | } |
313 | 318 | ||
314 | // ############################################################################################# | 319 | // ############################################################################################# |
320 | |||
321 | // for internal use only: tell lanes.lua which base libraries are actually supported internally | ||
322 | LUAG_FUNC(supported_libs) | ||
323 | { | ||
324 | STACK_CHECK_START_REL(L_, 0); | ||
325 | lua_newtable(L_); // L_: out | ||
326 | for (luaL_Reg const& _entry : local::sLibs) { | ||
327 | lua_pushboolean(L_, 1); // L_: out true | ||
328 | luaG_setfield(L_, -2, std::string_view{ _entry.name }); // out[name] = true // L_: out | ||
329 | } | ||
330 | STACK_CHECK(L_, 1); | ||
331 | return 1; | ||
332 | } | ||
333 | |||
334 | // ############################################################################################# | ||
315 | // ############################################################################################# | 335 | // ############################################################################################# |
316 | } // namespace state | 336 | } // namespace state |
317 | // ################################################################################################# | 337 | // ################################################################################################# |