lua-users home
lua-l archive

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

If you need to get return values via loadstring, how about:

loadstring( "return "..funcName.."()" ) ()

..But I fail to see why you couldn't simply:


Functions don't have names in Lua; they are just values in variables. So you can toss them around as you would any value. Hope this helps?


Terisquas Brothers kirjoitti 17.12.2006 kello 15.18:

I have this code:

function funcXY(param) print (param); end;

This function is used in a coroutine which receives
some parameters. Sometimes I have to restart a
coroutine, however the file has probably been modified
and reloaded, so I can't store the function funcXY "as
is", so I have to its name "funcXY"

my idea would be doing something like

loadstring (funcName.."()"); --<-- this would be the
function to be called, with a parameter

however loadstring expands this to:

function () funcXY(); end;

where no parameters can be passed to funcXY

Is there any way to convert the string funcName to a
function which accepts a single parameter?


Try the all-new Yahoo! Mail. "The New Version is radically easier to use" – The Wall Street Journal