LuaBridge icon indicating copy to clipboard operation
LuaBridge copied to clipboard

An Issue in coroutine mode with LuaRef

Open Leon-zsl opened this issue 5 years ago • 1 comments

I use LuaBridge in my project for quite a long time. It works quite well until recently I am trying to support multi-coroutine mode in lua end. As we know, different coroutine has different lua_State. When I'm going to push a LuaRef into the stack of the current coroutine (L), LuaRef choose to push itself into the stack of the coroutine it cached (m_L) when it is created, instead of the current coroutine (L). As a consequence, the current coroutine can not get the value it wants, so unpredictable things will happen... My question is: is it possible to remove the cached m_L from LuaRef? or do you have any more elegant solutions to resolve or just bypass this issue? For example: when a lua coroutine want to get a property, which by coincidence is a LuaRef, like function getProperty in CFunctions.h, T is a LuaRef. LuaRef will just discard the input L and use the cached m_L instead, like function push in LuaRef.h, L is discarded After the push function returned, the LuaRef still does not exist in the current L, so the caller in Lua can not get the property it wants.

Leon-zsl avatar Jul 22 '20 03:07 Leon-zsl

How do you actually use coroutines? Could you please post some code examples?

dmitry-t avatar Aug 10 '20 17:08 dmitry-t