lunajson icon indicating copy to clipboard operation
lunajson copied to clipboard

Pretty Encoding

Open Ayplow opened this issue 5 years ago • 5 comments

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

Ayplow avatar Aug 05 '19 21:08 Ayplow

You are using _ENV... is your changes breaks the Lua 5.1 compat ?

tst2005 avatar Aug 06 '19 10:08 tst2005

Hah right, forgot to write the compat. I'll get on that

Ayplow avatar Aug 06 '19 19:08 Ayplow

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 ?

tst2005 avatar Aug 07 '19 09:08 tst2005

  • 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)

tst2005 avatar Aug 07 '19 11:08 tst2005

The string escape pattern is used in f_string? I don't understand what you mean.

Ayplow avatar Aug 07 '19 14:08 Ayplow