[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: transferring logical expression from lua to c
- From: Duncan Cross <duncan.cross@...>
- Date: Wed, 19 Oct 2011 14:05:50 +0100
On Wed, Oct 19, 2011 at 1:21 PM, Oskar Forsslund
<matrixsmurfen@googlemail.com> wrote:
> Can anyone think of a good way to transfer logical expressions from lua to
> c.
> expressions like
> func() and func2() and (func3() or func4())
Example 1: (A and B) via the C API:
/* (... put A on top of the stack ...) */
if (lua_toboolean(L, -1)) {
lua_pop(L, 1); // remove A
/* (... put B on top of the stack ...) */
}
// (A and B) now at the top of the stack
Example 2: (A or B) via the C API:
/* (... put A on top of the stack ...) */
if (!lua_toboolean(L, -1)) {
lua_pop(L, 1); // remove A
/* (... put B on top of the stack ...) */
}
// (A or B) now at the top of the stack
-Duncan