I have a C++ function, called lua_tcall, which extends the abilities of lua_pcall. When lua_tcall is called, it expects that the top value of the stack is a Lua function, much like lua_pcall does. I would like lua_tcall to be able to create a thread, and use the function on the top of the global stack as the thread's function. How do I push the function from the global state into the lua_State* that I get back from lua_newthread?
lua_pcalldoes not expect the top item on the stack to be a function (unless you're calling it with zero arguments). The location of the function on the stack is-(1 + nargs). So what exactly is it that you expect to be on the stack with yourlua_tcall? - Nicol Bolas