lua-users home
lua-l archive

Lua C Return problem

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


Hi there,

Here at work I need to write a lua function (A) that returns another lua function (B) which returns itself unless it gets nil arguments. It's like:

function A(teste)
function B(m,n)
if(m and n) then
return B
else
return
end
end
return A
end

I know how to do it using Lua, but in face of some decisions in here, it must be written inside a class of C++. This way, I've been using the library lunar.h which I found on this post http://lua-users.org/wiki/CppBindingWithLunar at the lua-users wiki.

This said, my approach was to first write function B inside the class and then function A, both returning function B, which came out this way:

int B(lua_State *L){
int m,n;
if(strcmp(luaL_typename(L,1),"number") == 0){
m = (int)luaL_checknumber(L,1);
n = (int)luaL_checknumber(L,2);
}
else{
lua_pushcfunction(L,drawer);
return 1;
}
}
int A(lua_State *L){
char* teste;
teste = (char*)lua_tostring(L,1);
lua_pushcfunction(L,drawer);
return 1;
}


This code inside the class gives the following error:

In member function 'int Classe::B(lua_State*)':
317: error: argument of type 'int (Classe::)(lua_State*)' does not match 'int (*)(lua_State*)'
In member function 'int Classe::A(lua_State*)':
327: error: argument of type 'int (Classe::)(lua_State*)' does not match 'int (*)(lua_State*)'

Lines 317 and 327 are the lines in which I call lua_pushcfunction. So, how should I do it? Is it possible to do this?


Thanks in advance,
Rodrigo Araujo

AltStyle によって変換されたページ (->オリジナル) /