Initial commit
This commit is contained in:
commit
fba8201fdf
|
@ -0,0 +1,31 @@
|
|||
local repl_env = table.copy(_G)
|
||||
|
||||
minetest.register_chatcommand("eval", {
|
||||
privs = {
|
||||
privs=true
|
||||
},
|
||||
description = 'Execute lua code on the server',
|
||||
|
||||
func = function(name, param)
|
||||
local chunk, errmsg = loadstring('return ' .. param)
|
||||
if not chunk then
|
||||
chunk, errmsg = loadstring(param)
|
||||
end
|
||||
if errmsg then
|
||||
return true, dump(errmsg)
|
||||
end
|
||||
|
||||
for key, value in pairs(_G) do
|
||||
repl_env[key] = value
|
||||
end
|
||||
|
||||
repl_env.cur_player = minetest.get_player_by_name(name)
|
||||
|
||||
setfenv(chunk, repl_env)
|
||||
local _, res = pcall(chunk)
|
||||
|
||||
for line in string.gmatch(dump(res), "[^\n]+") do
|
||||
minetest.chat_send_player(name, line)
|
||||
end
|
||||
end
|
||||
})
|
Loading…
Reference in New Issue