Derived member functions as coroutines

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Derived member functions as coroutines

Matt Spong
I have an abstract base class which I am deriving from in Lua and
overriding virtual functions, using wrap_base as described in the
documentation.

Where I run into problems is calling the derived members as coroutines:

luabind::object self; // this gets passed to wrapper's constructor by
derived class's __init

luabind::object func = self["foo"];
luabind::resume_function<void>(func, self);

This all appears to work properly until the coroutine calls yield().
When this happens, lua_status() returns 0 rather than LUA_YIELD, so my
scheduler decides the coroutine has exited and drops it.

Is this a bug in luabind or am I doing something incorrectly?

Matt

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Derived member functions as coroutines

Nigel Atkinson-2
On Thu, 2011-06-23 at 12:39 -0400, Matt Spong wrote:

> I have an abstract base class which I am deriving from in Lua and
> overriding virtual functions, using wrap_base as described in the
> documentation.
>
> Where I run into problems is calling the derived members as coroutines:
>
> luabind::object self; // this gets passed to wrapper's constructor by
> derived class's __init
>
> luabind::object func = self["foo"];
> luabind::resume_function<void>(func, self);
>
> This all appears to work properly until the coroutine calls yield().
> When this happens, lua_status() returns 0 rather than LUA_YIELD, so my
> scheduler decides the coroutine has exited and drops it.
>
> Is this a bug in luabind or am I doing something incorrectly?
>
> Matt
I haven't used luabind::resume_function myself, however looking at the
docs, it looks like you have to assign your "func" luabind::object using
the thread you made with luaL_newthread.

Hope that helps.

Nigel


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense..
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Derived member functions as coroutines

Matt Spong
Yes, that turned out to be my problem. The right way to do get the
function object seems to be:

luabind::object func = luabind::globals(thread)[className]["foo"];

One thing I haven't figured out - how to determine className from C++?
Currently I'm passing it from Lua.

Matt

On Jun 24, 2011, at 5:53 AM, Nigel Atkinson <[hidden email]> wrote:

> On Thu, 2011-06-23 at 12:39 -0400, Matt Spong wrote:
>> I have an abstract base class which I am deriving from in Lua and
>> overriding virtual functions, using wrap_base as described in the
>> documentation.
>>
>> Where I run into problems is calling the derived members as coroutines:
>>
>> luabind::object self; // this gets passed to wrapper's constructor by
>> derived class's __init
>>
>> luabind::object func = self["foo"];
>> luabind::resume_function<void>(func, self);
>>
>> This all appears to work properly until the coroutine calls yield().
>> When this happens, lua_status() returns 0 rather than LUA_YIELD, so my
>> scheduler decides the coroutine has exited and drops it.
>>
>> Is this a bug in luabind or am I doing something incorrectly?
>>
>> Matt
> I haven't used luabind::resume_function myself, however looking at the
> docs, it looks like you have to assign your "func" luabind::object using
> the thread you made with luaL_newthread.
>
> Hope that helps.
>
> Nigel
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense..
> http://p.sf.net/sfu/splunk-d2d-c1
> _______________________________________________
> luabind-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense..
http://p.sf.net/sfu/splunk-d2d-c1
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user