I’m new to Lua and I’d love some advice. I have a server on Go, and Defold communicates with it through websockets using britzl’s library. Serialization is easy in Go, but I’m having troubles on the Defold side of it.
Right now, let’s say I need to deserialize an int32 in Defold. This is what I do:
function ReadIntFromStream(message)
local result = ""
for i = 1, 4 do
result = result .. message:byte(i)
end
return tonumber(result)
end
After that, I cut off first 4 bytes from the “message”, before passing it along to other methods.
message = string.sub(message, 5)
All of this looks hacky to me. Is this the correct approach at all?
If I need to deserialize structs, do I have to manually do it for each element of the struct? Perhaps writing a C++ extension would be the better approach, especially for structs, since this is where I can also declare them? (at least from what I understood from reading about C++ extensions)