diff options
author | Uberi <azhang9@gmail.com> | 2014-07-22 18:42:15 -0400 |
---|---|---|
committer | Uberi <azhang9@gmail.com> | 2014-07-22 18:42:15 -0400 |
commit | 82ef580fae5634c48c0db1caf27966fdd046a64d (patch) | |
tree | f03cc31d8bb3fde97bf6422583fb7f323e6a591c /worldedit/code.lua | |
parent | 38fbc0a0461ea59c6d8a6dc9cd8b8cd24b374b24 (diff) |
Add `sort_pos` to make code module independent.
Diffstat (limited to 'worldedit/code.lua')
-rw-r--r-- | worldedit/code.lua | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/worldedit/code.lua b/worldedit/code.lua index 8e2d362..fb04ce9 100644 --- a/worldedit/code.lua +++ b/worldedit/code.lua @@ -1,6 +1,22 @@ worldedit = worldedit or {}
local minetest = minetest --local copy of global
+--modifies positions `pos1` and `pos2` so that each component of `pos1` is less than or equal to its corresponding conent of `pos2`, returning two new positions
+worldedit.sort_pos = function(pos1, pos2)
+ pos1 = {x=pos1.x, y=pos1.y, z=pos1.z}
+ pos2 = {x=pos2.x, y=pos2.y, z=pos2.z}
+ if pos1.x > pos2.x then
+ pos2.x, pos1.x = pos1.x, pos2.x
+ end
+ if pos1.y > pos2.y then
+ pos2.y, pos1.y = pos1.y, pos2.y
+ end
+ if pos1.z > pos2.z then
+ pos2.z, pos1.z = pos1.z, pos2.z
+ end
+ return pos1, pos2
+end
+
--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)
|