Besides the old a,b=1,2
, you can also say a,b=getpair()
where getpair()
returns more than one value. This is kind of strange, because you would expect that Lua would try and leverage on its built in dictionary type, not the sub-set of lists. But its in there, though it works kind of strange. For instance, if you try to cascade return values (lists) together, it doesn't really work:
function a(x) return x,x*2,x*4 end function b(x) return x,x*3,x*9 end =a(10) 10 20 30 =b(10) 10 30 90 =a(10),b(10) 10 10 30 90So if you're making a list, the only thing that can return a list is the last item in the list. This of course has not yet been mentioned in the documentation (they don't want to show things coming apart at the seems yet), but I did run across somebody discussing this in my original foray looking into Lua.
You can hack things up by making one function take the other function:
function a(x,fn) return x,x*2,x*4,fn(x) end =a(10,b) 10 20 40 10 30 90which will even let you use anonymous functions
=a(10,function(x) return x,x*x,x*x*x end) 10 20 40 10 100 1000Of course if you forget the function, its not very happy, so I attempted to make it more robust:
a=function(x,fn) return x,x*2,x*4,fn and fn(x) end -- you can use asignment interchangably with named definitions =a(10) 10 20 40 nil =a(10,b) 10 20 40 10Hmmm, not so good. Making a table didn't work any better because then you get a table reference back, not a set. You get into similar trouble in Perl right around now, but perl has the dereference operator and slice functions, and I don't know what the equivilent is Lua is yet. Oh well, enough fun for one night.
Feb '04
Oops I dropped by satellite.
New Jets create excitement in the air.
The audience is not listening.
Mar '04
Neat chemicals you don't want to mess with.
The Lack of Practise Effect
Apr '04
Scramjets take to the air
Doing dangerous things in the fire.
The Real Way to get a job
May '04
Checking out cool tools (with the kids)
A master geek (Ink Tank flashback)
How to play with your kids