summaryrefslogtreecommitdiff
path: root/worldedit
diff options
context:
space:
mode:
authorAnthony Zhang <azhang9@gmail.com>2013-01-12 18:20:41 -0500
committerAnthony Zhang <azhang9@gmail.com>2013-01-12 18:20:41 -0500
commite2f1c4ef174443b2807aa94a209261546bbf19fb (patch)
tree8e81c6141d2b7823b1112308fbddcfed1b2df2b1 /worldedit
parentc27ab877f1bc8afde76f9cfe11c7880cec9bdda2 (diff)
Add //homogenize, //lua, and //luatransform commands, as well as their documentation.
Diffstat (limited to 'worldedit')
-rw-r--r--worldedit/code.lua43
-rw-r--r--worldedit/init.lua10
2 files changed, 49 insertions, 4 deletions
diff --git a/worldedit/code.lua b/worldedit/code.lua
new file mode 100644
index 0000000..ee2d340
--- /dev/null
+++ b/worldedit/code.lua
@@ -0,0 +1,43 @@
+worldedit = worldedit or {}
+
+--executes `code` as a Lua chunk in the global namespace, returning an error if the code fails or nil otherwise
+worldedit.lua = function(code)
+ local operation, message = loadstring(code)
+ if operation == nil then --code parsing failed
+ return message
+ end
+ local status, message = pcall(operation)
+ if status == nil then --operation failed
+ return message
+ end
+ return nil
+end
+
+--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
+worldedit.luatransform = function(pos1, pos2, code)
+ local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
+
+ local factory, message = loadstring("return function(pos) " .. code .. " end")
+ if factory == nil then --code parsing failed
+ return message
+ end
+ local operation = factory()
+
+ local pos = {x=pos1.x, y=0, z=0}
+ while pos.x <= pos2.x do
+ pos.y = pos1.y
+ while pos.y <= pos2.y do
+ pos.z = pos1.z
+ while pos.z <= pos2.z do
+ local status, message = pcall(operation, pos)
+ if status == nil then --operation failed
+ return message
+ end
+ pos.z = pos.z + 1
+ end
+ pos.y = pos.y + 1
+ end
+ pos.x = pos.x + 1
+ end
+ return nil
+end \ No newline at end of file
diff --git a/worldedit/init.lua b/worldedit/init.lua
index 6f841eb..948d317 100644
--- a/worldedit/init.lua
+++ b/worldedit/init.lua
@@ -1,4 +1,6 @@
-dofile(minetest.get_modpath("worldedit") .. "/manipulations.lua")
-dofile(minetest.get_modpath("worldedit") .. "/primitives.lua")
-dofile(minetest.get_modpath("worldedit") .. "/visualization.lua")
-dofile(minetest.get_modpath("worldedit") .. "/serialization.lua") \ No newline at end of file
+local path = minetest.get_modpath("worldedit")
+dofile(path .. "/manipulations.lua")
+dofile(path .. "/primitives.lua")
+dofile(path .. "/visualization.lua")
+dofile(path .. "/serialization.lua")
+dofile(path .. "/code.lua") \ No newline at end of file