table.pack and LOVE

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

table.pack and LOVE

Post 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...
Last edited by ArchAngel075 on Sat Oct 05, 2013 3:06 pm, edited 1 time in total.
User avatar
mickeyjm
Party member
Posts: 237
Joined: Thu Dec 29, 2011 11:41 am

Re: table.pack and LOVE

Post 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
Your screen is very zoomed in...
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: table.pack and LOVE

Post 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
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: table.pack and LOVE

Post 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
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: table.pack and LOVE

Post 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).
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: table.pack and LOVE

Post 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.)
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: table.pack and LOVE

Post 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-
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: table.pack and LOVE

Post 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.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: table.pack and LOVE

Post 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.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: table.pack and LOVE

Post 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.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests