]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/script/cpp_api/s_inventory.cpp
Order es_DrawType exactly like enum NodeDrawType in nodedef.h (#5946)
[dragonfireclient.git] / src / script / cpp_api / s_inventory.cpp
index c8c90fd8f1f69bddd5a177eee9de25c8b2353f14..c90c7d4e2e78b99cbfb632e3c6377e74fc8da590 100644 (file)
@@ -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;
@@ -48,11 +50,11 @@ int ScriptApiDetached::detached_inventory_AllowMove(
        lua_pushinteger(L, to_index + 1);     // to_index
        lua_pushinteger(L, count);            // count
        objectrefGetOrCreate(L, player);      // player
-       PCALL_RES(lua_pcall(L, 7, 1, m_errorhandler));
+       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;
 }
 
@@ -64,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,11 +80,11 @@ int ScriptApiDetached::detached_inventory_AllowPut(
        lua_pushinteger(L, index + 1);       // index
        LuaItemStack::create(L, stack);      // stack
        objectrefGetOrCreate(L, player);     // player
-       PCALL_RES(lua_pcall(L, 5, 1, m_errorhandler));
+       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;
 }
 
@@ -92,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
@@ -104,11 +110,11 @@ int ScriptApiDetached::detached_inventory_AllowTake(
        lua_pushinteger(L, index + 1);       // index
        LuaItemStack::create(L, stack);      // stack
        objectrefGetOrCreate(L, player);     // player
-       PCALL_RES(lua_pcall(L, 5, 1, m_errorhandler));
+       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;
 }
 
@@ -121,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;
@@ -136,7 +144,8 @@ void ScriptApiDetached::detached_inventory_OnMove(
        lua_pushinteger(L, to_index + 1);     // to_index
        lua_pushinteger(L, count);            // count
        objectrefGetOrCreate(L, player);      // player
-       PCALL_RES(lua_pcall(L, 7, 0, m_errorhandler));
+       PCALL_RES(lua_pcall(L, 7, 0, error_handler));
+       lua_pop(L, 1);  // Pop error handler
 }
 
 // Report put items
@@ -147,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;
@@ -160,7 +171,8 @@ void ScriptApiDetached::detached_inventory_OnPut(
        lua_pushinteger(L, index + 1);       // index
        LuaItemStack::create(L, stack);      // stack
        objectrefGetOrCreate(L, player);     // player
-       PCALL_RES(lua_pcall(L, 5, 0, m_errorhandler));
+       PCALL_RES(lua_pcall(L, 5, 0, error_handler));
+       lua_pop(L, 1);  // Pop error handler
 }
 
 // Report taken items
@@ -171,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;
@@ -184,7 +198,8 @@ void ScriptApiDetached::detached_inventory_OnTake(
        lua_pushinteger(L, index + 1);       // index
        LuaItemStack::create(L, stack);      // stack
        objectrefGetOrCreate(L, player);     // player
-       PCALL_RES(lua_pcall(L, 5, 0, m_errorhandler));
+       PCALL_RES(lua_pcall(L, 5, 0, error_handler));
+       lua_pop(L, 1);  // Pop error handler
 }
 
 // Retrieves core.detached_inventories[name][callbackname]
@@ -209,6 +224,9 @@ bool ScriptApiDetached::getDetachedInventoryCallback(
                lua_pop(L, 1);
                return false;
        }
+
+       setOriginFromTable(-1);
+
        lua_getfield(L, -1, callbackname);
        lua_remove(L, -2);
        // Should be a function or nil