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:
NatureFreshMilk 2019-06-21 07:34:08 +02:00
parent b0158f5674
commit a2386164ac
1 changed files with 15 additions and 3 deletions

View File

@ -24,8 +24,7 @@
-- a very restricted environment.
-- Actually the only way to damage the server is to
-- use too much memory from the sandbox.
-- You can add more functions to the environment
-- (see where local env is defined)
-- You can add more functions to the environment if you override mesecon.luacontroller.customize_environment
-- Something nice to play is is appending minetest.env to it.
local BASENAME = "mesecons_luacontroller:luacontroller"
@ -38,6 +37,11 @@ local rules = {
}
-----------------------------
-- luacontroller namespace --
-----------------------------
mesecon.luacontroller = {}
------------------
-- Action stuff --
------------------
@ -433,6 +437,12 @@ local safe_globals = {
"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)
-- Gather variables for the environment
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]
end
-- customization hook
mesecon.luacontroller.customize_environment(env, pos, mem)
return env
end
@ -901,4 +914,3 @@ minetest.register_craft({
{'group:mesecon_conductor_craftable', 'group:mesecon_conductor_craftable', ''},
}
})