diff --git a/.luacheckrc b/.luacheckrc index ba6434e..78f2a98 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,3 +1,3 @@ -globals = {"minetest", "ItemStack", "VoxelArea", "vector", "nodecore", "include", "SecureRandom"} +globals = {"minetest", "ItemStack", "VoxelArea", "vector", "nodecore", "include", "SecureRandom", "dump"} color = false quiet = 1 diff --git a/.lualocals b/.lualocals index 19c8d07..d0ddfaf 100644 --- a/.lualocals +++ b/.lualocals @@ -2,3 +2,4 @@ minetest ItemStack VoxelArea +dump \ No newline at end of file diff --git a/szutil_lua/README.md b/szutil_lua/README.md new file mode 100644 index 0000000..ef985ce --- /dev/null +++ b/szutil_lua/README.md @@ -0,0 +1,5 @@ +Adds a `/lua` command to allow an admin to execute any arbitrary lua in the server context that they want. + +This is comparable to the //lua command functionality present in worldedit, but can be enabled without all the other worldedit stuff. + +The code is run inside a synchronous protected call, with no input parameters. The result (return or error) is sent to the user. \ No newline at end of file diff --git a/szutil_lua/init.lua b/szutil_lua/init.lua new file mode 100644 index 0000000..14768a3 --- /dev/null +++ b/szutil_lua/init.lua @@ -0,0 +1,31 @@ +-- LUALOCALS < --------------------------------------------------------- +local dump, loadstring, minetest, pcall, table, tostring + = dump, loadstring, minetest, pcall, table, tostring +local table_remove + = table.remove +-- LUALOCALS > --------------------------------------------------------- + +local modname = minetest.get_current_modname() + +minetest.register_privilege(modname, { + description = "Can run arbitrary lua code", + give_to_singleplayer = false, + give_to_admin = false, + }) + +minetest.register_chatcommand("lua", { + privs = {[modname] = true}, + description = "Run arbitrary lua code", + func = function(_, param) + local func, synerr = loadstring(param) + if not func then + return false, "parse error: " .. tostring(synerr) + end + local result = {pcall(func)} + if not result[1] then + return false, "runtime error: " .. tostring(result[2]) + end + table_remove(result, 1) + return true, "returned: " .. dump(result) + end + }) diff --git a/szutil_lua/mod.conf b/szutil_lua/mod.conf new file mode 100644 index 0000000..a209ec9 --- /dev/null +++ b/szutil_lua/mod.conf @@ -0,0 +1,3 @@ +name = szutil_lua +description = Arbitrary lua code chat command +supported_games = *