lunajson
lunajson copied to clipboard
Pretty Encoding
Related to #11
This is my shot at an efficient pretty encoding facility. I'm happy to implement any changes that could improve performance.
- A cache is built from the
cache
argument, avoiding recreation of indent strings. This will consume memory (that will be released with the encoder), however the footprint is minimal - Any encoders with the same indent share a cache. Only one assignment is made on depth change.
-
space
is equivalent to the third argument of javascript's JSON.stringify
You are using _ENV... is your changes breaks the Lua 5.1 compat ?
Hah right, forgot to write the compat. I'll get on that
Can't you just use a local table items instead of separated variables in _ENV ?
for sample
local config
...
-builder[i] = start_array
+builder[i] = config.start_array
...
- if type(space) ~= "string" or space == "" then _ENV = basic else
+ if type(space) ~= "string" or space == "" then config = basic else
and just avoid to use _ENV and ugly compat ?
- do you use somewhere the
f_string_esc_pat
introduce with the lua 5.1 compat ? - do you lost the original
local _ENV = nil
? (I don't know if it is really important)
The string escape pattern is used in f_string
? I don't understand what you mean.