X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fscript%2Fcpp_api%2Fs_inventory.cpp;h=251ddb2211634c7630db30e15122006e6ee7408d;hb=67f97f8d3274e0e96a8f541a05a39f81dfec1a20;hp=f423a9f3359ea1fc301e1a0874ab7317ad29d75c;hpb=c4359ff65cd8e4e754442b9f2ef7051a8eaa4241;p=minetest.git diff --git a/src/script/cpp_api/s_inventory.cpp b/src/script/cpp_api/s_inventory.cpp index f423a9f33..251ddb221 100644 --- a/src/script/cpp_api/s_inventory.cpp +++ b/src/script/cpp_api/s_inventory.cpp @@ -33,6 +33,8 @@ int ScriptApiDetached::detached_inventory_AllowMove( { SCRIPTAPI_PRECHECKHEADER + int error_handler = PUSH_ERROR_HANDLER(L); + // Push callback function on stack if (!getDetachedInventoryCallback(name, "allow_move")) return count; @@ -47,13 +49,12 @@ int ScriptApiDetached::detached_inventory_AllowMove( lua_pushstring(L, to_list.c_str()); // to_list lua_pushinteger(L, to_index + 1); // to_index lua_pushinteger(L, count); // count - objectrefGetOrCreate(player); // player - if (lua_pcall(L, 7, 1, m_errorhandler)) - scriptError(); + objectrefGetOrCreate(L, player); // player + PCALL_RES(lua_pcall(L, 7, 1, error_handler)); if(!lua_isnumber(L, -1)) throw LuaError("allow_move should return a number. name=" + name); int ret = luaL_checkinteger(L, -1); - lua_pop(L, 1); // Pop integer + lua_pop(L, 2); // Pop integer and error handler return ret; } @@ -65,6 +66,8 @@ int ScriptApiDetached::detached_inventory_AllowPut( { SCRIPTAPI_PRECHECKHEADER + int error_handler = PUSH_ERROR_HANDLER(L); + // Push callback function on stack if (!getDetachedInventoryCallback(name, "allow_put")) return stack.count; // All will be accepted @@ -76,13 +79,12 @@ int ScriptApiDetached::detached_inventory_AllowPut( lua_pushstring(L, listname.c_str()); // listname lua_pushinteger(L, index + 1); // index LuaItemStack::create(L, stack); // stack - objectrefGetOrCreate(player); // player - if (lua_pcall(L, 5, 1, m_errorhandler)) - scriptError(); + objectrefGetOrCreate(L, player); // player + PCALL_RES(lua_pcall(L, 5, 1, error_handler)); if (!lua_isnumber(L, -1)) throw LuaError("allow_put should return a number. name=" + name); int ret = luaL_checkinteger(L, -1); - lua_pop(L, 1); // Pop integer + lua_pop(L, 2); // Pop integer and error handler return ret; } @@ -94,6 +96,8 @@ int ScriptApiDetached::detached_inventory_AllowTake( { SCRIPTAPI_PRECHECKHEADER + int error_handler = PUSH_ERROR_HANDLER(L); + // Push callback function on stack if (!getDetachedInventoryCallback(name, "allow_take")) return stack.count; // All will be accepted @@ -105,13 +109,12 @@ int ScriptApiDetached::detached_inventory_AllowTake( lua_pushstring(L, listname.c_str()); // listname lua_pushinteger(L, index + 1); // index LuaItemStack::create(L, stack); // stack - objectrefGetOrCreate(player); // player - if (lua_pcall(L, 5, 1, m_errorhandler)) - scriptError(); + objectrefGetOrCreate(L, player); // player + PCALL_RES(lua_pcall(L, 5, 1, error_handler)); if (!lua_isnumber(L, -1)) throw LuaError("allow_take should return a number. name=" + name); int ret = luaL_checkinteger(L, -1); - lua_pop(L, 1); // Pop integer + lua_pop(L, 2); // Pop integer and error handler return ret; } @@ -124,6 +127,8 @@ void ScriptApiDetached::detached_inventory_OnMove( { SCRIPTAPI_PRECHECKHEADER + int error_handler = PUSH_ERROR_HANDLER(L); + // Push callback function on stack if (!getDetachedInventoryCallback(name, "on_move")) return; @@ -138,9 +143,9 @@ void ScriptApiDetached::detached_inventory_OnMove( lua_pushstring(L, to_list.c_str()); // to_list lua_pushinteger(L, to_index + 1); // to_index lua_pushinteger(L, count); // count - objectrefGetOrCreate(player); // player - if (lua_pcall(L, 7, 0, m_errorhandler)) - scriptError(); + objectrefGetOrCreate(L, player); // player + PCALL_RES(lua_pcall(L, 7, 0, error_handler)); + lua_pop(L, 1); // Pop error handler } // Report put items @@ -151,6 +156,8 @@ void ScriptApiDetached::detached_inventory_OnPut( { SCRIPTAPI_PRECHECKHEADER + int error_handler = PUSH_ERROR_HANDLER(L); + // Push callback function on stack if (!getDetachedInventoryCallback(name, "on_put")) return; @@ -163,9 +170,9 @@ void ScriptApiDetached::detached_inventory_OnPut( lua_pushstring(L, listname.c_str()); // listname lua_pushinteger(L, index + 1); // index LuaItemStack::create(L, stack); // stack - objectrefGetOrCreate(player); // player - if (lua_pcall(L, 5, 0, m_errorhandler)) - scriptError(); + objectrefGetOrCreate(L, player); // player + PCALL_RES(lua_pcall(L, 5, 0, error_handler)); + lua_pop(L, 1); // Pop error handler } // Report taken items @@ -176,6 +183,8 @@ void ScriptApiDetached::detached_inventory_OnTake( { SCRIPTAPI_PRECHECKHEADER + int error_handler = PUSH_ERROR_HANDLER(L); + // Push callback function on stack if (!getDetachedInventoryCallback(name, "on_take")) return; @@ -188,9 +197,9 @@ void ScriptApiDetached::detached_inventory_OnTake( lua_pushstring(L, listname.c_str()); // listname lua_pushinteger(L, index + 1); // index LuaItemStack::create(L, stack); // stack - objectrefGetOrCreate(player); // player - if (lua_pcall(L, 5, 0, m_errorhandler)) - scriptError(); + objectrefGetOrCreate(L, player); // player + PCALL_RES(lua_pcall(L, 5, 0, error_handler)); + lua_pop(L, 1); // Pop error handler } // Retrieves core.detached_inventories[name][callbackname] @@ -209,29 +218,28 @@ bool ScriptApiDetached::getDetachedInventoryCallback( lua_getfield(L, -1, name.c_str()); lua_remove(L, -2); // Should be a table - if(lua_type(L, -1) != LUA_TTABLE) - { + if (lua_type(L, -1) != LUA_TTABLE) { errorstream<<"Detached inventory \""<