Improved table encoding code to handle sparse arrays.
By going through the table before to get the maximum index we can handle sparse arrays. Also tostring seems to work better by maintaining float and integer number conversion.
Hello! This would be nice change, but table.pack() creates an array with property n. Would it be possible to add check to line 71, that if k == "n" and type(v) == "number" then length = v else treat as object?
Lua documentation: https://www.lua.org/manual/5.2/manual.html#pdf-table.pack
Current behaviour:
> json.encode({1, nil, 3})
"[1,null,3]"
> json.encode(table.pack(1, nil, 3))
"{1:1,3:3,\"n\":3}"
Why is this beneficial?
If lua array ends with nil(s), they are trimmed. If we however use table.pack, the original count of objects is stored in property n allowing the array to end with nil/null.
Fixed that. Now arrays can be specified through table.pack.
@appgurueu Is there a reason for your abrupt and occasionally hostile behavior?
You're coming off as unnecessarily rude.
@appgurueu Is there a reason for your abrupt and occasionally hostile behavior?
You're coming off as unnecessarily rude.
I'm not sure what you consider to be rude about my review. I made three comments:
- Pointing out a possible worst-case scenario.
- Commenting on the bad formatting.
- Labeling a clear code smell (outcommented code) as "dirty". If it isn't dirty, is it clean? I believe(d) this to be self-evident; it does not need elaboration. Maybe I should have phrased this differently, as "oops, looks like you forgot some outcommented code here"?
- Pointing out that using
tostringon numbers is unreliable (if a certain format is expected). I should have elaborated on this; I didn't because it is something I am used to.
This was intended just as very "direct" feedback from a quick look. In hindsight, some of it would have needed some elaboration.
If I came off as rude to @aryajur, that was not my intention, and I apologize for that.
@appgurueu Is there a reason for your abrupt and occasionally hostile behavior? You're coming off as unnecessarily rude.
I'm not sure what you consider to be rude about my review. I made three comments:
- Pointing out a possible worst-case scenario.
- Commenting on the bad formatting.
- Labeling a clear code smell (outcommented code) as "dirty". If it isn't dirty, is it clean? I believe(d) this to be self-evident; it does not need elaboration. Maybe I should have phrased this differently, as "oops, looks like you forgot some outcommented code here"?
- Pointing out that using
tostringon numbers is unreliable (if a certain format is expected). I should have elaborated on this; I didn't because it is something I am used to.This was intended just as very "direct" feedback from a quick look. In hindsight, some of it would have needed some elaboration.
If I came off as rude to @aryajur, that was not my intention, and I apologize for that.
I appreciate your feedback. Would always want to improve my work.