lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Yes, try dostring(), just remember to prefix the formula with "return ".

//Andreas

Oldřich Švec skrev:
And is there a way how to calculate fe. such string "(5+1+4)^(3+4)/5" so I dont need to change it into "5"+"1"..... The problem is that I get the formulas in string form... and I dont want to add " " all the time manualy
Oldrich Svec
______________________________________________________________
Od: kapheine@gmail.com
Komu: "Lua list" <lua@bazar2.conectiva.com.br>
CC: Datum: 27.04.2006 23:43
Předmět: Re: print("-5.3e - 10"*"2") doesnt work :/

On 4/27/06, Oldrich Svec <OLDRICH.SVEC@CENTRUM.CZ>wrote:
Here (http://www.lua.org/pil/2.4.html) you can find an example of using
strings (print("-5.3e - 10"*"2")) but it doesn't work(attempt to perform
arithmetic on a string value)... I use Lua 5.1.
Generaly I want to use it to calculate strings (fe. "5+1+4" =>
print("5+1+4"+"0") should give 10 but it doesnt work.. :(
In this case, "-5.3e - 10" isn't recognized as a number. Try
"-5.3e-10"*"2", which is recognized as a number.

"5+1+4"+"0" doesn't work because "5+1+4" is not a number. You would
have to do print("5"+"1"+"4"+"0") instead.

--
Zachary P. Landau <KAPHEINE@GMAIL.COM>