Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serialize lua_State to sent over network

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?

like image 714
Saulo Cabral Avatar asked Feb 22 '23 13:02

Saulo Cabral


1 Answers

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.

like image 110
Michal Kottman Avatar answered Feb 27 '23 04:02

Michal Kottman