lua-users home
lua-l archive

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


You could use the command design pattern where the Invoker has a
static invoke function which you could push into Lua as a closure with
some data pointing to a C++ functor containing you drawer member
function and class instance.

class Invoker
{
    static int invoke(lua_State *L)
{
   //get functor from upvalue index 1
   Functor *f = ...
    (*f)(L);
}
}

You could do this pretty easily with Loki's Functor class (
http://loki-lib.sourceforge.net/ ).  See Alexandrescu's Modern C++
Design for more info on this.

best,
wes



On Jan 9, 2008 11:21 AM, Ignacio Burgueño <ignaciob@inconcertcc.com> wrote:
> Rodrigo Araújo wrote:
> > Hi there,
> [...]
> > 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?
>
>
> Seems that your 'drawer' function is a member of your class. If so, you
> cannot use pushcfunction because it only allows non-member functions (or
> static ones) to be pushed.
>
> You can take a look at Lunar itself. When it registers in Lua your class
> functions, it actually registers a function called 'thunk', which
> retrieves the member function to be called using upvalues.
>
>
>
>