function clone (t) -- t is a table local new_t = {} -- creates a new table local i, v = next(t, nil) -- i is an index of t, v = t[i] while i do new_t[i] = v i, v = next(t, i) -- get next index end return new_t end
The next example prints the names of all global variables
in the system with non nil values:
function printGlobalVariables ()
local i, v = nextvar(nil)
while i do
print(i)
i, v = nextvar(i)
end
end