Add a simple lua mod
This commit is contained in:
parent
3b6ae83250
commit
d651dbc86a
@ -1,3 +1,3 @@
|
|||||||
globals = {"minetest", "ItemStack", "VoxelArea", "vector", "nodecore", "include", "SecureRandom"}
|
globals = {"minetest", "ItemStack", "VoxelArea", "vector", "nodecore", "include", "SecureRandom", "dump"}
|
||||||
color = false
|
color = false
|
||||||
quiet = 1
|
quiet = 1
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
minetest
|
minetest
|
||||||
ItemStack
|
ItemStack
|
||||||
VoxelArea
|
VoxelArea
|
||||||
|
dump
|
5
szutil_lua/README.md
Normal file
5
szutil_lua/README.md
Normal file
@ -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.
|
31
szutil_lua/init.lua
Normal file
31
szutil_lua/init.lua
Normal file
@ -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
|
||||||
|
})
|
3
szutil_lua/mod.conf
Normal file
3
szutil_lua/mod.conf
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
name = szutil_lua
|
||||||
|
description = Arbitrary lua code chat command
|
||||||
|
supported_games = *
|
Loading…
x
Reference in New Issue
Block a user