diff options
| author | Cy <whatever> | 2014-07-09 23:50:41 -0700 | 
|---|---|---|
| committer | Cy <whatever> | 2014-07-09 23:50:41 -0700 | 
| commit | f5b67c5bc2de047ec322c5e284bafe00becc84b1 (patch) | |
| tree | 5b4146d7c7b05572f0c62e70b8eaa4e13ab87b1e | |
| parent | 6084db9335c9c6576b00a4c169d29b83289f9282 (diff) | |
CPS-ifying stack
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.
| -rw-r--r-- | worldedit/manipulations.lua | 20 | 
1 files changed, 13 insertions, 7 deletions
| diff --git a/worldedit/manipulations.lua b/worldedit/manipulations.lua index a80de8f..2fa9a1e 100644 --- a/worldedit/manipulations.lua +++ b/worldedit/manipulations.lua @@ -420,13 +420,19 @@ worldedit.stack = function(pos1, pos2, axis, count)  	if count < 0 then
  		count = -count
  		length = -length
 -	end
 -	local amount = 0
 -	local copy = worldedit.copy
 -	for i = 1, count do
 -		amount = amount + length
 -		copy(pos1, pos2, axis, amount)
 -	end
 +    end
 +    local amount = 0
 +    local copy = worldedit.copy
 +    local i = 1
 +    function nextone() 
 +        if i <= count then
 +            i = i + 1
 +            amount = amount + length
 +            copy(pos1, pos2, axis, amount)
 +            minetest.after(0,nextone)
 +        end
 +    end
 +    nextone()
  	return worldedit.volume(pos1, pos2) * count
  end
 | 
