diff options
author | red-001 <red-001@outlook.ie> | 2018-01-04 07:21:12 +0000 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2018-01-04 08:21:12 +0100 |
commit | 30821ad8deb42728fbba9de60dda31033f70aaac (patch) | |
tree | 93e98b7699736fb98244b3bb586413bb1ed9d277 /src/script/cpp_api/s_base.cpp | |
parent | e7396a0c5060eccf3d4aea9b83647e1d02df308b (diff) | |
download | minetest-30821ad8deb42728fbba9de60dda31033f70aaac.tar.gz minetest-30821ad8deb42728fbba9de60dda31033f70aaac.tar.bz2 minetest-30821ad8deb42728fbba9de60dda31033f70aaac.zip |
[CSM] Don't load the IO library. (#6087)
* [CSM] Don't load the IO library.
* Rename the function to match the Lua API function name and add a missing `const`
* Add a comment to explain some strange code and fix the other issues pointed out by shadowninja.
Diffstat (limited to 'src/script/cpp_api/s_base.cpp')
-rw-r--r-- | src/script/cpp_api/s_base.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index c0d9a4f10..1decb836d 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -71,7 +71,8 @@ public: ScriptApiBase */ -ScriptApiBase::ScriptApiBase() +ScriptApiBase::ScriptApiBase(ScriptingType type): + m_type(type) { #ifdef SCRIPTAPI_LOCK_DEBUG m_lock_recursion_count = 0; @@ -82,7 +83,10 @@ ScriptApiBase::ScriptApiBase() lua_atpanic(m_luastack, &luaPanic); - luaL_openlibs(m_luastack); + if (m_type == ScriptingType::Client) + clientOpenLibs(m_luastack); + else + luaL_openlibs(m_luastack); // Make the ScriptApiBase* accessible to ModApiBase lua_pushlightuserdata(m_luastack, this); @@ -106,7 +110,10 @@ ScriptApiBase::ScriptApiBase() lua_newtable(m_luastack); lua_setglobal(m_luastack, "core"); - lua_pushstring(m_luastack, DIR_DELIM); + if (m_type == ScriptingType::Client) + lua_pushstring(m_luastack, "/"); + else + lua_pushstring(m_luastack, DIR_DELIM); lua_setglobal(m_luastack, "DIR_DELIM"); lua_pushstring(m_luastack, porting::getPlatformName()); @@ -128,6 +135,28 @@ int ScriptApiBase::luaPanic(lua_State *L) return 0; } +void ScriptApiBase::clientOpenLibs(lua_State *L) +{ + static const std::vector<std::pair<std::string, lua_CFunction>> m_libs = { + { "", luaopen_base }, + { LUA_LOADLIBNAME, luaopen_package }, + { LUA_TABLIBNAME, luaopen_table }, + { LUA_OSLIBNAME, luaopen_os }, + { LUA_STRLIBNAME, luaopen_string }, + { LUA_MATHLIBNAME, luaopen_math }, + { LUA_DBLIBNAME, luaopen_debug }, +#if USE_LUAJIT + { LUA_JITLIBNAME, luaopen_jit }, +#endif + }; + + for (const std::pair<std::string, lua_CFunction> &lib : m_libs) { + lua_pushcfunction(L, lib.second); + lua_pushstring(L, lib.first.c_str()); + lua_call(L, 1, 0); + } +} + void ScriptApiBase::loadMod(const std::string &script_path, const std::string &mod_name) { |