![]() |
Fun 0.41.5
The programming language that makes you have fun!
|
VM opcode snippet for converting a Fun Value to a JSON string. More...
Go to the source code of this file.
Functions | |
| push_value (vm, make_string(js ? js :"")) | |
| json_object_put (j) | |
| free_value (vpretty) | |
| free_value (any) | |
Variables | |
| case | OP_JSON_STRINGIFY |
| Value | any = pop_value(vm) |
| int | pretty = (vpretty.type == VAL_BOOL || vpretty.type == VAL_INT) ? (vpretty.i != 0) : 0 |
| json_object * | j = fun_to_json(&any) |
| int | flags = pretty ? JSON_C_TO_STRING_PRETTY : JSON_C_TO_STRING_PLAIN |
| const char * | js = json_object_to_json_string_ext(j, flags) |
| break | |
VM opcode snippet for converting a Fun Value to a JSON string.
Implements the OP_JSON_STRINGIFY instruction. Expects a boolean/integer flag indicating pretty-printing and a Value to serialize. Uses json-c to build a json_object from the Value and then renders it to a string, which is pushed back to the stack.
Build gating: compiled only when FUN_WITH_JSON is enabled. Otherwise the opcode consumes its two arguments and pushes the string "null".
Stack effect (with FUN_WITH_JSON):
Errors and edge cases:
Definition in file stringify.c.
| free_value | ( | any | ) |
| free_value | ( | vpretty | ) |
| json_object_put | ( | j | ) |
| push_value | ( | vm | , |
| make_string(js ? js :"") | ) |
Definition at line 35 of file stringify.c.
| break |
Definition at line 52 of file stringify.c.
| int flags = pretty ? JSON_C_TO_STRING_PRETTY : JSON_C_TO_STRING_PLAIN |
Definition at line 38 of file stringify.c.
| json_object* j = fun_to_json(&any) |
Definition at line 37 of file stringify.c.
Definition at line 39 of file stringify.c.
| case OP_JSON_STRINGIFY |
Definition at line 32 of file stringify.c.
Definition at line 36 of file stringify.c.