[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: loadstring to create a function with parameters
- From: Asko Kauppi <askok@...>
- Date: Sun, 17 Dec 2006 15:52:02 +0200
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