Re: To And From C++

Phil Cooper-King <[email protected]> Wed, 2 Nov 2011 19:31:55 +0000
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <CAPrH6UPr0Ob=WG--nEeWPoh2YUAMHhA24CFF81PbEmbNdSeb3g@mail.gmail.com>
Thanks Tony,

there must be something else going on.

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

causes a crash,
and also

luabind::object method = globals(L)["MyClass"]["methodName"];
int result = luabind::call_function<int>(method, instance, additionalParams)

causes a crash.

this is the full source
cpp http://pastie.org/2800173
lua http://pastie.org/2800570

On 2 November 2011 16:58, Tony Kostanjsek <[email protected]> wrote:
> 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
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1