summaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_base.cpp
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2014-04-27 21:02:48 -0400
committerShadowNinja <shadowninja@minetest.net>2014-05-08 13:02:04 -0400
commitc4359ff65cd8e4e754442b9f2ef7051a8eaa4241 (patch)
treefeaad8be8c36cc4a0abdbe8d7b84db3ac68ed87e /src/script/cpp_api/s_base.cpp
parent1cd512913e4d4ad1fb43d4b6e3d7971bb6c67528 (diff)
downloadminetest-c4359ff65cd8e4e754442b9f2ef7051a8eaa4241.tar.gz
minetest-c4359ff65cd8e4e754442b9f2ef7051a8eaa4241.tar.bz2
minetest-c4359ff65cd8e4e754442b9f2ef7051a8eaa4241.zip
Use "core" namespace internally
Diffstat (limited to 'src/script/cpp_api/s_base.cpp')
-rw-r--r--src/script/cpp_api/s_base.cpp28
1 files changed, 19 insertions, 9 deletions
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="<<cobj->getId()<<std::endl;
- // 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);
@@ -244,12 +254,12 @@ void ScriptApiBase::objectrefGet(u16 id)
{
lua_State *L = getStack();
- // Get minetest.object_refs[i]
- lua_getglobal(L, "minetest");
+ // Get core.object_refs[i]
+ lua_getglobal(L, "core");
lua_getfield(L, -1, "object_refs");
luaL_checktype(L, -1, LUA_TTABLE);
lua_pushnumber(L, id);
lua_gettable(L, -2);
lua_remove(L, -2); // object_refs
- lua_remove(L, -2); // minetest
+ lua_remove(L, -2); // core
}