Calling a function from a string

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
MrPickle
Prole
Posts: 24
Joined: Thu Jul 10, 2008 11:43 pm
Location: United Kingdom, Lincolnshire

Calling a function from a string

Post by MrPickle » Fri Aug 15, 2008 11:32 am

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")

User avatar
hagish
Citizen
Posts: 85
Joined: Thu May 01, 2008 12:51 pm
Contact:

Re: Calling a function from a string

Post by hagish » Fri Aug 15, 2008 12:03 pm

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. 

MrPickle
Prole
Posts: 24
Joined: Thu Jul 10, 2008 11:43 pm
Location: United Kingdom, Lincolnshire

Re: Calling a function from a string

Post by MrPickle » Sat Aug 16, 2008 11:14 am

Thanks

Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests