2024-04-21 23:33:55 +02:00
local S = minetest.get_translator ( " worldedit_commands " )
local function check_region ( name )
return worldedit.volume ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
end
worldedit.register_command ( " lua " , {
params = " <code> " ,
description = S ( " Executes <code> as a Lua chunk in the global namespace " ) ,
category = S ( " Code " ) ,
privs = { worldedit = true , server = true } ,
parse = function ( param )
if param == " " then
return false
end
return true , param
end ,
func = function ( name , param )
-- shorthand like in the Lua interpreter
if param : sub ( 1 , 1 ) == " = " then
param = " return " .. param : sub ( 2 )
end
local err , ret = worldedit.lua ( param , name )
if err == nil then
minetest.log ( " action " , name .. " executed " .. param )
if ret ~= " nil " then
2024-04-22 17:33:16 +02:00
worldedit.player_notify ( name , " code successfully executed, returned " .. ret , " info " )
2024-04-21 23:33:55 +02:00
else
2024-04-22 17:33:16 +02:00
worldedit.player_notify ( name , " code successfully executed " , " ok " )
2024-04-21 23:33:55 +02:00
end
else
minetest.log ( " action " , name .. " tried to execute " .. param )
2024-04-22 17:33:16 +02:00
worldedit.player_notify ( name , " code error: " .. err , " error " )
2024-04-21 23:33:55 +02:00
end
end ,
} )
worldedit.register_command ( " luatransform " , {
params = " <code> " ,
description = S ( " Executes <code> as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region " ) ,
category = S ( " Code " ) ,
privs = { worldedit = true , server = true } ,
require_pos = 2 ,
parse = function ( param )
return true , param
end ,
nodes_needed = check_region ,
func = function ( name , param )
local err = worldedit.luatransform ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] , param )
if err then
2024-04-22 17:33:16 +02:00
worldedit.player_notify ( name , " code error: " .. err , " error " )
2024-04-21 23:33:55 +02:00
minetest.log ( " action " , name .. " tried to execute luatransform " .. param )
else
2024-04-22 17:33:16 +02:00
worldedit.player_notify ( name , " code successfully executed " , " ok " )
2024-04-21 23:33:55 +02:00
minetest.log ( " action " , name .. " executed luatransform " .. param )
end
end ,
} )