Page 1 of 1

Multiplayer using RakNet/Löve with Lua C API

Posted: Sat Dec 25, 2010 3:51 pm
by olle
Hello, everybody!

I'm quite new to Löve. I'm using it right know for prototyping our game project (info here: https://sites.google.com/site/anakhagame/).

I will use Raknet to program the network stuff, thus I need to export functions to Lua, I think. How do I use the Lua C API with Löve? I think that will be necessary, or is there any other way to program network with Löve?

Regards
Olle

Re: Multiplayer using RakNet/Löve with Lua C API

Posted: Sat Dec 25, 2010 4:25 pm
by vrld
Welcome to the world of LÖVE, you will not regret entering it! :awesome:
olle wrote:I will use Raknet to program the network stuff, thus I need to export functions to Lua, I think. How do I use the Lua C API with Löve?
Well, normally you don't. But you can build modules using the C api and require them in your game. But this will likely break portability - you have to provide the compiled module for every platform you wish to support.
olle wrote:I think that will be necessary, or is there any other way to program network with Löve?
LuaSocket is bundled with LÖVE, and it is awesome. Apart from rather low level socket programming it offers a nice high level concept called LTN12.
There is also LUBE which was developed by bartbes specifically for the use with LÖVE.

Re: Multiplayer using RakNet/Löve with Lua C API

Posted: Sat Dec 25, 2010 10:05 pm
by olle
Well, normally you don't. But you can build modules using the C api and require them in your game.
Wouldn't that require that I start a separate Lua state from C? I can't use C functions in Lua without having a C executable running, right? Is it possible to start Löve from C?
But this will likely break portability - you have to provide the compiled module for every platform you wish to support.
Breaking portability is no biggy in this state.

EDIT: Ok, found link http://lua-users.org/wiki/BuildingModules, I think that's what I need. Thanks!!

EDIT2: I'd still like to know if it's possible to start Löve from C, though...

Re: Multiplayer using RakNet/Löve with Lua C API

Posted: Sun Dec 26, 2010 1:59 am
by Robin
Welcome!
olle wrote:EDIT2: I'd still like to know if it's possible to start Löve from C, though...
LÖVE is written as an application, and although there has been some action to make it usable as a library, but AFAIK only from the Lua side.

Is there a special reason to use RakNet instead of LuaSocket, though?

Re: Multiplayer using RakNet/Löve with Lua C API

Posted: Sun Dec 26, 2010 2:51 pm
by olle
Robin wrote:Welcome!
Thank you! :)
LÖVE is written as an application, and although there has been some action to make it usable as a library, but AFAIK only from the Lua side.
Using Löve as a library could work too. In that case I could use the regular C API and start up LÖVE from my own Lua state. Is there information available on this?
Is there a special reason to use RakNet instead of LuaSocket, though?
Performance, I suppose. Also, the chief of the project don't know about LuaSocket (well, not yet, anyway). LÖVE will not be used in the final produc.

If any one is interested, this is the network algorithm we will try to implement: http://www.gamasutra.com/view/feature/3 ... twork_.php

Our ambition is to make it peer-to-peer, though. Eventually.

Re: Multiplayer using RakNet/Löve with Lua C API

Posted: Sun Dec 26, 2010 4:28 pm
by Robin
olle wrote:Using Löve as a library could work too. In that case I could use the regular C API and start up LÖVE from my own Lua state. Is there information available on this?
Not that I know of.
olle wrote:
Is there a special reason to use RakNet instead of LuaSocket, though?
Performance, I suppose.
I doubt performance will be affected by this. The core part of LuaSocket is implemented in C. And even if it were implemented completely in Lua, network lag poses a much larger performance issue. If you won't use LÖVE in the final product, why use RakNet in the prototype?

Re: Multiplayer using RakNet/Löve with Lua C API

Posted: Sun Dec 26, 2010 5:41 pm
by vrld
RakNet is rather high level. Implementing the network functionality with luasocket in the prototype would mean to reinvent the whole thing later. Plus you'd have to learn luasocket in addition to RakNet.
That said, it is possibly easier to make a lua module out of RakNet than to make a module out of LÖVE...

Re: Multiplayer using RakNet/Löve with Lua C API

Posted: Thu Dec 30, 2010 4:27 pm
by olle
If you won't use LÖVE in the final product, why use RakNet in the prototype?
Because I can. ;) It will save time, too, of course.

A good question is which functions in the network routine should be exported to Lua.

I think I will do like this:
1. Make a module that works on Ubuntu, with RakNet etc and LÖVE.
2. When LÖVE no longer is needed, start my own Lua state and export the functions in the former module.

Thank you for your time!