Stu's Rusty Bucket

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
.exex.lua:9attempt to concatenate field 'first' (a nil value)
stack traceback:
x.lua:9in function 'printName'
x.lua:13in 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

Posted by on 10/19 at 09:42 AM    
Filed Under : Development
Comments are closed There are no comments on this entry.

Next entry: little one

Previous entry: GP2X dev : Fishguts I

<< Back to main