mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-09-27 23:00:29 +02:00
add luacontroller environment customization function
the luacontroller environment can be customized in dependent mods by overriding the mesecon.luacontroller.customize_environment(env, pos, mem) function prividing dependent mods the ability to add more functions to the luacontroller enviromment (use-case, for example: mob-control, chat, etc)
This commit is contained in:
parent
b0158f5674
commit
a2386164ac
|
@ -24,8 +24,7 @@
|
||||||
-- a very restricted environment.
|
-- a very restricted environment.
|
||||||
-- Actually the only way to damage the server is to
|
-- Actually the only way to damage the server is to
|
||||||
-- use too much memory from the sandbox.
|
-- use too much memory from the sandbox.
|
||||||
-- You can add more functions to the environment
|
-- You can add more functions to the environment if you override mesecon.luacontroller.customize_environment
|
||||||
-- (see where local env is defined)
|
|
||||||
-- Something nice to play is is appending minetest.env to it.
|
-- Something nice to play is is appending minetest.env to it.
|
||||||
|
|
||||||
local BASENAME = "mesecons_luacontroller:luacontroller"
|
local BASENAME = "mesecons_luacontroller:luacontroller"
|
||||||
|
@ -38,6 +37,11 @@ local rules = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------
|
||||||
|
-- luacontroller namespace --
|
||||||
|
-----------------------------
|
||||||
|
mesecon.luacontroller = {}
|
||||||
|
|
||||||
------------------
|
------------------
|
||||||
-- Action stuff --
|
-- Action stuff --
|
||||||
------------------
|
------------------
|
||||||
|
@ -433,6 +437,12 @@ local safe_globals = {
|
||||||
"tonumber", "tostring", "type", "unpack", "_VERSION"
|
"tonumber", "tostring", "type", "unpack", "_VERSION"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- luacontroller environment customization
|
||||||
|
-- can be overridden in dependent mods to add more functions
|
||||||
|
function mesecon.luacontroller.customize_environment(env, pos, mem)
|
||||||
|
-- no-op
|
||||||
|
end
|
||||||
|
|
||||||
local function create_environment(pos, mem, event, itbl, send_warning)
|
local function create_environment(pos, mem, event, itbl, send_warning)
|
||||||
-- Gather variables for the environment
|
-- Gather variables for the environment
|
||||||
local vports = minetest.registered_nodes[minetest.get_node(pos).name].virtual_portstates
|
local vports = minetest.registered_nodes[minetest.get_node(pos).name].virtual_portstates
|
||||||
|
@ -515,6 +525,9 @@ local function create_environment(pos, mem, event, itbl, send_warning)
|
||||||
env[name] = _G[name]
|
env[name] = _G[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- customization hook
|
||||||
|
mesecon.luacontroller.customize_environment(env, pos, mem)
|
||||||
|
|
||||||
return env
|
return env
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -901,4 +914,3 @@ minetest.register_craft({
|
||||||
{'group:mesecon_conductor_craftable', 'group:mesecon_conductor_craftable', ''},
|
{'group:mesecon_conductor_craftable', 'group:mesecon_conductor_craftable', ''},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user