Eval function for Lua?

Is there an “eval” function available to Corona devs? In general this could be useful in a number of use cases, but right now I simply want to write a function that accepts the name of a variable as a string or even any valid expression as a string and returns the evaluated result.

John [import]uid: 75226 topic_id: 34882 reply_id: 334882[/import]

Lua has such a function but it is disabled by Corona because Apple doesn’t allow it…

If you want to calculate a math string expression, I’ve personally done this using the “shunting yard” algorithm:
http://en.wikipedia.org/wiki/Shunting-yard_algorithm

Using this algorithm we have built our Math app called Mathemagica which is available for iOS and Android. All the drills are based on a randomly generated strings, and we calculate the right result using this algorithm.
[import]uid: 80469 topic_id: 34882 reply_id: 138619[/import]

Yeah, I was wondering if that would be allowed. Thanks for letting me know so quickly.

My immediate need was to get the value of a variable at runtime given its name as a string.

There are ways to retrieve arrays of all the local, global, and intermediate scope variables through a debug library, so I could retrieve those arrays and do a lookup for the specific variable name. I just didn’t know if there was a more direct way to do this for variables. Do you know if such a beast already exists. I’m sure someone’s skinned this cat before. Otherwise, how would the various Corona IDEs allow variables to be evaluated and watched?

I only need to use it in a debug context during development. I would not execute such logic in production code.

John
[import]uid: 75226 topic_id: 34882 reply_id: 138623[/import]

Lua has such a function but it is disabled by Corona because Apple doesn’t allow it…

If you want to calculate a math string expression, I’ve personally done this using the “shunting yard” algorithm:
http://en.wikipedia.org/wiki/Shunting-yard_algorithm

Using this algorithm we have built our Math app called Mathemagica which is available for iOS and Android. All the drills are based on a randomly generated strings, and we calculate the right result using this algorithm.
[import]uid: 80469 topic_id: 34882 reply_id: 138619[/import]

Yeah, I was wondering if that would be allowed. Thanks for letting me know so quickly.

My immediate need was to get the value of a variable at runtime given its name as a string.

There are ways to retrieve arrays of all the local, global, and intermediate scope variables through a debug library, so I could retrieve those arrays and do a lookup for the specific variable name. I just didn’t know if there was a more direct way to do this for variables. Do you know if such a beast already exists. I’m sure someone’s skinned this cat before. Otherwise, how would the various Corona IDEs allow variables to be evaluated and watched?

I only need to use it in a debug context during development. I would not execute such logic in production code.

John
[import]uid: 75226 topic_id: 34882 reply_id: 138623[/import]

I was looking for something similar … so I wrote one myself.  It can take a string of math and returns a number:

x = evalMath( "3\*(2+1)" ) print( x )   -- prints 6

Another function, evalString, takes a table of key-value pairs and substitutes them into the string first, then calculates the result.

More info:  http://developer.coronalabs.com/node/38357

(I saw a couple of people looking for this … sorry if you see double-posting)

I was looking for something similar … so I wrote one myself.  It can take a string of math and returns a number:

x = evalMath( "3\*(2+1)" ) print( x )   -- prints 6

Another function, evalString, takes a table of key-value pairs and substitutes them into the string first, then calculates the result.

More info:  http://developer.coronalabs.com/node/38357

(I saw a couple of people looking for this … sorry if you see double-posting)