[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: References to tables
- From: Nick Trout <Nick.Trout@...>
- Date: Mon, 1 Jul 2002 12:37:51 +0100
> This seems like a question to which the answer should be
> obvious, but I'm
> going to double-check and ask it anyway. I'm wondering if
> it's possible to
> get a reference to a table which is passed to a C function,
> if that table is
> created during the function call with a table constructor, instead of
> created ahead of time. Here's an example of what I want to do:
Yes its possible to do what you say. Look at the Lua source code for
examples.
eg.
math_min for variable args.
luaB_tinsert table manipulation.
For parsing your table argument see previous post for lua2c.
Regards,
Nick
> C code snippet:
>
> int somecfunction(lua_State *L)
> {
> char *a_string;
> int table_reference;
>
> a_string = lua_tostring(L, 1);
> table_reference = lua_getref(L, 1);
> }
>
> Lua code snippet:
>
> x = {1st_number, 2nd_number, 3rd_number}
> somecfunction(a_string, x); -- I'm pretty sure this will work
> somecfunction(a_string, {1st_number, 2nd_number,
> 3rd_number}); -- but I'm
> not sure about this one.
>
> Will both of the above function calls work as expected? Also,
> since I'm
> asking, is the correct way to force Lua to perform a
> garbage-collection to
> call lua_setgcthreshold() with an argument of zero?
>