Hi all,
I've just come across SLikeNet (used RakNet previously) and was wondering if anyone has tried to expose SLikeNet functions in Lua?
Thanks in advance
Shando
PS: From what I've seen so far, SLikeNet is looking like a good replacement for RakNet
SLikeNet and Lua
Re: SLikeNet and Lua
Unfortunately that's not on our priority list atm. A start might be to investigate using SWIG to generate Lua wrappers. Since SWIG is used to create C# wrappers already, that might be the easiest start.
An alternative approach could be to use LuaJIT and FFI. That should allow a straight forward integration of SLikeNet in Lua.
If you happen to invest some work on that side yourself and want it being integrated in SLikeNet directly, don't hesitate to speak up. For now, I put the request/suggestion on our issue tracker at least (internal case number: SLNET-235).
An alternative approach could be to use LuaJIT and FFI. That should allow a straight forward integration of SLikeNet in Lua.
If you happen to invest some work on that side yourself and want it being integrated in SLikeNet directly, don't hesitate to speak up. For now, I put the request/suggestion on our issue tracker at least (internal case number: SLNET-235).
Re: SLikeNet and Lua
Thanks for the reply.
I've looked into SWIG, but it seems to generate way too much overhead and isn't human readable
In the past I managed to get this working fine:
https://github.com/pabloko/Lua-JIT-RakNet
Which is fairly simple, though I will have to code most new functions by hand, but I suppose that's what the samples are for
Does anyone happen to have a list of functions that would be the minimum set required to get as much functionality (incuding plugins) as possible, without getting into too much detail?
Thanks in advance
Shando
I've looked into SWIG, but it seems to generate way too much overhead and isn't human readable
In the past I managed to get this working fine:
https://github.com/pabloko/Lua-JIT-RakNet
Which is fairly simple, though I will have to code most new functions by hand, but I suppose that's what the samples are for
Does anyone happen to have a list of functions that would be the minimum set required to get as much functionality (incuding plugins) as possible, without getting into too much detail?
Thanks in advance
Shando
Re: SLikeNet and Lua
OK, so I invested some time in SWIG
I have (hopefully) managed to get over 1,500 available, of which I have successfully tested almost 50 in my ‘TestMain.lua’ code.
NOTE: Testing was carried out on Windows 10 using Visual Studio 2017 Community, Lua 5.2 & SWIG 3.0.12.
With the testing I tried to use as many regularly used functions as possible, including creating, writing & reading Bitstreams and running both a Server and a Client.
In the Function Listing by Class section in the 'SLNet_Lua_Funcs.docx' file, C++ functions are in black and the corresponding Lua function is in blue:
NOTE: One thing to be careful of is that for any ‘static’ function (and ENUMs) in C++, Lua uses the ‘.’ notation rather than the ‘:’ notation used above:
Getting to this point was not an easy task as there are quite a few issues with the SWIG process:
In the ‘SLNet_Lua.zip’ file are all the relevant files that I used for testing:
Shando
The .zip file is too large to add here, so this is a link to it on Mega:
https://mega.nz/#!35JwDCID!P7ZRRIRPttLk ... az8VTiC7_g
I have (hopefully) managed to get over 1,500 available, of which I have successfully tested almost 50 in my ‘TestMain.lua’ code.
NOTE: Testing was carried out on Windows 10 using Visual Studio 2017 Community, Lua 5.2 & SWIG 3.0.12.
With the testing I tried to use as many regularly used functions as possible, including creating, writing & reading Bitstreams and running both a Server and a Client.
In the Function Listing by Class section in the 'SLNet_Lua_Funcs.docx' file, C++ functions are in black and the corresponding Lua function is in blue:
- bool = SLNet::AddressOrGUID::__eq ( SLNet::AddressOrGUID * ) = C++ Version
- OUT = AddressOrGUID:_eq ( IN ) = Lua Version
Code: Select all
aog1 = SLNet:AddressOrGUID ( inPacket1 )
aog2 = SLNet:AddressOrGUID ( inPacket2 )
bResult = aog1:_eq ( aog2 )
Code: Select all
testServer = SLNet.RakPeer.GetInstance ( )
*** ‘.’ notation ***
testServer:Startup ( 1, SLNet.SocketDescriptor ( 60001, "127.0.0.1" ), 1 )
*** ‘:’ AND ‘.’ notation ***
testServer:SetMaximumIncomingConnections ( 1 )
*** ‘:’ notation ***
enumVal = SLNet.ID_USER_PACKET_ENUM
*** ‘.’ notation ***
- The generated TYPES TABLE sometimes has 2 entries for the same type. Basically SWIG creates a ‘SWIGTYPE_p_’ and a ‘SWIGTYPE_p_SLNet__’, which leads to some functions not recognising the correct type and requiring manual fixes.
- Marking parameters as ‘OUTPUT’ or ‘INOUT’ only works for “normal” datatypes (bool, int etc.).
- SWIG doesn't work with Structs embedded in Classes. In fact, they are simply ignored.
- SWIG seems to duplicate any ENUMs embedded in Classes. One is created in the Class in 'static swig_lua_const_info swig_CLASSNAME_Sf_SwigStatic_constants[]' and the other in the Module in 'static swig_lua_const_info swig_SwigModule_constants[]'. NOTE: The version in ‘SwigModule’ has 'CLASSNAME_' added as a prefix to the ENUM.
In the ‘SLNet_Lua.zip’ file are all the relevant files that I used for testing:
- ‘Source’ folder – contains the required Lua ‘.h’ files
- ‘SWIG I Files’ folder – contains the ‘i’ files required by SWIG to generate the wrapper code. The main ones to generate the basic wrapper are ‘SLNet.i’ and ‘SWIG_Templates.i’.
- ‘inspect.lua’ – an excellent piece of Lua code that allows you to pretty-print the contents of a Lua table (including ‘_G’).
- ‘lua52.dll’ & ‘lua52.lib’ – the main Lua files for dynamic/static linking.
- ‘SLNet_exe.cpp’ – the main code to run the demo/SWIG – NOTE: any Lua file can be passed to this, via the command line, but the code at lines 31 & 32 will need uncommenting / commenting.
- ‘SLNet_Funcs_Lua.docx’ – the documentation.
- ‘SLNet_wrapper.cxx’ – the SWIG-generated wrapper file.
- ‘SLNet_wrapper_plus_extensions.cxx’ – a SWIG-generated wrapper file that includes the RakVoice, Lobby2, PostgreSQL & MySQL extensions. NOTE: This wrapper has NOT been tested at all as it needs quite a few external programs to function, such as speex and PostgreSQL.
- ‘stdafx.cpp’ & ‘stdafx.h’ – a couple of files required to get the tests working in Visual Studio 2017.
- ‘SWIG_Funcs_new.xlsx’ – an Excel spreadsheet that I used to create the Function listing.
- ‘TestMain.lua’ – the Lua file containing my test code.
Shando
The .zip file is too large to add here, so this is a link to it on Mega:
https://mega.nz/#!35JwDCID!P7ZRRIRPttLk ... az8VTiC7_g
Re: SLikeNet and Lua
Great work Shando.
If you like I can put the file onto our server so you can use it as a download mirror.
Would it be fine with you, if we base a later integrated Lua support on your code?
For the time being, I'd add a note in the readme file in the next version to point to your Lua interface package, if you are fine with that (pointing out it's a 3rd-party contribution).
If you like I can put the file onto our server so you can use it as a download mirror.
Would it be fine with you, if we base a later integrated Lua support on your code?
For the time being, I'd add a note in the readme file in the next version to point to your Lua interface package, if you are fine with that (pointing out it's a 3rd-party contribution).
Re: SLikeNet and Lua
Hey buddy,
No worries. Feel free to use them any way you want.
The only proviso I have is that it clearly states that they have not been fully tested and there is no warranty, though I will try to help any way I can.
Regards
Shando
PS: apologies for not responding sooner
No worries. Feel free to use them any way you want.
The only proviso I have is that it clearly states that they have not been fully tested and there is no warranty, though I will try to help any way I can.
Regards
Shando
PS: apologies for not responding sooner
Who is online
Users browsing this forum: No registered users and 1 guest