Introduce builtin_shared and use it to fix #4778
authorest31 <MTest31@outlook.com>
Wed, 16 Nov 2016 09:17:46 +0000 (10:17 +0100)
committerest31 <MTest31@outlook.com>
Wed, 16 Nov 2016 17:51:36 +0000 (18:51 +0100)
Fixes #4778 which was about the error:

ServerError: Lua: Runtime error from mod '' in callback item_OnPlace():
/usr/local/share/minetest/builtin/game/item.lua:278: attempt to call global 'check_attached_node' (a nil value)

The issue was a regression of commit 649448a2a91fbf3e944b2f2e739f4e2292af1df0

"Rename nodeupdate and nodeupdate_single and make them part of the official API"

builtin/game/falling.lua
builtin/game/init.lua
builtin/game/item.lua

index ece08b325fa9db50078cb71f7bdeb04b2220a283..8b88b68d83668d8a627f88ea38cde85bde148f08 100644 (file)
@@ -1,5 +1,7 @@
 -- Minetest: builtin/item.lua
 
+local builtin_shared = ...
+
 --
 -- Falling stuff
 --
@@ -127,7 +129,7 @@ local function drop_attached_node(p)
        end
 end
 
-local function check_attached_node(p, n)
+function builtin_shared.check_attached_node(p, n)
        local def = core.registered_nodes[n.name]
        local d = {x = 0, y = 0, z = 0}
        if def.paramtype2 == "wallmounted" then
@@ -177,7 +179,7 @@ function core.check_single_for_falling(p)
        end
 
        if core.get_item_group(n.name, "attached_node") ~= 0 then
-               if not check_attached_node(p, n) then
+               if not builtin_shared.check_attached_node(p, n) then
                        drop_attached_node(p)
                        return true
                end
index 2f9f90315c440688d73539acebeece0471418184..b5e2f7ccae5a4ed422e9e180b1bf39f22933def5 100644 (file)
@@ -3,10 +3,14 @@ local scriptpath = core.get_builtin_path()..DIR_DELIM
 local commonpath = scriptpath.."common"..DIR_DELIM
 local gamepath = scriptpath.."game"..DIR_DELIM
 
+-- Shared between builtin files, but
+-- not exposed to outer context
+local builtin_shared = {}
+
 dofile(commonpath.."vector.lua")
 
 dofile(gamepath.."constants.lua")
-dofile(gamepath.."item.lua")
+assert(loadfile(gamepath.."item.lua"))(builtin_shared)
 dofile(gamepath.."register.lua")
 
 if core.setting_getbool("profiler.load") then
@@ -21,7 +25,7 @@ dofile(gamepath.."auth.lua")
 dofile(gamepath.."chatcommands.lua")
 dofile(gamepath.."static_spawn.lua")
 dofile(gamepath.."detached_inventory.lua")
-dofile(gamepath.."falling.lua")
+assert(loadfile(gamepath.."falling.lua"))(builtin_shared)
 dofile(gamepath.."features.lua")
 dofile(gamepath.."voxelarea.lua")
 dofile(gamepath.."forceloading.lua")
index 26ff8225c15715361399406778ffa79d6b2174a7..ec996292f3510d88080f9c90a28592f34811c7ff 100644 (file)
@@ -1,5 +1,7 @@
 -- Minetest: builtin/item.lua
 
+local builtin_shared = ...
+
 local function copy_pointed_thing(pointed_thing)
        return {
                type  = pointed_thing.type,
@@ -275,7 +277,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2)
 
        -- Check if the node is attached and if it can be placed there
        if core.get_item_group(def.name, "attached_node") ~= 0 and
-               not check_attached_node(place_to, newnode) then
+               not builtin_shared.check_attached_node(place_to, newnode) then
                core.log("action", "attached node " .. def.name ..
                        " can not be placed at " .. core.pos_to_string(place_to))
                return itemstack, false