lua-users home
lua-l archive

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


On Thursday 30 March 2006 9:18 am, Alexander Gladysh wrote:
> > You can define a placeholder for false...
> Unfortunately, I need to have all tables in "honest" state, so such
> joined usage would be completely transparent for their other users.

another solution with a C function... (luaTCC in this case ;-)  ) it returns 
the first non-nil parameter:

require "lua_tcc"
getfirst = tcc.compile ([[
  #include "lua.h"

  int getfirst (lua_State *L) {
    int i, n = lua_gettop (L);
		
    for (i = 1; i <= n; i++) {
      if (!lua_isnil (L, i)) {
        lua_settop (L, i);
        return 1;
      }
    }
    return 0;
  }

]], "getfirst")

print (getfirst (nil,1,2))
==> 1
print (getfirst (nil, false,2))
==> 2

use it as:
  return getfirst (A[k], B[k], C[k])


-- 
Javier

Attachment: pgprhBE84z72b.pgp
Description: PGP signature