Re: To And From C++

Tony Kostanjsek <[email protected]> Wed, 2 Nov 2011 17:58:40 +0100
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
hi Phil,

pointer from luabind::object:

Base* ptr = luabind::object_cast<Base*>(myobject);

as for the method call: do you derive from a C++ class in Lua and do you want to call a method from the C++ interface, or do you want to call a method that has been added in Lua, but wasn't part of the original interface?
In any case, you can resort to a Lua style construction which should always work.

luabind::object method = globals(L)["MyClass"]["methodName"];
int result = luabind::call_function<int>(method, instance, additionalParams)
which would be equivalent to Lua:
result = instance:methodName(additionalParams)
or alternatively
result = MyClass.methodName(instance, additionalParams)

hth,
Tony

On 02.11.2011, at 17:37, Phil Cooper-King wrote:

> Hey Guys,
> 
> I'm finding it quite easy to go from C++ to Lua in terms exposing
> functionality, but the other way around I'm not really understanding
> how to do it.
> 
> I have C++ function
> void addObject(luabind::object)
> {
>     // Get Base ptr
>     // Call lua objects method.
> }
> 
> How do I get the base pointer of this object (amusing its both wrapped
> and inherited), and also how do I call its lua methods.
> 
> I thought  the classes would be just tables, but they dont seem to
> return LUA_TTABLE.
> 
> Thanks
> Phil.
> 
> ------------------------------------------------------------------------------
> RSA&#174; Conference 2012
> Save $700 by Nov 18
> Register now&#33;
> http://p.sf.net/sfu/rsa-sfdev2dev1
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
RSA&#174; Conference 2012
Save $700 by Nov 18
Register now&#33;
http://p.sf.net/sfu/rsa-sfdev2dev1