lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On May 11, 2012 3:54 AM, "Thijs Schreijer" <thijs@thijsschreijer.nl> wrote:
>
> A lot has been written on callbacks, but couldn’t find an answer to this one in the archives;
>
>  
>
> Does it make a difference on what (valid) lua_State object I execute a callback? Does it change anything for the callback function being executed? Or is there no difference, whatever lua_State is being used (as long as it is valid)?
>
>  
>
> Any pointers are appreciated.
When working on coroutines and callbacks in the past, I found it best to store the calling Lua state before entering whatever outside loop was about to occur.

Example pseudo:
Register callback function x
...
Sometime later, perhaps in a different coroutine
  Function run loop:
    Store L in location all C side callbacks can see
    Call C function that may call C callbacks
    on complete, set L to an invalid value since no callbacks should call on return
    (if not the case... multithreaded environment... then the strategy may need to change)