1 worldedit = worldedit or {}
\r
2 local minetest = minetest --local copy of global
\r
4 --executes `code` as a Lua chunk in the global namespace, returning an error if the code fails or nil otherwise
\r
5 worldedit.lua = function(code)
\r
6 local operation, message = loadstring(code)
\r
7 if operation == nil then --code parsing failed
\r
10 local status, message = pcall(operation)
\r
11 if status == nil then --operation failed
\r
17 --executes `code` as a Lua chunk in the global namespace with the variable pos available, for each node in a region defined by positions `pos1` and `pos2`, returning an error if the code fails or nil otherwise
\r
18 worldedit.luatransform = function(pos1, pos2, code)
\r
19 local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
\r
21 local factory, message = loadstring("return function(pos) " .. code .. " end")
\r
22 if factory == nil then --code parsing failed
\r
25 local operation = factory()
\r
27 --make area stay loaded
\r
28 local manip = minetest.get_voxel_manip()
\r
29 manip:read_from_map(pos1, pos2)
\r
31 local pos = {x=pos1.x, y=0, z=0}
\r
32 while pos.x <= pos2.x do
\r
34 while pos.y <= pos2.y do
\r
36 while pos.z <= pos2.z do
\r
37 local status, message = pcall(operation, pos)
\r
38 if status == nil then --operation failed
\r