Lua sessions with dedicated "consoles" in a multi-threaded environment

There are many Lua sessions (each represented by its own lua_State) in an embedded multithreaded C ++ program. Each Lua session has a dedicated "console" represented by a C ++ object. This "console" is designed to provide session-specific stdin / stdout / stderr streams.

What's the correct way to deliver such a "console" to a Lua session?
What's the correct way to implement redirecting standard streams to / from such a console?

+3


source to share


1 answer


You can insert userdata

into io.stdin

/ stdout

/ stderr

with



lua_getglobal(L, "io");
lua_pushlightuserdata(L, …); // or whatever value you want here
lua_setfield(L, 0, "stdin");
// rinse, repeat for stdout and stderr

      

+1


source







All Articles