Lua is a strict dynamic language
Read an interesting article on sitepoint, its old in internet time, dating back to july of 2006.
It brings up the idea in dynamic languages on what one should do in the case of errors and how some dynamic languages handle it. Perl and PHP ignore the error and keep going, silently corrupting data while Python and Ruby halt execution and spit out an error message.
I decided to do the same test code in Lua, translating the ruby into Lua.
Its nice to see that it falls along the same lines as Ruby and Python and spits out an error message then halting.
names = {
{ first = "Bob", given = "Smith"},
{ given = "Lukas"},
{ first = "Mary", given ="Doe"},
};
function printName(name)
print("Name is " .. name.first .. " " .. name.given)
end
for x,y in pairs(names) do
printName(y)
end
and the runtime output is;
C:lua5.1>lua5.1.exe x.lua
Name is Bob Smith
lua5.1.exe: x.lua:9: attempt to concatenate field 'first' (a nil value)
stack traceback:
x.lua:9: in function 'printName'
x.lua:13: in main chunk
[C]: ?
Lua unfortunatly (imo) likes to co-erce things into strings and numbers when it can without explicitly being told to do so. lua
Filed Under : Development •
Comments are closed There are no comments on this entry.