lua-users home
lua-l archive

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


> How do I return a 2d table from a C-function (I'm using Lua 5)? So
> far I have managed to return a vector from a C-function using
> lua_newtable()-function. Code example would be nice.

Create a vector of vectors.  You can use lua_rawseti to populate the
vectors.

/* matrix */
lua_newtable(L);

/* first vector */
lua_newtable(L);
/* populate first vector here ... */

lua_rawseti(L, -2, 1);

/* second vector */
lua_newtable(L);
/* populate second vector here ... */

lua_rawseti(L, -2, 2);

/* etc. */

/* matrix is at top of stack */
return 1;

--
Wim