Make: foreach take any pair data

This commit is contained in:
Coder12a 2019-10-15 11:19:31 -05:00
parent 9aaba0eca6
commit 6096d5601a
2 changed files with 3 additions and 3 deletions

View File

@ -27,7 +27,7 @@ end, function() minetest.log("Callback") end)
5. run throught each element in a table.
```lua
local array = {"start", "text2", "text3", "text4", "text5", "end"}
async.foreach(array, function(k, v)
async.foreach(pairs(array), function(k, v)
minetest.log(v)
end, function() minetest.log("Callback") end)
```

View File

@ -68,11 +68,11 @@ function async.Async()
return
end)
end
self.foreach = function(array, func, callback)
self.foreach = function(_pairs, func, callback)
self.create_worker(function()
local last_time = minetest.get_us_time() / 1000
local maxtime = self.maxtime
for k,v in ipairs(array) do
for k, v in _pairs do
local b = func(k, v)
if b ~= nil and b == false then
break