commit fba8201fdf8d384a363a5c2ac48b998d03d059ca Author: bad Date: Wed May 25 15:43:45 2022 +0200 Initial commit diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..0232631 --- /dev/null +++ b/init.lua @@ -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 +}) diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..88d1e9e --- /dev/null +++ b/mod.conf @@ -0,0 +1,2 @@ +name=repl +description=A simple repl