Page 1 of 1

Calling a function from a string

Posted: Fri Aug 15, 2008 11:32 am
by MrPickle
How can I call a function from a string in LUA?

EG I had a string like this: "DoMath("1+1")" and I wanted to use that string to call DoMath("1+1")

Re: Calling a function from a string

Posted: Fri Aug 15, 2008 12:03 pm
by hagish

Code: Select all

loadstring (string [, chunkname])

Similar to load, but gets the chunk from the given string.

To load and run a given string, use the idiom

     assert(loadstring(s))()

When absent, chunkname defaults to the given string. 

Re: Calling a function from a string

Posted: Sat Aug 16, 2008 11:14 am
by MrPickle
Thanks