[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Access Lua's last evaluated result from C
- From: "Maggie Webb and Pete Kerr" <magnpete@...>
- Date: Wed, 14 May 2008 16:38:00 +0800
Hi
Is there a clean way I can access, from C, the last value computed by Lua,
if it wasn't assigned to a variable?
Here's why I want to do it:
My C application requires the user to specify parameter values in a file
like this
param1 3.5
param2 -0.4
I want to extend this by allowing the user to replace the explicit value
with some Lua code between dollar signs
param3 $ param2*1.5 $
If I send this chunk to Lua, how do I get the value back? If it was MATLAB,
say, I'd just fetch the value of variable ans, which always holds the last
value computed.
I could concatenate "param3=" with "param2*1.5" and fetch the value of
param3, but in more complex examples the user might submit a list of
statements with the last one evaluating to the required parameter value.
e.g.
param3 $ lots of code ; required_value $
I could of course insist on:
param3 $ lots of code ; param3 = required_value $
Which gives me the easy to read (by a human) list of parameter names down
the left, but forces the user to type param3 twice, which somehow seems
inelegant in the context of the already defined syntax for constant values.
Anyway, in another part of the input file, the user supplies simple values
without a name, where the requirement to supply one would be even more
clunky.
Thanks,
Pete Kerr