Page 1 of 4

table.pack and LOVE

Posted: Sat Oct 05, 2013 1:37 pm
by ArchAngel075
Greetings!

Im currently working on a minigame and i require to send objects (love.physics or just tables) between clients and servers.
BUT my LOVE2D does not seem to have the table.pack function so i assume LOVE2D is using 5.1 or not 5.2.

Is there a way to have it use a specific LUA version so that i can have access to the table.pack?

-end-

-EDIT-
I may be wrong.. Its not table.pack that i need, but rather i think serialization. BUT rather ill describe :
Convert a table into a complete string that can be reconverted back into a table. The string needs to be able to be sent over a network..
Simply put i need to send tables across networks...

Re: table.pack and LOVE

Posted: Sat Oct 05, 2013 2:04 pm
by mickeyjm
what I have done in the past is this:

Code: Select all

function pack(...)
    return {...}
end
Which should do the job without needing a custom version of LOVE/Lua

Re: table.pack and LOVE

Posted: Sat Oct 05, 2013 2:56 pm
by ArchAngel075
Sadly it doesnt seem to do the trick, it returns a table, which cant be concat with a string unless using a tostrinng() function.
BUT then on the other side, i recieve a string version of the table, like --> table : 0x5902GH, i tried using unpack() on the string sent accross, but again it will error because it needs a table and not a string.

I m looking at using luajit but im unsure if its possible.

Is there anyway i can send the table over networks using a string
ie
server side : string = pack(table) ; server:send(string) end
client side : function onReceive(msg); message = unpack(msg) end

Re: table.pack and LOVE

Posted: Sat Oct 05, 2013 5:32 pm
by T-Bone
Depending on what you have in your tables, it can be very easy to create pack and unpack functions yourself. Tricky parts include dealing with circular references, metatbles and functions in general...

Check out https://love2d.org/wiki/Jupiter and https://love2d.org/wiki/Serial and https://love2d.org/wiki/Tserial

Re: table.pack and LOVE

Posted: Sun Oct 06, 2013 4:15 am
by Lafolie
If your serialisation is targeted for network transmission you're going to need a way to delimit table entries. It is preferable to use as few dimensions as possible (1) for the data structure to be serialised. As T-Bone mentioned, anything that can't be easily coerced into a string is basically impossible to express (unless you use Java, well I'm being cruel here, but it's a function call nontheless).

Re: table.pack and LOVE

Posted: Sun Oct 06, 2013 9:12 pm
by bartbes
For future reference, lua 5.2's table.pack is basically equivalent to:
function pack(...)
return {n = select('#', ...), ...}
end
And is therefore not related to serialization in any way. (It is, indeed, meant as the complement to unpack, or table.unpack in 5.2.)

Re: table.pack and LOVE

Posted: Mon Oct 07, 2013 1:25 pm
by ArchAngel075
Well i am using the Tserial library/snippet as it is doing the trick perfectly. I can send a table easily over a network and then simply unpack it the other side, and if the table is too complex (metatables etc) then i just include extra information with my sent string converted table so that it understands how to deal with it.

Anyhow thanks all for the tips and input >>

-end-

Re: table.pack and LOVE

Posted: Mon Oct 07, 2013 5:25 pm
by Lafolie
You should not have to send information pertaining to how data should be used over the network. It's fine to send some meta such as "this is a bullet object" etc, but the method of internally structuring and implementing the data should already be known by both the client and server. You generally want to send as little information as possible, and sending things like functions poses a security risk.

When you send data over the network you ideally would send only attribute values (XYs, health etc), not the structures behind them.

Re: table.pack and LOVE

Posted: Mon Oct 07, 2013 11:36 pm
by ArchAngel075
Thats simply what im doing, i have each client pack together info the server needs, then the server uses the collected info to do any changes (say a player moved 4 up, the server processes this request while considering other clients etc) and then a broadcast of results is sent out. This way clients are synched with the exact same data and the only lag occurs when a clients ping isn't received and the servers broadcast isnt received.

I generally use a function MSG that checks all messages received (both server and client have it) and a second argument "check" which is a string. it simply says "if this message starts with "&WHATEVER&" then do this. This way i can pass information easily by simply appending the specific string "&XYZ&" to it.

Also i dont send functions, but rather just necessary information. Also i can reduce the ping times later. I perhaps will write a collective ping function that collects all messages that would normally go out, and then send them all at once within the "tick" to reduce the number of messages going out.
I am pretty new to the idea of networking in games and so i try to avoid causing unnecessary messages to be sent out for trivial things.

Re: table.pack and LOVE

Posted: Tue Oct 08, 2013 7:00 am
by Lafolie
Sounds like you're doing this sensibly.
ArchAngel075 wrote: if the table is too complex (metatables etc) then i just include extra information with my sent string converted table so that it understands how to deal with it
This is why I mentioned not sending anything other than 'raw values'.

Good luck with your project, hope to see it in P&D soon.