Finished manual gearbox
This commit is contained in:
@@ -93,3 +93,15 @@ function table.find(tbl, predicate)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function table.reduce(tbl, func, init)
|
||||
init = init or 0
|
||||
|
||||
local accum = init
|
||||
|
||||
for _, field in ipairs(tbl) do
|
||||
accum = accum + func(field)
|
||||
end
|
||||
|
||||
return accum
|
||||
end
|
||||
|
||||
14
koptilnya/libs/watcher.txt
Normal file
14
koptilnya/libs/watcher.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
function watcher(expr, cbk)
|
||||
local lastVal = expr()
|
||||
|
||||
return function()
|
||||
local newVal = expr()
|
||||
|
||||
if newVal == lastVal then
|
||||
return
|
||||
end
|
||||
|
||||
cbk(newVal, lastVal)
|
||||
lastVal = newVal
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user