Sean Edwards
Sean Edwards

Reputation: 2093

Pushing a function from the global state into a Lua thread

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?

Upvotes: 1

Views: 989

Answers (2)

corsix
corsix

Reputation: 36

To transfer values between states, lua_xmove is better than using a shared intermediary.

Upvotes: 2

Nicol Bolas
Nicol Bolas

Reputation: 473312

To transfer a function from one lua_State to another, you must use something global to both states to store the object as an intermediary. You could use a global variable or a registry entry.

Upvotes: 2

Related Questions