Page 1 of 1

Question about Lube.bin:pack

Posted: Fri Oct 08, 2010 7:06 am
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?

Re: Question about Lube.bin:pack

Posted: Fri Oct 08, 2010 7:35 pm
by kikito
Define "choke".

(maybe with some code example, and the desired result)

Re: Question about Lube.bin:pack

Posted: Fri Oct 08, 2010 8:44 pm
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

Re: Question about Lube.bin:pack

Posted: Fri Oct 08, 2010 9:14 pm
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.

Re: Question about Lube.bin:pack

Posted: Fri Oct 08, 2010 9:21 pm
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