From fba8201fdf8d384a363a5c2ac48b998d03d059ca Mon Sep 17 00:00:00 2001 From: bad Date: Wed, 25 May 2022 15:43:45 +0200 Subject: [PATCH] Initial commit --- init.lua | 31 +++++++++++++++++++++++++++++++ mod.conf | 2 ++ 2 files changed, 33 insertions(+) create mode 100644 init.lua create mode 100644 mod.conf 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