diff options
Diffstat (limited to 'src/script/cpp_api')
-rw-r--r-- | src/script/cpp_api/s_async.cpp | 19 | ||||
-rw-r--r-- | src/script/cpp_api/s_base.cpp | 28 | ||||
-rw-r--r-- | src/script/cpp_api/s_entity.cpp | 26 | ||||
-rw-r--r-- | src/script/cpp_api/s_env.cpp | 16 | ||||
-rw-r--r-- | src/script/cpp_api/s_inventory.cpp | 4 | ||||
-rw-r--r-- | src/script/cpp_api/s_item.cpp | 16 | ||||
-rw-r--r-- | src/script/cpp_api/s_mainmenu.cpp | 8 | ||||
-rw-r--r-- | src/script/cpp_api/s_player.cpp | 32 | ||||
-rw-r--r-- | src/script/cpp_api/s_server.cpp | 10 |
9 files changed, 81 insertions, 78 deletions
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="<<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 } diff --git a/src/script/cpp_api/s_entity.cpp b/src/script/cpp_api/s_entity.cpp index 8e79f8838..ab8c6ee95 100644 --- a/src/script/cpp_api/s_entity.cpp +++ b/src/script/cpp_api/s_entity.cpp @@ -31,8 +31,8 @@ bool ScriptApiEntity::luaentity_Add(u16 id, const char *name) verbosestream<<"scriptapi_luaentity_add: id="<<id<<" name=\"" <<name<<"\""<<std::endl; - // Get minetest.registered_entities[name] - lua_getglobal(L, "minetest"); + // Get core.registered_entities[name] + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_entities"); luaL_checktype(L, -1, LUA_TTABLE); lua_pushstring(L, name); @@ -62,8 +62,8 @@ bool ScriptApiEntity::luaentity_Add(u16 id, const char *name) luaL_typerror(L, -1, "ObjectRef"); lua_setfield(L, -2, "object"); - // minetest.luaentities[id] = object - lua_getglobal(L, "minetest"); + // core.luaentities[id] = object + lua_getglobal(L, "core"); lua_getfield(L, -1, "luaentities"); luaL_checktype(L, -1, LUA_TTABLE); lua_pushnumber(L, id); // Push id @@ -80,7 +80,7 @@ void ScriptApiEntity::luaentity_Activate(u16 id, verbosestream << "scriptapi_luaentity_activate: id=" << id << std::endl; - // Get minetest.luaentities[id] + // Get core.luaentities[id] luaentity_get(L, id); int object = lua_gettop(L); @@ -106,8 +106,8 @@ void ScriptApiEntity::luaentity_Remove(u16 id) verbosestream << "scriptapi_luaentity_rm: id=" << id << std::endl; - // Get minetest.luaentities table - lua_getglobal(L, "minetest"); + // Get core.luaentities table + lua_getglobal(L, "core"); lua_getfield(L, -1, "luaentities"); luaL_checktype(L, -1, LUA_TTABLE); int objectstable = lua_gettop(L); @@ -117,7 +117,7 @@ void ScriptApiEntity::luaentity_Remove(u16 id) lua_pushnil(L); lua_settable(L, objectstable); - lua_pop(L, 2); // pop luaentities, minetest + lua_pop(L, 2); // pop luaentities, core } std::string ScriptApiEntity::luaentity_GetStaticdata(u16 id) @@ -126,7 +126,7 @@ std::string ScriptApiEntity::luaentity_GetStaticdata(u16 id) //infostream<<"scriptapi_luaentity_get_staticdata: id="<<id<<std::endl; - // Get minetest.luaentities[id] + // Get core.luaentities[id] luaentity_get(L, id); int object = lua_gettop(L); @@ -157,7 +157,7 @@ void ScriptApiEntity::luaentity_GetProperties(u16 id, //infostream<<"scriptapi_luaentity_get_properties: id="<<id<<std::endl; - // Get minetest.luaentities[id] + // Get core.luaentities[id] luaentity_get(L, id); // Set default values that differ from ObjectProperties defaults @@ -196,7 +196,7 @@ void ScriptApiEntity::luaentity_Step(u16 id, float dtime) //infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl; - // Get minetest.luaentities[id] + // Get core.luaentities[id] luaentity_get(L, id); int object = lua_gettop(L); // State: object is at top of stack @@ -225,7 +225,7 @@ void ScriptApiEntity::luaentity_Punch(u16 id, //infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl; - // Get minetest.luaentities[id] + // Get core.luaentities[id] luaentity_get(L,id); int object = lua_gettop(L); // State: object is at top of stack @@ -255,7 +255,7 @@ void ScriptApiEntity::luaentity_Rightclick(u16 id, //infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl; - // Get minetest.luaentities[id] + // Get core.luaentities[id] luaentity_get(L, id); int object = lua_gettop(L); // State: object is at top of stack diff --git a/src/script/cpp_api/s_env.cpp b/src/script/cpp_api/s_env.cpp index ee3783bb9..9ac9302ac 100644 --- a/src/script/cpp_api/s_env.cpp +++ b/src/script/cpp_api/s_env.cpp @@ -31,8 +31,8 @@ void ScriptApiEnv::environment_OnGenerated(v3s16 minp, v3s16 maxp, { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_generateds - lua_getglobal(L, "minetest"); + // Get core.registered_on_generateds + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_generateds"); // Call callbacks push_v3s16(L, minp); @@ -46,8 +46,8 @@ void ScriptApiEnv::environment_Step(float dtime) SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_environment_step"<<std::endl; - // Get minetest.registered_globalsteps - lua_getglobal(L, "minetest"); + // Get core.registered_globalsteps + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_globalsteps"); // Call callbacks lua_pushnumber(L, dtime); @@ -80,8 +80,8 @@ void ScriptApiEnv::environment_OnMapgenInit(MapgenParams *mgparams) { SCRIPTAPI_PRECHECKHEADER - // Get minetest.registered_on_mapgen_inits - lua_getglobal(L, "minetest"); + // Get core.registered_on_mapgen_inits + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_on_mapgen_inits"); // Call callbacks @@ -114,8 +114,8 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env) Add ActiveBlockModifiers to environment */ - // Get minetest.registered_abms - lua_getglobal(L, "minetest"); + // Get core.registered_abms + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_abms"); luaL_checktype(L, -1, LUA_TTABLE); int registered_abms = lua_gettop(L); diff --git a/src/script/cpp_api/s_inventory.cpp b/src/script/cpp_api/s_inventory.cpp index a2d186d00..f423a9f33 100644 --- a/src/script/cpp_api/s_inventory.cpp +++ b/src/script/cpp_api/s_inventory.cpp @@ -193,7 +193,7 @@ void ScriptApiDetached::detached_inventory_OnTake( scriptError(); } -// Retrieves minetest.detached_inventories[name][callbackname] +// Retrieves core.detached_inventories[name][callbackname] // If that is nil or on error, return false and stack is unchanged // If that is a function, returns true and pushes the // function onto the stack @@ -202,7 +202,7 @@ bool ScriptApiDetached::getDetachedInventoryCallback( { lua_State *L = getStack(); - lua_getglobal(L, "minetest"); + lua_getglobal(L, "core"); lua_getfield(L, -1, "detached_inventories"); lua_remove(L, -2); luaL_checktype(L, -1, LUA_TTABLE); diff --git a/src/script/cpp_api/s_item.cpp b/src/script/cpp_api/s_item.cpp index cb5b1e775..ab82b6b47 100644 --- a/src/script/cpp_api/s_item.cpp +++ b/src/script/cpp_api/s_item.cpp @@ -112,7 +112,7 @@ bool ScriptApiItem::item_OnCraft(ItemStack &item, ServerActiveObject *user, { SCRIPTAPI_PRECHECKHEADER - lua_getglobal(L, "minetest"); + lua_getglobal(L, "core"); lua_getfield(L, -1, "on_craft"); LuaItemStack::create(L, item); objectrefGetOrCreate(user); @@ -143,7 +143,7 @@ bool ScriptApiItem::item_CraftPredict(ItemStack &item, ServerActiveObject *user, { SCRIPTAPI_PRECHECKHEADER - lua_getglobal(L, "minetest"); + lua_getglobal(L, "core"); lua_getfield(L, -1, "craft_predict"); LuaItemStack::create(L, item); objectrefGetOrCreate(user); @@ -169,19 +169,19 @@ bool ScriptApiItem::item_CraftPredict(ItemStack &item, ServerActiveObject *user, return true; } -// Retrieves minetest.registered_items[name][callbackname] +// Retrieves core.registered_items[name][callbackname] // If that is nil or on error, return false and stack is unchanged // If that is a function, returns true and pushes the // function onto the stack -// If minetest.registered_items[name] doesn't exist, minetest.nodedef_default +// If core.registered_items[name] doesn't exist, core.nodedef_default // is tried instead so unknown items can still be manipulated to some degree bool ScriptApiItem::getItemCallback(const char *name, const char *callbackname) { lua_State* L = getStack(); - lua_getglobal(L, "minetest"); + lua_getglobal(L, "core"); lua_getfield(L, -1, "registered_items"); - lua_remove(L, -2); // Remove minetest + lua_remove(L, -2); // Remove core luaL_checktype(L, -1, LUA_TTABLE); lua_getfield(L, -1, name); lua_remove(L, -2); // Remove registered_items @@ -192,8 +192,8 @@ bool ScriptApiItem::getItemCallback(const char *name, const char *callbackname) errorstream << "Item \"" << name << "\" not defined" << std::endl; lua_pop(L, 1); - // Try minetest.nodedef_default instead - lua_getglobal(L, "minetest"); + // Try core.nodedef_default instead + lua_getglobal(L, "core"); lua_getfield(L, -1, "nodedef_default"); lua_remove(L, -2); luaL_checktype(L, -1, LUA_TTABLE); diff --git a/src/script/cpp_api/s_mainmenu.cpp b/src/script/cpp_api/s_mainmenu.cpp index 62baeb406..ef8cea6c9 100644 --- a/src/script/cpp_api/s_mainmenu.cpp +++ b/src/script/cpp_api/s_mainmenu.cpp @@ -38,9 +38,9 @@ void ScriptApiMainMenu::handleMainMenuEvent(std::string text) SCRIPTAPI_PRECHECKHEADER // Get handler function - lua_getglobal(L, "engine"); + lua_getglobal(L, "core"); lua_getfield(L, -1, "event_handler"); - lua_remove(L, -2); // Remove engine + lua_remove(L, -2); // Remove core if (lua_isnil(L, -1)) { lua_pop(L, 1); // Pop event_handler return; @@ -58,9 +58,9 @@ void ScriptApiMainMenu::handleMainMenuButtons(std::map<std::string, std::string> 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); |