fix: sjson -> cjson.
This commit is contained in:
parent
784b2dbfdf
commit
696fe8843d
6 changed files with 35 additions and 26 deletions
|
@ -1,4 +1,4 @@
|
|||
package sjson
|
||||
package cjson
|
||||
|
||||
import "github.com/d5/tengo/v2"
|
||||
import "encoding/json"
|
||||
|
@ -28,10 +28,10 @@ func NewDecoder(args ...tengo.Object) (tengo.Object, error) {
|
|||
inputName = StrStdin
|
||||
} else if len(args) > 1 {
|
||||
return nil, tengo.ErrWrongNumArguments
|
||||
}
|
||||
|
||||
} else {
|
||||
var ok bool
|
||||
inputObject := args[0]
|
||||
inputName, ok := tengo.ToString(inputObject)
|
||||
inputName, ok = tengo.ToString(inputObject)
|
||||
if !ok {
|
||||
return nil, tengo.ErrInvalidArgumentType{
|
||||
Name: "first",
|
||||
|
@ -39,6 +39,8 @@ func NewDecoder(args ...tengo.Object) (tengo.Object, error) {
|
|||
Found: inputObject.TypeName(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var reader io.Reader
|
||||
var err error
|
|
@ -1,4 +1,4 @@
|
|||
package sjson
|
||||
package cjson
|
||||
|
||||
import "github.com/d5/tengo/v2"
|
||||
import "io"
|
16
tests/cjson.xgo
Normal file
16
tests/cjson.xgo
Normal 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
4
tests/data.cjson
Normal file
|
@ -0,0 +1,4 @@
|
|||
{"somename": {
|
||||
"value": 1
|
||||
}}
|
||||
["array",135,"integers", 135, 135]
|
|
@ -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)
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue