[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Returning 2d table from C-function
- From: "Wim Couwenberg" <w.couwenberg@...>
- Date: Thu, 3 Jul 2003 13:24:35 +0200
> 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