mirror of
https://github.com/minetest-mods/MoreMesecons.git
synced 2024-11-19 21:53:50 +01:00
LuaBlock: don't set the function environment + remove created pos global
This commit is contained in:
parent
abe8368e32
commit
e1d2e84746
@ -81,8 +81,8 @@ minetest.register_node("moremesecons_luablock:luablock", {
|
|||||||
return meta:get_string("owner") == player:get_player_name()
|
return meta:get_string("owner") == player:get_player_name()
|
||||||
end,
|
end,
|
||||||
mesecons = {effector = {
|
mesecons = {effector = {
|
||||||
action_on = function(pos, node)
|
action_on = function(npos, node)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(npos)
|
||||||
local code = meta:get_string("code")
|
local code = meta:get_string("code")
|
||||||
if code == "" then
|
if code == "" then
|
||||||
return
|
return
|
||||||
@ -98,11 +98,12 @@ minetest.register_node("moremesecons_luablock:luablock", {
|
|||||||
make_formspec(meta, pos)
|
make_formspec(meta, pos)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local env = _G
|
-- Set the "pos" global
|
||||||
env.pos = table.copy(pos)
|
local old_pos = pos -- In case there's already an existing "pos" global
|
||||||
setfenv(func, env)
|
pos = table.copy(npos)
|
||||||
local good, err = pcall(func)
|
local good, err = pcall(func)
|
||||||
-- Still alive! No shutdown requested? No infinite loop?
|
pos = old_pos
|
||||||
|
|
||||||
if not good then -- Runtime error
|
if not good then -- Runtime error
|
||||||
meta:set_string("errmsg", err)
|
meta:set_string("errmsg", err)
|
||||||
make_formspec(meta, pos)
|
make_formspec(meta, pos)
|
||||||
|
Loading…
Reference in New Issue
Block a user