-worldedit = worldedit or {}\r
-local minetest = minetest -- local copy of global\r
+--- Lua code execution functions.\r
+-- @module worldedit.code\r
\r
--- Copies and modifies positions `pos1` and `pos2` so that each component of\r
--- `pos1` is less than or equal to the corresponding component of `pos2`.\r
--- Returns the new positions.\r
-worldedit.sort_pos = function(pos1, pos2)\r
- pos1 = {x=pos1.x, y=pos1.y, z=pos1.z}\r
- pos2 = {x=pos2.x, y=pos2.y, z=pos2.z}\r
- if pos1.x > pos2.x then\r
- pos2.x, pos1.x = pos1.x, pos2.x\r
- end\r
- if pos1.y > pos2.y then\r
- pos2.y, pos1.y = pos1.y, pos2.y\r
- end\r
- if pos1.z > pos2.z then\r
- pos2.z, pos1.z = pos1.z, pos2.z\r
- end\r
- return pos1, pos2\r
-end\r
-\r
--- Executes `code` as a Lua chunk in the global namespace,\r
--- returning an error if the code fails, or nil otherwise.\r
-worldedit.lua = function(code)\r
+--- Executes `code` as a Lua chunk in the global namespace.\r
+-- @return An error message if the code fails, or nil on success.\r
+function worldedit.lua(code)\r
local func, err = loadstring(code)\r
if not func then -- Syntax error\r
return err\r
return nil\r
end\r
\r
--- Executes `code` as a Lua chunk in the global namespace with the variable\r
+\r
+--- Executes `code` as a Lua chunk in the global namespace with the variable\r
-- pos available, for each node in a region defined by positions `pos1` and\r
--- `pos2`, returning an error if the code fails, or nil otherwise\r
-worldedit.luatransform = function(pos1, pos2, code)\r
+-- `pos2`.\r
+-- @return An error message if the code fails, or nil on success.\r
+function worldedit.luatransform(pos1, pos2, code)\r
pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
\r
local factory, err = loadstring("return function(pos) " .. code .. " end")\r
end\r
local func = factory()\r
\r
- -- Keep area loaded\r
- local manip = minetest.get_voxel_manip()\r
- manip:read_from_map(pos1, pos2)\r
+ worldedit.keep_loaded(pos1, pos2)\r
\r
local pos = {x=pos1.x, y=0, z=0}\r
while pos.x <= pos2.x do\r