我需要使用 C++ 中的套接字将 lua_state 发送到服务器。我如何序列化 lua_State 以便它可以通过网络发送?
最佳答案
根据您的需要,您有多种选择。您可以尝试使用 Pluto 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.
您也可以尝试 lper ,它使用 Linux Persistent Memory .
请注意,您将在发送自定义 C 函数和用户数据时遇到问题...
如果你真的不需要发送整个lua_State
(你为什么需要那个?),你可以看看TableSerialization Lua-users Wiki 上的页面。也许您可以通过发送包含您需要的整个“状态”的序列化(可能很大)Lua 表来解决您的问题。
关于c++ - 序列化 lua_State 以通过网络发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9216012/