Error: load() is not available because the parser is not loaded

I need the equivalent of eval() which since Lua 5.2 is load().

All of the formulas are simple calculations using only * / + - and parentheses, and look something like this:

(((49))\*100+1000)\*-1

But

print(load("return (((49))\*100+1000)\*-1")())

gives the error message in the topic title.

a ) How do I load the parser?
b ) Are there alternatives?
c ) Is there any way in which I can evaluate these using the Corona SDK short of rolling my own eval()?

d ) Has someone rolled their own eval()?

Corona has a built in Lua 5.1 parser/compiler.  We don’t support load().  However we do allow but don’t encourage the use of loadstring() which will do what you want. We explicitly block load(), dofile() and loadfile(). Apple doesn’t like apps that can program themselves.

There are also several math parsers out there that’s Lua code to do the work:  https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=lua+math+parser

What is your use case for this?

Rob

Loadstring works perfectly! I’ll correct the liars on StackOverflow. :wink: Thanks!

 

Parsing mathematical expressions is not executing code. Lua has the full parser instead of an eval() function, but I couldn’t find one in the results of your link…? It’s for calculating answers to generated dynamic math problems (educational).

Corona has a built in Lua 5.1 parser/compiler.  We don’t support load().  However we do allow but don’t encourage the use of loadstring() which will do what you want. We explicitly block load(), dofile() and loadfile(). Apple doesn’t like apps that can program themselves.

There are also several math parsers out there that’s Lua code to do the work:  https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=lua+math+parser

What is your use case for this?

Rob

Loadstring works perfectly! I’ll correct the liars on StackOverflow. :wink: Thanks!

 

Parsing mathematical expressions is not executing code. Lua has the full parser instead of an eval() function, but I couldn’t find one in the results of your link…? It’s for calculating answers to generated dynamic math problems (educational).