mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-13 16:45:20 +02:00
Use "core" namespace internally
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user