Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function copy(table1, table2, positionFunction)
- if not table1 then return end
- local table3 = table2 or {}
- positionFunction = positionFunction or function() return true end
- local position = 0
- for index, value in next, table1 do
- position = position + 1
- if (positionFunction and positionFunction(index, value, position)) then
- table3[index] = value
- end
- end
- return table3
- end
- ------------------------------------------------------------------
- local example = {[1]="a", [2]="b", [3]="c", [4]="d", [5]="e", [6]="f"}
- local copied = copy(example, {}--[[, function(index, value, position)
- return position <= 4 --the result will be to copy only the first 4 things in "example" into an empty table
- end]])
- for i,v in next, copied do print(i,v) end --print out results
Advertisement
Add Comment
Please, Sign In to add comment