Re: To And From C++
Nigel Atkinson <[email protected]> Thu, 3 Nov 2011 09:13:21 +1100
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Phil,
I got your example to work (at lest with GCC on Linux) by changing:
struct SomeBase {
virtual void tickle() = 0 {}
};
to
struct SomeBase {
virtual void tickle() { std::cout << "SomeBase::tickle()" <<
std::endl; }
};
That is, I got rid of the " = 0 " bit on the method. And it seemed to
work, also with the bit you commented out back in. GCC alerted me to
the pure but not function when I tried compiling.
Also remember you could do:
void addLuaObj( SomeBase* obj)
{
obj->ticklel();
}
as well.
Nigel
On 03/11/2011, at 6:31 AM, Phil Cooper-King wrote:
> 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® Conference 2012
>>> Save $700 by Nov 18
>>> Register now!
>>> http://p.sf.net/sfu/rsa-sfdev2dev1
>>> _______________________________________________
>>> luabind-user mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>>
>>
>> ------------------------------------------------------------------------------
>> RSA® Conference 2012
>> Save $700 by Nov 18
>> Register now!
>> 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
> _______________________________________________
> 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
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user