[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Evaluating expressions, not statements?
- From: "Paul E.C. Melis" <melis@...>
- Date: Thu, 5 Apr 2001 19:38:25 +0200
Is there a way to evaluate a Lua expression in the form of a string? There
only seems to be dostring() which will give an error if you pass it
something like "2+3*5".
I came up with the following to work around the problem, but it doesn't
function eval_string (str)
-- convert the expression to an assignment by prepending "<var> ="
stmt = "tempvar12345 = " .. str
res = dostring(stmt)
if res then
-- report an error
The problem with this is that I can't see a way to check if the expression
evaluates to nil or that dostring() simply returns nil because of an error.
I also don't it, because it's very ugly. Why is there no way to evaluate an
expression just like dostring() does for statements?