Skip to content

Commit afc48c8

Browse files
committedNov 16, 2016
Introduce builtin_shared and use it to fix #4778
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 649448a "Rename nodeupdate and nodeupdate_single and make them part of the official API"
1 parent 5f0dc8e commit afc48c8

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed
 

‎builtin/game/falling.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
-- Minetest: builtin/item.lua
22

3+
local builtin_shared = ...
4+
35
--
46
-- Falling stuff
57
--
@@ -127,7 +129,7 @@ local function drop_attached_node(p)
127129
end
128130
end
129131

130-
local function check_attached_node(p, n)
132+
function builtin_shared.check_attached_node(p, n)
131133
local def = core.registered_nodes[n.name]
132134
local d = {x = 0, y = 0, z = 0}
133135
if def.paramtype2 == "wallmounted" then
@@ -177,7 +179,7 @@ function core.check_single_for_falling(p)
177179
end
178180

179181
if core.get_item_group(n.name, "attached_node") ~= 0 then
180-
if not check_attached_node(p, n) then
182+
if not builtin_shared.check_attached_node(p, n) then
181183
drop_attached_node(p)
182184
return true
183185
end

‎builtin/game/init.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ local scriptpath = core.get_builtin_path()..DIR_DELIM
33
local commonpath = scriptpath.."common"..DIR_DELIM
44
local gamepath = scriptpath.."game"..DIR_DELIM
55

6+
-- Shared between builtin files, but
7+
-- not exposed to outer context
8+
local builtin_shared = {}
9+
610
dofile(commonpath.."vector.lua")
711

812
dofile(gamepath.."constants.lua")
9-
dofile(gamepath.."item.lua")
13+
assert(loadfile(gamepath.."item.lua"))(builtin_shared)
1014
dofile(gamepath.."register.lua")
1115

1216
if core.setting_getbool("profiler.load") then
@@ -21,7 +25,7 @@ dofile(gamepath.."auth.lua")
2125
dofile(gamepath.."chatcommands.lua")
2226
dofile(gamepath.."static_spawn.lua")
2327
dofile(gamepath.."detached_inventory.lua")
24-
dofile(gamepath.."falling.lua")
28+
assert(loadfile(gamepath.."falling.lua"))(builtin_shared)
2529
dofile(gamepath.."features.lua")
2630
dofile(gamepath.."voxelarea.lua")
2731
dofile(gamepath.."forceloading.lua")

‎builtin/game/item.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
-- Minetest: builtin/item.lua
22

3+
local builtin_shared = ...
4+
35
local function copy_pointed_thing(pointed_thing)
46
return {
57
type = pointed_thing.type,
@@ -275,7 +277,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2)
275277

276278
-- Check if the node is attached and if it can be placed there
277279
if core.get_item_group(def.name, "attached_node") ~= 0 and
278-
not check_attached_node(place_to, newnode) then
280+
not builtin_shared.check_attached_node(place_to, newnode) then
279281
core.log("action", "attached node " .. def.name ..
280282
" can not be placed at " .. core.pos_to_string(place_to))
281283
return itemstack, false

0 commit comments

Comments
 (0)
Please sign in to comment.