Consider some simple situation like:
Code: Select all
function myFunc ( input )
print ( "input: " .. input)
end
myFunc ( 5 ) -- prints: input: 5
myFunc ( "5" ) -- prints: input: 5
myFunc ( false ) -- error: attempt to concatenate local 'input' (a boolean value)
myFunc ( {} ) -- error: attempt to concatenate local 'input' (a table value)
Lua simply does some
implicit type conversion from numbers to strings if applicable to the situation, like string concatenation. It won't do the conversion for all variable types and simply throws an error, though, as shown above. Ultimately, it depends on the function and its implementation, since the function may do some type checking (eq. with assert) even if it otherwise would work.
As for _G, you can traverse it just like any other table:
Code: Select all
for globalKey, globalVariableValue in pairs (_G) do
print ( globalKey, globalVariableValue )
end
someGlobalTable = {
-- etc
}
for k, v in pairs (_G.someGlobalTable) do
print ( k, v )
end