lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


No where in your code do you define "MyFunction" in the table...until you
define the function, its nil in the table. You could do (I think):

Table[Function] = function()
	print("Hello World")
end

Table[Function]()

but you have to define the function somewhere along the way. Your trying to
get the value at index "MyFunction", but you never define it, thus your
calling a nil value.

Matt

-----Original Message-----
From: owner-lua-l@tecgraf.puc-rio.br
[mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of nikdo79
Sent: Monday, March 25, 2002 1:41 PM
To: Multiple recipients of list
Subject: Syntactic Sugar for function??


Hi there,

Today i wanted to do this:


Table={}
local Function="MyFunction"
function Table[Function] ()
   print("Hello World")
end

and i got an error!

I thought

function Var() ... end

was full "syntatic sugar" for

Var = function () ... end

but it sad-to-know isn't because

Table[Function] = function ()
   print("Hello World")
end

works fine.

What's the Problem? A Bug? Or even intenion?

Regards,
   Dominik