lua-users home
lua-l archive

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


My apologies if this has been covered recently on this list but I couldn’t find it in the archive.

 

I’m trying to pass a table containing functions as a parameter as follows:

 

local myTable =

{

            {‘hello’, nil, myFunc (3,4) },

            {‘not now’', nil, print(‘the end is nigh’) },

            {‘maybe later’, nil, anotherFunc(5,6) }

}

bigFunc(myTable);

 

where myFunc and anotherFunc are pre-declared functions and bigFunc is a function which _might_ call the 3rd entry in each subTable in myTable. The problem is that on calling bigFunc, the 3rd parameter of each subTable is always evaluated and the function is always called immediately, which is not desirable. Is there a way to suppress evaluation at call time or am I looking at this assways?

 

I’ve got around it by passing the function and its parameters in as a table

 

local myTable =

{

            {‘hello', nil, {myFunc,3,4 },

            {‘not now’', nil, {print,‘the end is nigh’} },

            …

}

bigFunc(myTable);

 

and then putting the function call together inside bigFunc but this feels like cheating given how flexible Lua is.

 

Thanks for any light you can throw on this

 

Colm