I’m new to Defold and to Lua. I’m coming from 4 years of programming in UE4 (and some Unity). I’m not an expert programmer, but I’ve studied as one, I love doing it and that’s all I’ve been doing for the last 4 years. I’m supposed to be able to handle Defold.
Saying that I’m having difficulties with Defold is saying nothing…
My idea is to write a 2D MMORPG on mobile. The server would be written in Go, the client on Defold. I need the server to be efficient, so I need to have as little overhead as possible from client-server communication. After researching a little, it looks like Json, Msgpack and the likes are too slow. Thankfully, there’s Protobufs and Flatbuffers that could do the job. Protobufs are less efficient, but easier to use, and Flatbuffers are more efficient, but require a lot of ugly code. Frankly, at this point, I could settle for either of those two, but I can’t make any of them work in Defold.
Let’s start with Flatbuffers. There’s an official Lua implementation, so no problem there. But it depends on string.pack and string.unpack from Lua 5.3. No biggie, looks like there’s compat53 (a library for lua 5.1 that backports string.pack and unpack), and if that fails, there’s roberto’s struct.pack/unpack library that offers similar functionnality (but not the same?)
- I couldn’t turn compat53’s string library into a native extension. It crashes on startup with an error that tells me nothing (seen below). What is this script.cpp? I don’t have it in my project. Is it some other native extension that crashes, and if so - why? Is there a crash log? In case anyone wants to have a look at the code itself, here’s my NE.
Assertion failed: top == lua_gettop(L), file …\src\script.cpp, line 214
- I managed to turn roberto’s library into a native extension. With it, flatbuffers’ serialization doesn’t work. The library probably doesn’t do exactly what’s needed. I’ll come back to it later.
Now trying Protobufs. There are two Lua implementations (one complicated and one simple), both supposed to work with Lua 5.1.
- I couldn’t install the simple one as a NE: Assertion failed: top == lua_gettop(L), file …\src\script.cpp, line 214 again. NE.
- Couldn’t install the complicated one either, same error. NE.
Five days of working on this problem and I got exactly nowhere. Any advice would be truly appreciated.
P.S. I’m using these extensions:
- https://github.com/britzl/defold-websocket/archive/master.zip
- https://github.com/britzl/defold-luasocket/archive/master.zip
- https://github.com/britzl/defold-luasec/archive/master.zip
compat53: GitHub - lunarmodules/lua-compat-5.3: Compatibility module providing Lua-5.3-style APIs for Lua 5.2 and 5.1
roberto’s library: http://www.inf.puc-rio.br/~roberto/struct/
protobufs complicated library: GitHub - starwing/lua-protobuf: A Lua module to work with Google protobuf
protobufs simple library: GitHub - urbanairship/protobuf-lua: Lua library for Google's Protocol Buffers
Some questions:
-
How to turn compat53 into a NE? It has multiple .c files, so is each .c file supposed to be a separate NE, or is it possible to combine them somehow into one NE? What am I doing wrong?
-
When you have something like #include <lua.h> in a native extension, are you supposed to comment out these includes? Or are you supposed to dump these headers into the /include folder every time a NE needs it?