LuaJIT = Awesome! luaJIT-Enet Loaded!
Tonight I did some more modeling and discovered that sandbags and sandbag walls and bunkers are hella hard! Sandbags will either have to wait for a version 2.0 release of the pack or be on hold indefinitely .
I also did some learning for the sake of learning. The topic: Lua JIT. There was a lua jit in Leadwerks 3.0 but I never braved it. In Leadwerks 3.1 it has been advertised that it has a jit compiler. So being the curious person that I am I decided to read up on it. Upon further research I discovered the LuaJIT FFI Extension (http://luajit.org/ext_ffi.html). This allows you to directly call C functions and data structures from lua. This is very useful to me because I'm not as familiar with C/C++ than I would like to be, but would allow me to still use some C functions from relative safety.
Through a bunch of trial and error I was able to successfully load the Enet library into the my game using the luajit commands. I need to do more experimenting to make the loading of the library simpler and make a simple way to sync the entitys in the game.
To the curious more reading: (i'm going to bed soon so i cant go into much detail )
http://luajit.org/extensions.html Learn about the luajit and how to use C commands.
http://wiki.luajit.org/FFI-Bindings List of luajit-bindings HEAD THE NOTE AT THE TOP!
https://github.com/ColonelThirtyTwo/luajit-ffi-enet The luajit Enit Binding
https://github.com/lsalzman/enet The enet repo, if you want to go the easy way, install codeblocks and open the .cbp with it and compile
after you make the dll
look through this repo for examples https://github.com/arch-jslin/mysandbox/tree/master/lua
follow this example specificaly https://github.com/arch-jslin/mysandbox/blob/master/lua/enet1.lua
Almost most there!
Now i was not able to run that last example as is, i had to do some shortcuts:
I put this all in function App:Start()
local ffi = require 'ffi' local enet = ffi.load[[enet\libenet]]
!!!HERE IS WHERE I HAD PROBLEMS!!!
i was not able to get this line:
ffi.cdef( io.open([[enet\ffi_enet.h]]):read('*a')
to work. so what i did was opened the file, copied everything from ffi_enet.h except for the first return and pasted it between these blocks of code.
it should look like:
ffi.cdef[[ static const int ENET_VERSION_MAJOR = 1; static const int ENET_VERSION_MINOR = 3; static const int ENET_VERSION_PATCH = 4; : :the rest of the code : extern size_t enet_range_coder_decompress (void *, const enet_uint8 *, size_t, enet_uint8 *, size_t); extern size_t enet_protocol_command_size (enet_uint8); ]]
if enet.enet_initialize() ~= 0 then Debug:Error("An error occurred while initializing ENet.") end local addr = ffi.new("ENetAddress[1]") addr[0].host = enet.ENET_HOST_ANY addr[0].port = 12345 local serv = enet.enet_host_create(addr, 32, 2, 0, 0) if tonumber(ffi.cast("int", serv)) == 0 then Debug:Error("An error occurred while trying to create the host.\n") end
*io.stderr turns to Debug:Error, and we remove os.exit(1) entierly (if there is an error, check your debug console!)
This will create a host server and the windows firewall thing will popup asking for permission
enet.enet_deinitialize()
This is how you close enet when your game ends. Is there an app:end() that we can use? it would be nice to use for cleanup.
- 3
3 Comments
Recommended Comments