| 1 | module main |
| 2 | |
| 3 | import json.cjson |
| 4 | |
| 5 | type Node = C.cJSON |
| 6 | |
| 7 | fn as_n(p &cjson.Node) &Node { |
| 8 | return unsafe { &Node(p) } |
| 9 | } |
| 10 | |
| 11 | fn as_c(p &Node) &cjson.Node { |
| 12 | return unsafe { &cjson.Node(p) } |
| 13 | } |
| 14 | |
| 15 | @[inline] |
| 16 | fn create_object() &Node { |
| 17 | return as_n(cjson.create_object()) |
| 18 | } |
| 19 | |
| 20 | @[inline] |
| 21 | fn create_array() &Node { |
| 22 | return as_n(cjson.create_array()) |
| 23 | } |
| 24 | |
| 25 | @[inline] |
| 26 | fn create_string(val string) &Node { |
| 27 | return as_n(cjson.create_string(val)) |
| 28 | } |
| 29 | |
| 30 | @[inline] |
| 31 | fn create_number(val f64) &Node { |
| 32 | return as_n(cjson.create_number(val)) |
| 33 | } |
| 34 | |
| 35 | @[inline] |
| 36 | fn create_true() &Node { |
| 37 | return as_n(cjson.create_true()) |
| 38 | } |
| 39 | |
| 40 | @[inline] |
| 41 | fn create_false() &Node { |
| 42 | return as_n(cjson.create_false()) |
| 43 | } |
| 44 | |
| 45 | @[inline] |
| 46 | fn create_null() &Node { |
| 47 | return as_n(cjson.create_null()) |
| 48 | } |
| 49 | |
| 50 | @[inline] |
| 51 | fn add_item_to_object(mut obj Node, key string, item &Node) { |
| 52 | mut o := unsafe { &cjson.Node(obj) } |
| 53 | o.add_item_to_object(key, item) |
| 54 | } |
| 55 | |
| 56 | @[inline] |
| 57 | fn add_item_to_array(mut obj Node, item &Node) { |
| 58 | mut o := as_c(obj) |
| 59 | o.add_item_to_array(item) |
| 60 | } |
| 61 | |
| 62 | fn json_print(mut obj Node) string { |
| 63 | mut o := as_c(obj) |
| 64 | return o.print() |
| 65 | } |
| 66 | |