lua-users home
lua-l archive

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


Hi =)

Suppose I'd like to keep references to a bunch of lua_Objects that were passed to my C function by Lua. The reference manual (no pun intended) says that lua_ref() will obtain a reference to the lua_Object that's on top of the stack, but does this apply for the "getting arguments" situation? In other words, is this the right way to obtain references to passed arguments (for later use), or am I way off? In the likely event that I'm "way off" -- how is this done correctly?

void my_Lua_callable_function()
{
  int ref_to_param_1 = lua_ref(1);
  lua_pop();
  int ref_to_param_2 = lua_ref(1);
  lua_pop();

  // etc ...
}

Another approach I can think of is to push all the arguments using lua_pushobject(lua_lua2C(N)), and then use the lua_ref() interface with the stack that was just created, but I have a feeling that that's a particularly cruddy way to do things. Any ideas?

Thanks,
Cyril.