Call a Lua method on instance from C++

Remi Gillig <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
[I couldn't find the search function for this mailing list on
sourceforge, sorry if this has already been asked]

Hello,

I am trying to conceptualize some things with luabind and I would like
to do something specific but there is not much information on how to
achieve that.

What I want to do is be able to call from C++ a method that was
created on an instance of an object in Lua.

e = Entity("Hello")

function e:update()
    print("update Hello")
end

>From the C++ side, I also have an update() function on the class
Entity and I would like to call the Lua defined method inside it.

I tried a couple of things like making a wrapper with base_wrap but I
couldn't do it without creating another class, or also something like
creating a self object directly from the this pointer :

void update()
{
    printf("Entity::update()\n");

    object self(L, *this);

    int t = type(gettable(self, "update"));
    printf("type %i\n", t);
    if (t == LUA_TFUNCTION)
        call_member<void>(self, "update");
}

Well that didn't work (obviously) so I ask my question here because
that would be a great technique for events. Thanks!

Remi Gillig.

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.