1

Is there a way to know which thread (coroutine) executing a Lua script is at the origin of a lua_pushcclosure call?

In order to manage some stuff relative to lua threads (delayed pause/resume, or private thread variables) I need to identify the thread involved in the callback. I know I can get the thread index when creating it by using lua_gettop, but I can't find a way to use it so it helps identifying the thread when a lua_pushcclosure call is issued from a Lua script.

My current system permits nested script calls, so a script can execute other scripts (each nested script call create a new thread with the same lua_state. Thus the lua_state used to get multiple thread entries in the stack.)

I'm using Lua 5.2

Valkea
  • 1,216
  • 1
  • 12
  • 26
  • "lua_pushcclosure callback" `lua_pushcclosure` is not a callback. Are you talking about when you *call* that function? – Nicol Bolas Sep 08 '12 at 05:33
  • Yes I am talking about when the function is called from within the lua script. The function exposed through `lua_pushcclosure` can be called from different threads and I need to identify which one. – Valkea Sep 08 '12 at 12:53

1 Answers1

3

If you're in a C function that has been called from Lua, and you want to know what thread you're in... just call lua_pushthread(L).

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982