diff --git a/gjson/config.go b/gjson/config.go index a318557..c792721 100644 --- a/gjson/config.go +++ b/gjson/config.go @@ -2,14 +2,14 @@ package gjson // Default configuration values (matching lua-cjson defaults) const ( - defaultEncodeSparseConvert = false - defaultEncodeSparseRatio = 2 - defaultEncodeSparseSafe = 10 - defaultEncodeMaxDepth = 1000 - defaultDecodeMaxDepth = 1000 + defaultEncodeSparseConvert = false + defaultEncodeSparseRatio = 2 + defaultEncodeSparseSafe = 10 + defaultEncodeMaxDepth = 1000 + defaultDecodeMaxDepth = 1000 defaultEncodeNumberPrecision = 14 - defaultEncodeKeepBuffer = true - defaultEncodeSortKeys = false // 默认不排序,保持高性能 + defaultEncodeKeepBuffer = true + defaultEncodeSortKeys = false // 默认不排序,保持高性能 ) // sparseArrayConfig controls sparse array handling during encoding. @@ -21,12 +21,12 @@ type sparseArrayConfig struct { // Config holds all configuration options for a GJSON instance. type Config struct { - encodeSparseArray sparseArrayConfig - encodeMaxDepth int - decodeMaxDepth int + encodeSparseArray sparseArrayConfig + encodeMaxDepth int + decodeMaxDepth int encodeNumberPrecision int - encodeKeepBuffer bool - encodeSortKeys bool // 是否对 object 键排序(稳定输出) + encodeKeepBuffer bool + encodeSortKeys bool // 是否对 object 键排序(稳定输出) } // defaultConfig returns a new Config with default values. @@ -37,11 +37,11 @@ func defaultConfig() *Config { ratio: defaultEncodeSparseRatio, safe: defaultEncodeSparseSafe, }, - encodeMaxDepth: defaultEncodeMaxDepth, - decodeMaxDepth: defaultDecodeMaxDepth, + encodeMaxDepth: defaultEncodeMaxDepth, + decodeMaxDepth: defaultDecodeMaxDepth, encodeNumberPrecision: defaultEncodeNumberPrecision, - encodeKeepBuffer: defaultEncodeKeepBuffer, - encodeSortKeys: defaultEncodeSortKeys, + encodeKeepBuffer: defaultEncodeKeepBuffer, + encodeSortKeys: defaultEncodeSortKeys, } } @@ -53,10 +53,10 @@ func (c *Config) Clone() *Config { ratio: c.encodeSparseArray.ratio, safe: c.encodeSparseArray.safe, }, - encodeMaxDepth: c.encodeMaxDepth, - decodeMaxDepth: c.decodeMaxDepth, + encodeMaxDepth: c.encodeMaxDepth, + decodeMaxDepth: c.decodeMaxDepth, encodeNumberPrecision: c.encodeNumberPrecision, - encodeKeepBuffer: c.encodeKeepBuffer, - encodeSortKeys: c.encodeSortKeys, + encodeKeepBuffer: c.encodeKeepBuffer, + encodeSortKeys: c.encodeSortKeys, } } diff --git a/gjson/decode.go b/gjson/decode.go index 4a65b91..71e1dcd 100644 --- a/gjson/decode.go +++ b/gjson/decode.go @@ -108,4 +108,4 @@ func parseJSONNumber(s string) (glua.LNumber, error) { } return glua.LNumber(0), fmt.Errorf("invalid number format: %s", s) -} \ No newline at end of file +} diff --git a/gjson/encode.go b/gjson/encode.go index 1434e67..d91231e 100644 --- a/gjson/encode.go +++ b/gjson/encode.go @@ -267,4 +267,3 @@ func formatNumber(n float64, precision int) string { // Use 'g' format for floating point return strconv.FormatFloat(n, 'g', precision, 64) } - diff --git a/internal/lua/coroutine.go b/internal/lua/coroutine.go index 648f8b8..393bdb3 100644 --- a/internal/lua/coroutine.go +++ b/internal/lua/coroutine.go @@ -368,7 +368,6 @@ func (c *LuaCoroutine) executeProto(proto *glua.FunctionProto) error { fn := c.Co.NewFunctionFromProto(proto) c.Co.Push(fn) err := c.Co.PCall(0, 0, nil) - if err != nil { atomic.AddUint64(&c.Engine.stats.ScriptsErrors, 1) return fmt.Errorf("lua execution error: %w", err) diff --git a/internal/lua/pool.go b/internal/lua/pool.go index fa89484..5070724 100644 --- a/internal/lua/pool.go +++ b/internal/lua/pool.go @@ -50,7 +50,7 @@ func NewLStatePool(factory func() *glua.LState, initialSize, maxSize int) *LStat } // 预热:预先创建 initialSize 个 LState - for i := 0; i < initialSize; i++ { + for range initialSize { L := p.factory() p.pool = append(p.pool, L) p.current++