lua-users home
lua-l archive

Re: loadstring to create a function with parameters

[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:
funcXY()
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?
-asko
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
funcName="funcXY";
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?
TIA
Kak
		
___________________________________________________________
Try the all-new Yahoo! Mail. "The New Version is radically easier to use" – The Wall Street Journal
http://uk.docs.yahoo.com/nowyoucan.html

AltStyle によって変換されたページ (->オリジナル) /