lua-users home
lua-l archive

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


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