Is it possible to do this:
function calculate(str) --do stuff with "str" return str end string = "1+2/3-2^(2*2.4)" result = calculate(string) print(result)
Is it possible to make a function to calculate what is in the string?
The easiest way to do it is to use the loadstring function. The thing this function does, is, it returns a function that does what you tell it, but through a string.
For example,
local func = loadstring("print'hello world'") func() --> hello world
Now, we can use this to calculate strings.
function calculate(str) local str2 = loadstring("return "..str)() -- the same as function() return [anything] end return str2 end
I hope it helped.
Look up string patterns and string function dump on the wiki.
or try tonumber(string)