Jump to content

Does Rakknet work with lua?


wburton72
 Share

Recommended Posts

You have to make the bindings. This basically means exposing the C++ RakNet to Lua. I've done this before but have since lost the code as back before it was free the creator said I couldn't distribute the DLL but had to give the source instead. It's very doable and not all that hard. I've been meaning to do it again but just haven't found the time.

 

You don't have to expose all of RakNet, just create some high level functions that give you the functionality of sending/receiving data. I think I exposed like maybe 5 functions to Lua or something like that.

  • Upvote 1
Link to comment
Share on other sites

When I did it some time ago I actually didn't use ToLua but just the old fashion way. I flattened the RakNet classes and made it more procedural. Had functions like: Connect(), Host(), CreateBitStream(), WriteBitStream(), ReadBitStream(), Send(), NetworkLoop(), BindEvent().

 

More like the top part of this: http://lua-users.org/wiki/BindingCodeToLua

 

So I had global RakNet variables in my DLL for the peer interface and such.

Link to comment
Share on other sites

When I did it some time ago I actually didn't use ToLua but just the old fashion way. I flattened the RakNet classes and made it more procedural. Had functions like: Connect(), Host(), CreateBitStream(), WriteBitStream(), ReadBitStream(), Send(), NetworkLoop(), BindEvent().

 

More like the top part of this: http://lua-users.org/wiki/BindingCodeToLua

 

So I had global RakNet variables in my DLL for the peer interface and such.

 

Oh, well that'd work just fine but since LE3 uses LuaJit I'd strongly recommend using toLua. toLua is much faster and weighs in at like 1/10th the overhead.

Link to comment
Share on other sites

I don't believe LuaJit and toLua are in any way related are they? I personally don't like messing around with the whole idea of "cleaned header files". I'm sure RakNet doesn't adhere to those rules and setting that up manually for all of RakNet would be a pain in the arse. I could do it for my own exposure but then again the need to mess around with that I don't feel is required when simple static C++ methods gets the job done. When I looked at that it seemed more trouble than it was worth, but that's just my take on it.

 

If someone had the time to expose all of RakNet using something like toLua then that would be great, but it would also take a long time and be error prone most likely, but very welcomed I'm sure by many people.

Link to comment
Share on other sites

I don't believe LuaJit and toLua are in any way related are they? I personally don't like messing around with the whole idea of "cleaned header files". I'm sure RakNet doesn't adhere to those rules and setting that up manually for all of RakNet would be a pain in the arse. I could do it for my own exposure but then again the need to mess around with that I don't feel is required when simple static C++ methods gets the job done. When I looked at that it seemed more trouble than it was worth, but that's just my take on it.

 

If someone had the time to expose all of RakNet using something like toLua then that would be great, but it would also take a long time and be error prone most likely, but very welcomed I'm sure by many people.

 

Agreed but doing it through C++ would produce more overhead, however I do agree with you about toLua, I'm not a big fan of it, also I haven't used it much; I would much prefer the implementation of LuaJit's FFI api into Leadwerks, I think this is something that should be strongly considered in the future.

 

Edit: Nevermind, it looks like FFI is in Leadwerks. Perfect biggrin.png

I'd strongly recommend using FFI.

Link to comment
Share on other sites

I've exposed the ENET library to Lua in my project. I'm considering making it open-source once my project matures a bit more. :) Standard Leadwerks edition is required though, unless Josh would allow me to distribute the customized binaries.

Link to comment
Share on other sites

 

That's handy, but its unnecessarily large and complex.my version is purely Lua and a total of about 50 lines in the main lua file, aside from the header and the enums.

 

It also produces nicer functions instead of enet.enet_initialize it'd be proper, like: enet.initialize

 

I'll find it on my old external harddrive later and post some snippets.

Link to comment
Share on other sites

  • 2 weeks later...

That's handy, but its unnecessarily large and complex.my version is purely Lua and a total of about 50 lines in the main lua file, aside from the header and the enums.

 

It also produces nicer functions instead of enet.enet_initialize it'd be proper, like: enet.initialize

 

I'll find it on my old external harddrive later and post some snippets.

 

Still waiting to see this ...still waiting ..been 14 days now biggrin.png

Threadripper 2920X Gen2 CPU(AMD 12-core 24 thread) | 32Gigs DDR4 RAM | MSI Nvidia GeForce RTX 2070 Stock OCed | ASRock X399 Professional Gaming Motherboard | Triple M.2 500Gig SSD's in Raid0

Windows 10 Pro | Blender | Paint.NetWorld Machine | Shader Map 4 | Substance Designer | Substance Painter | Inkscape | Universal Sound FX | ProBuilder | 3D World Studio | Spacescape | OpenSky | CubeMapGen | Ecrett Music | Godot Engine | Krita | Kumoworks | GDScript | Lua | Python | C# | Leadworks Engine | Unity Engine

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...