[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Returning data from C functions called using "loadlib".
- From: Ignacio Burgueño <ignacio@...>
- Date: Tue, 31 Aug 2004 12:43:04 -0300
> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br
> [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Aaron Newell
> Sent: Martes, 31 de Agosto de 2004 12:30
> To: lua@bazar2.conectiva.com.br
> Subject: Re: Returning data from C functions called using "loadlib".
>
> Thanks but that doesnt seem to work:
>
> extract from c file:
> static int functionFromCLibrary(lua_State* L) {
> int a = (int)lua_tonumber(L, -1);
> printf("cfunction: %d\n", a);
> a = a + 1;
> printf("cfunction now: %d\n", a);
> return a;
> }
>
I'm quite sure that C code is wrong. You need to push a onto the stack, and
then return how many results your function is returning. So the function
would be something like:
static int functionFromCLibrary(lua_State* L) {
int a = (int)lua_tonumber(L, -1);
printf("cfunction: %d\n", a);
a = a + 1;
printf("cfunction now: %d\n", a);
lua_settop(L, 0);
lua_pushnumber(L, a);
return 1;
}
Greetings,
Ignacio Burgueño