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...
table.pack and LOVE
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- ArchAngel075
- Party member
- Posts: 319
- Joined: Mon Jun 24, 2013 5:16 am
table.pack and LOVE
Last edited by ArchAngel075 on Sat Oct 05, 2013 3:06 pm, edited 1 time in total.
Re: table.pack and LOVE
what I have done in the past is this:
Which should do the job without needing a custom version of LOVE/Lua
Code: Select all
function pack(...)
return {...}
end
Your screen is very zoomed in...
- ArchAngel075
- Party member
- Posts: 319
- Joined: Mon Jun 24, 2013 5:16 am
Re: table.pack and LOVE
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
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
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
Check out https://love2d.org/wiki/Jupiter and https://love2d.org/wiki/Serial and https://love2d.org/wiki/Tserial
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Re: table.pack and LOVE
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.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: table.pack and LOVE
For future reference, lua 5.2's table.pack is basically equivalent to:
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.)function pack(...)
return {n = select('#', ...), ...}
end
- ArchAngel075
- Party member
- Posts: 319
- Joined: Mon Jun 24, 2013 5:16 am
Re: table.pack and LOVE
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-
Anyhow thanks all for the tips and input >>
-end-
Re: table.pack and LOVE
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.
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.
- ArchAngel075
- Party member
- Posts: 319
- Joined: Mon Jun 24, 2013 5:16 am
Re: table.pack and LOVE
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.
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
Sounds like you're doing this sensibly.
Good luck with your project, hope to see it in P&D soon.
This is why I mentioned not sending anything other than 'raw values'.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
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.
Who is online
Users browsing this forum: Bing [Bot] and 5 guests