diff --git a/_demo/mkjson/mkjson.go b/_demo/mkjson/mkjson.go new file mode 100644 index 0000000..f4889b4 --- /dev/null +++ b/_demo/mkjson/mkjson.go @@ -0,0 +1,13 @@ +package main + +import ( + "github.com/goplus/cjson" + "github.com/goplus/llgo/c" +) + +func main() { + mod := cjson.Object() + mod.SetItem(c.Str("name"), cjson.String(c.Str("math"))) + c.Printf(c.Str("%s\n"), mod.CStr()) + mod.Delete() +} diff --git a/cjson.go b/cjson.go index 3d08175..d3ebf61 100644 --- a/cjson.go +++ b/cjson.go @@ -15,3 +15,102 @@ */ package cjson + +import ( + _ "unsafe" + + "github.com/goplus/llgo/c" +) + +const ( + LLGoPackage = "link: cjson" +) + +// llgo:type C +type JSON struct { + Unused [0]byte +} + +//go:linkname Null C.cJSON_CreateNull +func Null() *JSON + +//go:linkname True C.cJSON_CreateTrue +func True() *JSON + +//go:linkname False C.cJSON_CreateFalse +func False() *JSON + +//go:linkname Bool C.cJSON_CreateBool +func Bool(boolean c.Int) *JSON + +//go:linkname Number C.cJSON_CreateNumber +func Number(num float64) *JSON + +//go:linkname String C.cJSON_CreateString +func String(str *c.Char) *JSON + +//go:linkname Array C.cJSON_CreateArray +func Array() *JSON + +//go:linkname Object C.cJSON_CreateObject +func Object() *JSON + +// raw json +// +//go:linkname Raw C.cJSON_CreateRaw +func Raw(raw *c.Char) *JSON + +// Create a string where valuestring references a string so +// it will not be freed by Delete +// +//go:linkname StringRef C.cJSON_CreateStringReference +func StringRef(str *c.Char) *JSON + +// Create an object that only references it's elements so +// they will not be freed by Delete +// +//go:linkname ObjectRef C.cJSON_CreateObjectReference +func ObjectRef(child *JSON) *JSON + +// Create an array that only references it's elements so +// they will not be freed by Delete +// +//go:linkname ArrayRef C.cJSON_CreateArrayReference +func ArrayRef(child *JSON) *JSON + +// Delete a JSON entity and all subentities. +// +// llgo:link (*JSON).Delete C.cJSON_Delete +func (o *JSON) Delete() {} + +// Append item to the specified array. +// +// llgo:link (*JSON).Add C.cJSON_AddItemToArray +func (o *JSON) AddItem(item *JSON) c.Int { return 0 } + +// Append item to the specified object. +// +// llgo:link (*JSON).Set C.cJSON_AddItemToObject +func (o *JSON) SetItem(key *c.Char, item *JSON) c.Int { return 0 } + +// llgo:link (*JSON).CStr C.cJSON_PrintUnformatted +func (o *JSON) CStr() *c.Char { return nil } + +// Render a JSON entity to text for transfer/storage. +// +// llgo:link (*JSON).Print C.cJSON_Print +func (o *JSON) Print() *c.Char { return nil } + +// Render a JSON entity to text for transfer/storage without any formatting. +// +// llgo:link (*JSON).PrintUnformatted C.cJSON_PrintUnformatted +func (o *JSON) PrintUnformatted() *c.Char { return nil } + +// Render a JSON entity to text using a buffered strategy. +// +// prebuffer is a guess at the final size. guessing well reduces reallocation. +// +// fmt=0 gives unformatted, =1 gives formatted. +// +// llgo:link (*JSON).PrintBuffered C.cJSON_PrintBuffered +func (o *JSON) PrintBuffered(prebuffer c.Int, fmt c.Int) *c.Char { return nil } diff --git a/go.mod b/go.mod index b6fa2c6..57cd4ea 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/goplus/cjson go 1.18 + +require github.com/goplus/llgo v0.8.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..9d1325c --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/goplus/llgo v0.8.1 h1:M02K0unq0Ee/uK5wW1EBPCFJ+LxfQq45kkJawS5maRE= +github.com/goplus/llgo v0.8.1/go.mod h1:FZVAPoRTpAuQIizMP7wcZYcZ25Ft+GUX6WhD23GcFhc=