Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yyjson-cinder

Bindings for yyjson in the Cinder programming language.

Requirements

  • The Cinder compiler (cinder on PATH)
  • LLVM llc, as, and a C compiler (cc)
  • yyjson installed on the system, with headers and pkg-config support (this project does not vendor yyjson, install it with your package manager)

Building

make            # builds examples/ into build/
make test       # builds and runs test/test_basic.cnd
make clean

Usage

use "std/io.cnd";
use "yyjson.cnd";

fn main() -> i32 {
    let json = "{\"name\":\"cinder\"}";
    let mut err = YyjsonReadErr { code: 0, msg: null, pos: 0 };

    let doc = yyjson_parse(json, &err) else {
        println_err("failed to parse json");
        return 1;
    };
    defer yyjson_free(doc);

    let root = yyjson_root(doc) else { return 1; };
    let name = yyjson_obj_get(root, c"name") else { return 1; };
    println(yyjson_val_get_str(name));
    return 0;
}

Build it against the bindings with -I src, same as the bundled examples.

API overview

Opaque handles: YyjsonDoc, YyjsonVal, YyjsonMutDoc, YyjsonMutVal, always used through pointers.

Reading: yyjson_parse, yyjson_parse_opts, yyjson_free, yyjson_root, yyjson_val_type, yyjson_val_is_*, yyjson_val_get_bool/sint/uint/real/num/str, yyjson_arr_len, yyjson_arr_get, yyjson_arr_iter_init/next, yyjson_obj_len, yyjson_obj_get, yyjson_obj_iter_init/next, yyjson_obj_iter_get_val, yyjson_write.

Writing (mutable documents): yyjson_mut_new, yyjson_mut_free, yyjson_mut_set_root, yyjson_mut_null/bool/uint/sint/real/str/arr/obj, yyjson_mut_arr_add, yyjson_mut_obj_add, yyjson_mut_write.

Object keys are passed as null-terminated *u8 (use c"key" literals). Buffers returned by yyjson_write/yyjson_mut_write are heap-allocated by yyjson's default allocator; free them with dealloc(.ptr) from std/alloc.cnd once done.

Read/write option flags (YYJSON_READ_*, YYJSON_WRITE_*) and the type tag constants (YYJSON_TYPE_*) are exported as-is from yyjson.h.

License

MIT, see LICENSE.

About

Bindings for yyjson in the Cinder programming language.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Contributors

Languages