Dear sirs,
Does anyone know a Lua Expression Library to solve expressions/formulas “excel-like” ?
Thank you!
Marcos Tito.
Dear sirs,
Does anyone know a Lua Expression Library to solve expressions/formulas “excel-like” ?
Thank you!
Marcos Tito.
Evaluating expressions Excel-like ? Mmmh…How is that working for you ?
local function eval(str) return loadstring('return '..str)() end -- Example print(eval('2\*math.pi')) --\> prints '6.2831853071796'
Well it has its own limitations, tho. loadstring works only with globals, not locals.
Didn’t know corona uses loadstring
Good point, Jstrahan. My mistake, Corona doesn’t support loadstring, for security reasons.
Well, it seems there’s no simple option. You might have to implement your own evaluation function.
This might be a good start. As a pointer, you might want to take a closer look to the Shunting-Yard algorithm.
Evaluating expressions Excel-like ? Mmmh…How is that working for you ?
local function eval(str) return loadstring('return '..str)() end -- Example print(eval('2\*math.pi')) --\> prints '6.2831853071796'
Well it has its own limitations, tho. loadstring works only with globals, not locals.
Didn’t know corona uses loadstring
Good point, Jstrahan. My mistake, Corona doesn’t support loadstring, for security reasons.
Well, it seems there’s no simple option. You might have to implement your own evaluation function.
This might be a good start. As a pointer, you might want to take a closer look to the Shunting-Yard algorithm.
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 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