I need to send a lua_state to a server using Sockets in C ++. How I can serialize a lua_State so that it can be sent over the network?
Depending on your needs, you have several choices. You can try to use the Pluto Library. It is a "heavy-weight" serialization library:
Pluto is a library which allows users to write arbitrarily large portions of the "Lua universe" into a flat file, and later read them back into the same or a different Lua universe. Object references are appropriately handled, such that the file contains everything needed to recreate the objects in question.
You may also try lper, which uses Linux Persistent Memory.
Note that you will have problems with sending custom C functions and userdata...
If you actually do not need to send entire lua_State
(why would you need that?), you can take a look at the TableSerialization page at the Lua-users Wiki. Maybe you can solve your problem by sending serialized (possibly large) Lua tables containing the entire "state" you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With