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_async.cpp | 19 ++++++------------- src/script/cpp_api/s_base.cpp | 28 +++++++++++++++++++--------- src/script/cpp_api/s_entity.cpp | 26 +++++++++++++------------- src/script/cpp_api/s_env.cpp | 16 ++++++++-------- src/script/cpp_api/s_inventory.cpp | 4 ++-- src/script/cpp_api/s_item.cpp | 16 ++++++++-------- src/script/cpp_api/s_mainmenu.cpp | 8 ++++---- src/script/cpp_api/s_player.cpp | 32 ++++++++++++++++---------------- src/script/cpp_api/s_server.cpp | 10 +++++----- 9 files changed, 81 insertions(+), 78 deletions(-) (limited to 'src/script/cpp_api') diff --git a/src/script/cpp_api/s_async.cpp b/src/script/cpp_api/s_async.cpp index 64260fb3a..0b19572c2 100644 --- a/src/script/cpp_api/s_async.cpp +++ b/src/script/cpp_api/s_async.cpp @@ -146,7 +146,7 @@ void AsyncEngine::putJobResult(LuaJobInfo result) /******************************************************************************/ void AsyncEngine::step(lua_State *L, int errorhandler) { - lua_getglobal(L, "engine"); + lua_getglobal(L, "core"); resultQueueMutex.Lock(); while (!resultQueue.empty()) { LuaJobInfo jobDone = resultQueue.front(); @@ -169,7 +169,7 @@ void AsyncEngine::step(lua_State *L, int errorhandler) } } resultQueueMutex.Unlock(); - lua_pop(L, 1); // Pop engine + lua_pop(L, 1); // Pop core } /******************************************************************************/ @@ -223,17 +223,10 @@ AsyncWorkerThread::AsyncWorkerThread(AsyncEngine* jobDispatcher, { lua_State *L = getStack(); - luaL_openlibs(L); - // Prepare job lua environment - lua_newtable(L); - lua_setglobal(L, "engine"); - lua_getglobal(L, "engine"); + lua_getglobal(L, "core"); int top = lua_gettop(L); - lua_pushstring(L, DIR_DELIM); - lua_setglobal(L, "DIR_DELIM"); - // Push builtin initialization type lua_pushstring(L, "async"); lua_setglobal(L, "INIT"); @@ -278,9 +271,9 @@ void* AsyncWorkerThread::Thread() continue; } - lua_getglobal(L, "engine"); + lua_getglobal(L, "core"); if (lua_isnil(L, -1)) { - errorstream << "Unable to find engine within async environment!"; + errorstream << "Unable to find core within async environment!"; abort(); } @@ -310,7 +303,7 @@ void* AsyncWorkerThread::Thread() toProcess.serializedResult = std::string(retval, length); } - // Pop engine, job_processor, and retval + // Pop core, job_processor, and retval lua_pop(L, 3); // Put job result 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()< SCRIPTAPI_PRECHECKHEADER // Get handler function - lua_getglobal(L, "engine"); + lua_getglobal(L, "core"); lua_getfield(L, -1, "button_handler"); - lua_remove(L, -2); // Remove engine + lua_remove(L, -2); // Remove core if (lua_isnil(L, -1)) { lua_pop(L, 1); // Pop button handler return; diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp index d357689f2..d7375082a 100644 --- a/src/script/cpp_api/s_player.cpp +++ b/src/script/cpp_api/s_player.cpp @@ -25,8 +25,8 @@ void ScriptApiPlayer::on_newplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_newplayers - lua_getglobal(L, "minetest"); + // Get core.registered_on_newplayers + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_newplayers"); // Call callbacks objectrefGetOrCreate(player); @@ -37,8 +37,8 @@ void ScriptApiPlayer::on_dieplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_dieplayers - lua_getglobal(L, "minetest"); + // Get core.registered_on_dieplayers + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_dieplayers"); // Call callbacks objectrefGetOrCreate(player); @@ -49,8 +49,8 @@ bool ScriptApiPlayer::on_respawnplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_respawnplayers - lua_getglobal(L, "minetest"); + // Get core.registered_on_respawnplayers + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_respawnplayers"); // Call callbacks objectrefGetOrCreate(player); @@ -63,8 +63,8 @@ bool ScriptApiPlayer::on_prejoinplayer(std::string name, std::string ip, std::st { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_prejoinplayers - lua_getglobal(L, "minetest"); + // Get core.registered_on_prejoinplayers + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_prejoinplayers"); lua_pushstring(L, name.c_str()); lua_pushstring(L, ip.c_str()); @@ -80,8 +80,8 @@ void ScriptApiPlayer::on_joinplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_joinplayers - lua_getglobal(L, "minetest"); + // Get core.registered_on_joinplayers + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_joinplayers"); // Call callbacks objectrefGetOrCreate(player); @@ -92,8 +92,8 @@ void ScriptApiPlayer::on_leaveplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_leaveplayers - lua_getglobal(L, "minetest"); + // Get core.registered_on_leaveplayers + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_leaveplayers"); // Call callbacks objectrefGetOrCreate(player); @@ -105,8 +105,8 @@ void ScriptApiPlayer::on_cheat(ServerActiveObject *player, { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_cheats - lua_getglobal(L, "minetest"); + // Get core.registered_on_cheats + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_cheats"); // Call callbacks objectrefGetOrCreate(player); @@ -122,8 +122,8 @@ void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player, { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_chat_messages - lua_getglobal(L, "minetest"); + // Get core.registered_on_chat_messages + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_player_receive_fields"); // Call callbacks // param 1 diff --git a/src/script/cpp_api/s_server.cpp b/src/script/cpp_api/s_server.cpp index 7d21f968b..21fe164aa 100644 --- a/src/script/cpp_api/s_server.cpp +++ b/src/script/cpp_api/s_server.cpp @@ -62,13 +62,13 @@ void ScriptApiServer::getAuthHandler() { lua_State *L = getStack(); - lua_getglobal(L, "minetest"); + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_auth_handler"); if (lua_isnil(L, -1)){ lua_pop(L, 1); lua_getfield(L, -1, "builtin_auth_handler"); } - lua_remove(L, -2); // Remove minetest + lua_remove(L, -2); // Remove core if (lua_type(L, -1) != LUA_TTABLE) throw LuaError("Authentication handler table not valid"); } @@ -130,8 +130,8 @@ bool ScriptApiServer::on_chat_message(const std::string &name, { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_chat_messages - lua_getglobal(L, "minetest"); + // Get core.registered_on_chat_messages + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_chat_messages"); // Call callbacks lua_pushstring(L, name.c_str()); @@ -146,7 +146,7 @@ void ScriptApiServer::on_shutdown() SCRIPTAPI_PRECHECKHEADER // Get registered shutdown hooks - lua_getglobal(L, "minetest"); + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_shutdown"); // Call callbacks script_run_callbacks(L, 0, RUN_CALLBACKS_MODE_FIRST); -- cgit v1.2.3