lua-users home
lua-l archive

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

>From Sun Jun 28 20:52:59 1998
>In looking into my problem, I don't understand why this works:
>static void next (void)
>  lua_Object o = luaL_tablearg(1);
>  lua_Object r = luaL_nonnullarg(2);
>  Node *n = luaH_next(luaA_Address(o), luaA_Address(r));
>  if (n) {
>    luaA_pushobject(&n->ref);
>    luaA_pushobject(&n->val);
>  }
>Why is arg2 checked to be a nonnullarg? It's a property of next that if
>you call it with a second arg == nil, then it starts at the beginning of
>the list. This seems to actually WORK like that, but I don't understand,
>given the code above, why I don't get an error when I do: "next(foo,nil)"
>within lua.

luaL_nonnullarg checks compares with LUA_NOOBJECT, which is not the same as nil.
here is luaL_nonnullarg:

lua_Object luaL_nonnullarg (int numArg)
  lua_Object o = lua_getparam(numArg);
  luaL_arg_check(o != LUA_NOOBJECT, numArg, "value expected");
  return o;

lua_getparam (which is really lua_lua2C) returns LUA_NOOBJECT when you ask
for a non-existent param.
again, this is not the same as a param with value nil.

a C function that is registered in Lua should compare the value returned by
with LUA_NOOBJECT to know when to stop getting params.