From c4359ff65cd8e4e754442b9f2ef7051a8eaa4241 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Sun, 27 Apr 2014 21:02:48 -0400 Subject: Use "core" namespace internally --- src/script/cpp_api/s_base.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'src/script/cpp_api/s_base.cpp') diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index 1a172fd31..d27506fbe 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "lua_api/l_object.h" #include "serverobject.h" #include "debug.h" +#include "filesys.h" #include "log.h" #include "mods.h" #include "util/string.h" @@ -48,13 +49,13 @@ public: { // Store current modname in registry lua_pushstring(L, modname.c_str()); - lua_setfield(L, LUA_REGISTRYINDEX, "minetest_current_modname"); + lua_setfield(L, LUA_REGISTRYINDEX, "current_modname"); } ~ModNameStorer() { // Clear current modname in registry lua_pushnil(L); - lua_setfield(L, LUA_REGISTRYINDEX, "minetest_current_modname"); + lua_setfield(L, LUA_REGISTRYINDEX, "current_modname"); } }; @@ -72,6 +73,8 @@ ScriptApiBase::ScriptApiBase() m_luastack = luaL_newstate(); assert(m_luastack); + luaL_openlibs(m_luastack); + // Add and save an error handler lua_pushcfunction(m_luastack, script_error_handler); m_errorhandler = lua_gettop(m_luastack); @@ -88,6 +91,13 @@ ScriptApiBase::ScriptApiBase() lua_pop(m_luastack, 1); #endif + // Add basic globals + lua_newtable(m_luastack); + lua_setglobal(m_luastack, "core"); + + lua_pushstring(m_luastack, DIR_DELIM); + lua_setglobal(m_luastack, "DIR_DELIM"); + m_server = NULL; m_environment = NULL; m_guiengine = NULL; @@ -191,8 +201,8 @@ void ScriptApiBase::addObjectReference(ServerActiveObject *cobj) ObjectRef::create(L, cobj); // Puts ObjectRef (as userdata) on stack int object = lua_gettop(L); - // Get minetest.object_refs table - lua_getglobal(L, "minetest"); + // Get core.object_refs table + lua_getglobal(L, "core"); lua_getfield(L, -1, "object_refs"); luaL_checktype(L, -1, LUA_TTABLE); int objectstable = lua_gettop(L); @@ -208,8 +218,8 @@ void ScriptApiBase::removeObjectReference(ServerActiveObject *cobj) SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_rm_object_reference: id="<getId()<