[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Safe way to push strings to a yielded thread
- From: Kevin Martin <kev82@...>
- Date: Tue, 18 Dec 2018 13:49:02 +0000
Hi,
I think, from the 5.3 documentation, that lua_pushstring may run a garbage collection (this is how I understand the 'm' in '[-0, +1, m]'). Hence it is possible for this function to error, e.g. in a __gc metamethod.
It's not possible for me to be in a protected environment, so in order to safely push a string, I guess I need to wrap lua_pushstring in a pcall. This is fine normally, but then I am unsure what to do when I am trying to push a string onto a suspended thread, as the manual says that you can only call functions on a state when lua_status(state) == LUA_OK, which is not true for a suspended thread.
Do I need to create an extra thread initially, just for the purpose of safely pushing strings, and then lua_xmove-ing them to the thread where I want them? Is there a better solution, or have I misunderstood the manual.
Thanks,
Kev