[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Eval a Lua expression
- From: Eugen-Andrei Gavriloaie <shiretu@...>
- Date: Wed, 2 Apr 2008 23:06:09 +0300
Hi,
Sorry if this is a stupid question. But either I can't find the
answer in the docs because of a "selective" blindness or it's not so
obvious (I'm a newbie in Lua world). So here is the question:
Suppose we have a Lua file like this:
-- begin cut --
applications=
{
{
name="selector",
description="Application for selecting the rest of
the applications",
database=
{
type="postgresql",
connectingString="postgresql connecting
string....",
workersCount=10
}
},
{
name="simpleLive",
description="Sample application",
database=
{
type="mysql",
connectingString="postgresql connecting
string....",
workersCount=10
}
}
}
-- end cut --
This is in fact a part of a configuration file. I can load it, extract
all the data I need from it using lua_gettable and such, but my c++
code is looking very ugly. Because I keep pushing and popping from the
stack and other things like that. Is there a method of evaluating an
expression in the present lua context? Here is what I want:
lua_evaluate_expression(L,"applications[2].type"); // expect to find
`mysql` string pushed into the stack after this call
or
lua_evaluate_expression(L,"#applications"); // expect to find value of
2 pushed into the stack after this call
This is supposed to push the result of the expression into the stack.
After that, I will pop it up from there and do whatever I want with
it. The end resulting c++ code would be much cleaner and easy to
understand.
Thank you