Question about Lube.bin:pack

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.
Post Reply
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Question about Lube.bin:pack

Post by Mr. Strange »

I've got this working on tables for which each element is a value - but it seems to choke on tables which have other tables as elements.

Is that the intent? Or is there some way I can make this work without adjusting my data structure?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Question about Lube.bin:pack

Post by kikito »

Define "choke".

(maybe with some code example, and the desired result)
When I write def I mean function.
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Re: Question about Lube.bin:pack

Post by Mr. Strange »

I have a table in this form:

example = {
name = myName,
pos = { x = 0, y = 0},
color = "red",
}

When I call lube.bin:pack(example) I get an error message which says : "Type table is not supported by lube.bin"

If I remove the sub-table (the pos = {} line) and replace it with a variable, it works fine. So my conclusion is that I can't pack a table which includes tables as elements. This seems really limiting - but maybe that's just because I have unreasonable expectations?

I could do something like write a manual pack function - but that seems silly. The pack function looks like it could easily be modified to include tables as a supported type - of course this makes the function somewhat recursive, which is maybe a frightening thing.

In any case, I hope that clears up my question

--Mr. Strange
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Question about Lube.bin:pack

Post by bartbes »

No, the thing is, the code isn't smart enough to recognize embedded tables, you can however, change the special characters, pack the subtable with it, switch back and pack a table with the pre-packed string. Oh, and that sucks I know, but lube.bin, like lube.easy isn't really advanced, in fact, I remember writing a notice somewhere about it being mostly for reference/learning/base/whatever.
Mr. Strange
Party member
Posts: 101
Joined: Mon Aug 11, 2008 5:19 am

Re: Question about Lube.bin:pack

Post by Mr. Strange »

Since my last post I re-wrote lube.bin:pack to pack tables as well, but then I realized that since the elements in the sub-table are spaced with null characters just like the elements of the parent - unpack can't differentiate.

Crap.

Well, unless someone steps up to write a more intelligent recursive unpack mechanism, I guess I'll have to re-structure my data. Grrr...

--Mr. Strange
Post Reply

Who is online

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