fix: sjson -> cjson.

This commit is contained in:
Andrey Parhomenko 2024-06-06 11:07:56 +05:00
parent 784b2dbfdf
commit 696fe8843d
6 changed files with 35 additions and 26 deletions

View file

@ -1,4 +1,4 @@
package sjson
package cjson
import "github.com/d5/tengo/v2"
import "encoding/json"
@ -28,18 +28,20 @@ func NewDecoder(args ...tengo.Object) (tengo.Object, error) {
inputName = StrStdin
} else if len(args) > 1 {
return nil, tengo.ErrWrongNumArguments
}
inputObject := args[0]
inputName, ok := tengo.ToString(inputObject)
if !ok {
return nil, tengo.ErrInvalidArgumentType{
Name: "first",
Expected: "stringer",
Found: inputObject.TypeName(),
} else {
var ok bool
inputObject := args[0]
inputName, ok = tengo.ToString(inputObject)
if !ok {
return nil, tengo.ErrInvalidArgumentType{
Name: "first",
Expected: "stringer",
Found: inputObject.TypeName(),
}
}
}
var reader io.Reader
var err error
switch {

View file

@ -1,4 +1,4 @@
package sjson
package cjson
import "github.com/d5/tengo/v2"
import "io"

16
tests/cjson.xgo Normal file
View file

@ -0,0 +1,16 @@
cjson := import("cjson")
fmt := import("fmt")
fmt.println(cjson.__check())
dec := cjson.new_decoder("tests/data.cjson")
for {
v := dec.decode()
if is_error(v) {
break
}
if !v {
break
}
fmt.println(v)
}

4
tests/data.cjson Normal file
View file

@ -0,0 +1,4 @@
{"somename": {
"value": 1
}}
["array",135,"integers", 135, 135]

View file

@ -1,13 +0,0 @@
sjson := import("sjson")
fmt := import("fmt")
fmt.println(sjson.__check())
dec := sjson.new_decoder("<stdin>")
for {
v := dec.decode()
if !v {
break
}
fmt.println(v)
}

View file

@ -19,7 +19,7 @@ import (
)
import "surdeus.su/core/cli/mtool"
import "surdeus.su/core/xgo/sjson"
import "surdeus.su/core/xgo/cjson"
const (
sourceFileExt = ".xgo"
@ -53,7 +53,7 @@ func Run(flags *mtool.Flags) {
return
}
modules := stdlib.GetModuleMap(stdlib.AllModuleNames()...)
modules.AddBuiltinModule("sjson", sjson.Module)
modules.AddBuiltinModule("cjson", cjson.Module)
if len(iargs) == 0 {
// REPL
RunREPL(modules, os.Stdin, os.Stdout)