]> git.lizzy.rs Git - worldedit.git/commitdiff
CPS-ifying stack
authorCy <whatever>
Thu, 10 Jul 2014 06:50:41 +0000 (23:50 -0700)
committerCy <whatever>
Thu, 10 Jul 2014 06:50:41 +0000 (23:50 -0700)
Continuation Passing Style lets me use minetest.after, so the server
gets a chance to not hang in between every stack iteration. Could even
set minetest.after(1000,nextone) if you want to see it extend once every
second.

worldedit/manipulations.lua

index a80de8f07c5d0752eb1c8f2a539294766a87fefd..2fa9a1e712cc7adbd3c70934e27ab98d7619f0ce 100644 (file)
@@ -420,13 +420,19 @@ worldedit.stack = function(pos1, pos2, axis, count)
        if count < 0 then\r
                count = -count\r
                length = -length\r
-       end\r
-       local amount = 0\r
-       local copy = worldedit.copy\r
-       for i = 1, count do\r
-               amount = amount + length\r
-               copy(pos1, pos2, axis, amount)\r
-       end\r
+    end\r
+    local amount = 0\r
+    local copy = worldedit.copy\r
+    local i = 1\r
+    function nextone() \r
+        if i <= count then\r
+            i = i + 1\r
+            amount = amount + length\r
+            copy(pos1, pos2, axis, amount)\r
+            minetest.after(0,nextone)\r
+        end\r
+    end\r
+    nextone()\r
        return worldedit.volume(pos1, pos2) * count\r
 end\r
 \r