Kohi Game Engine
|
This file contains the parser implementation for the KSON (Kohi Storage Object Notation) file format. More...
#include "defines.h"
#include "math/math_types.h"
#include "strings/kname.h"
#include "strings/kstring_id.h"
Go to the source code of this file.
Data Structures | |
struct | kson_token |
struct | kson_parser |
struct | kson_object |
union | kson_property_value |
struct | kson_property |
struct | kson_tree |
Typedefs | |
typedef enum kson_token_type | kson_token_type |
typedef struct kson_token | kson_token |
typedef struct kson_parser | kson_parser |
typedef enum kson_property_type | kson_property_type |
typedef enum kson_object_type | kson_object_type |
typedef struct kson_object | kson_object |
typedef kson_object | kson_array |
typedef union kson_property_value | kson_property_value |
typedef struct kson_property | kson_property |
typedef struct kson_tree | kson_tree |
Functions | |
KAPI const char * | kson_property_type_to_string (kson_property_type type) |
Gets the given property type as a constant string. NOTE: Caller should NOT attempt to free this string. More... | |
KAPI b8 | kson_parser_create (kson_parser *out_parser) |
Creates a kson parser. Note that it is generally recommended to use the kson_tree_from_string() and kson_tree_to_string() functions instead of invoking this manually, as these also handle cleanup of the parser object. More... | |
KAPI void | kson_parser_destroy (kson_parser *parser) |
Destroys the provided parser. More... | |
KAPI b8 | kson_parser_tokenize (kson_parser *parser, const char *source) |
Uses the given parser to tokenize the provided source string. Note that it is recommended to use the kson_tree_from_string() function instead. More... | |
KAPI b8 | kson_parser_parse (kson_parser *parser, kson_tree *out_tree) |
Uses the given parser to build a kson_tree using the tokens previously parsed. This means that kson_parser_tokenize() must have been called and completed successfully for this function to work. It is recommended to use kson_tree_from_string() instead. More... | |
KAPI b8 | kson_tree_from_string (const char *source, kson_tree *out_tree) |
Takes the provided source and tokenizes, then parses it in order to create a tree of kson_objects. More... | |
KAPI const char * | kson_tree_to_string (kson_tree *tree) |
KAPI void | kson_object_cleanup (kson_object *obj) |
Cleans up the given kson object and its properties recursively. More... | |
KAPI void | kson_tree_cleanup (kson_tree *tree) |
Performs cleanup operations on the given tree, freeing memory and resources held by it. More... | |
KAPI b8 | kson_array_value_add_int (kson_array *array, i64 value) |
Adds an unnamed signed 64-bit integer value to the provided array. More... | |
KAPI b8 | kson_array_value_add_float (kson_array *array, f32 value) |
Adds an unnamed floating-point value to the provided array. More... | |
KAPI b8 | kson_array_value_add_boolean (kson_array *array, b8 value) |
Adds an unnamed boolean value to the provided array. More... | |
KAPI b8 | kson_array_value_add_string (kson_array *array, const char *value) |
Adds an unnamed string value to the provided array. More... | |
KAPI b8 | kson_array_value_add_mat4 (kson_array *array, mat4 value) |
Adds an unnamed mat4 value to the provided array. More... | |
KAPI b8 | kson_array_value_add_vec4 (kson_array *array, vec4 value) |
Adds an unnamed vec4 value to the provided array. More... | |
KAPI b8 | kson_array_value_add_vec3 (kson_array *array, vec3 value) |
Adds an unnamed vec3 value to the provided array. More... | |
KAPI b8 | kson_array_value_add_vec2 (kson_array *array, vec2 value) |
Adds an unnamed vec2 value to the provided array. More... | |
KAPI b8 | kson_array_value_add_kname_as_string (kson_array *array, kname value) |
Adds an unnamed kname value as a string to the provided array. More... | |
KAPI b8 | kson_array_value_add_kstring_id_as_string (kson_array *array, kstring_id value) |
Adds an unnamed kstring_id value as a string to the provided array. More... | |
KAPI b8 | kson_array_value_add_object (kson_array *array, kson_object value) |
Adds an unnamed object value to the provided array. More... | |
KAPI b8 | kson_array_value_add_object_empty (kson_array *array) |
Adds an unnamed empty object value to the provided array. More... | |
KAPI b8 | kson_array_value_add_array (kson_array *array, kson_array value) |
Adds an unnamed array value to the provided array. More... | |
KAPI b8 | kson_array_value_add_array_empty (kson_array *array) |
Adds an unnamed empty array value to the provided array. More... | |
KAPI b8 | kson_object_value_add_int (kson_object *object, const char *name, i64 value) |
Adds a named signed 64-bit integer value to the provided object. More... | |
KAPI b8 | kson_object_value_add_float (kson_object *object, const char *name, f32 value) |
Adds a named floating-point value to the provided object. More... | |
KAPI b8 | kson_object_value_add_boolean (kson_object *object, const char *name, b8 value) |
Adds a named boolean value to the provided object. More... | |
KAPI b8 | kson_object_value_add_string (kson_object *object, const char *name, const char *value) |
Adds a named string value to the provided object. More... | |
KAPI b8 | kson_object_value_add_mat4 (kson_object *object, const char *name, mat4 value) |
Adds a named mat4 value to the provided object. More... | |
KAPI b8 | kson_object_value_add_vec4 (kson_object *object, const char *name, vec4 value) |
Adds a named vec4 value to the provided object. More... | |
KAPI b8 | kson_object_value_add_vec3 (kson_object *object, const char *name, vec3 value) |
Adds a named vec3 value to the provided object. More... | |
KAPI b8 | kson_object_value_add_vec2 (kson_object *object, const char *name, vec2 value) |
Adds a named vec2 value to the provided object. More... | |
KAPI b8 | kson_object_value_add_kname_as_string (kson_object *object, const char *name, kname value) |
Adds a named kname value as a string to the provided object. More... | |
KAPI b8 | kson_object_value_add_kstring_id_as_string (kson_object *object, const char *name, kstring_id value) |
Adds a named kstring_id value as a string to the provided object. More... | |
KAPI b8 | kson_object_value_add_object (kson_object *object, const char *name, kson_object value) |
Adds a named object value to the provided object. More... | |
KAPI b8 | kson_object_value_add_object_empty (kson_object *object, const char *name) |
Adds a named empty object value to the provided object. More... | |
KAPI b8 | kson_object_value_add_array (kson_object *object, const char *name, kson_array value) |
Adds a named array value to the provided object. More... | |
KAPI b8 | kson_object_value_add_array_empty (kson_object *object, const char *name) |
Adds a named empty array value to the provided object. More... | |
KAPI b8 | kson_array_element_count_get (kson_array *array, u32 *out_count) |
Obtains the length of the given array. More... | |
KAPI b8 | kson_array_element_type_at (kson_array *array, u32 index, kson_property_type *out_type) |
Obtains the element type at the provided index of the given array. Fails if out of range. More... | |
KAPI b8 | kson_array_element_value_get_int (const kson_array *array, u32 index, i64 *out_value) |
Attempts to retrieve the array element's value at the provided index as a signed integer. Fails if out of range. or on type mismatch. More... | |
KAPI b8 | kson_array_element_value_get_float (const kson_array *array, u32 index, f32 *out_value) |
Attempts to retrieve the array element's value at the provided index as a floating-point number. Fails if out of range. or on type mismatch. More... | |
KAPI b8 | kson_array_element_value_get_bool (const kson_array *array, u32 index, b8 *out_value) |
Attempts to retrieve the array element's value at the provided index as a boolean. Fails if out of range. or on type mismatch. More... | |
KAPI b8 | kson_array_element_value_get_string (const kson_array *array, u32 index, const char **out_value) |
Attempts to retrieve the array element's value at the provided index as a string. Fails if out of range or on type mismatch. More... | |
KAPI b8 | kson_array_element_value_get_mat4 (const kson_array *array, u32 index, mat4 *out_value) |
Attempts to retrieve the array element's value at the provided index as a mat4. Fails if out of range or on type mismatch (these are stored as strings). More... | |
KAPI b8 | kson_array_element_value_get_vec4 (const kson_array *array, u32 index, vec4 *out_value) |
Attempts to retrieve the array element's value at the provided index as a vec4. Fails if out of range or on type mismatch (these are stored as strings). More... | |
KAPI b8 | kson_array_element_value_get_vec3 (const kson_array *array, u32 index, vec3 *out_value) |
Attempts to retrieve the array element's value at the provided index as a vec3. Fails if out of range or on type mismatch (these are stored as strings). More... | |
KAPI b8 | kson_array_element_value_get_vec2 (const kson_array *array, u32 index, vec2 *out_value) |
Attempts to retrieve the array element's value at the provided index as a vec2. Fails if out of range or on type mismatch (these are stored as strings). More... | |
KAPI b8 | kson_array_element_value_get_string_as_kname (const kson_array *array, u32 index, kname *out_value) |
Attempts to retrieve the array element's value at the provided index as a kname. Fails if out of range or on type mismatch. knames are always stored as strings. More... | |
KAPI b8 | kson_array_element_value_get_string_as_kstring_id (const kson_array *array, u32 index, kstring_id *out_value) |
Attempts to retrieve the array element's value at the provided index as a kstring_id. Fails if out of range or on type mismatch. kstring_ids are always stored as strings. More... | |
KAPI b8 | kson_array_element_value_get_object (const kson_array *array, u32 index, kson_object *out_value) |
Attempts to retrieve the array element's value at the provided index as an object. Fails if out of range. or on type mismatch. More... | |
KAPI b8 | kson_array_element_value_get_array (const kson_array *array, u32 index, kson_array *out_value) |
Attempts to retrieve the array element's value at the provided index as an array. Fails if out of range. or on type mismatch. More... | |
KAPI b8 | kson_object_property_type_get (const kson_object *object, const char *name, kson_property_type *out_type) |
KAPI b8 | kson_object_property_count_get (const kson_object *object, u32 *out_count) |
KAPI b8 | kson_object_property_value_type_get (const kson_object *object, const char *name, kson_property_type *out_type) |
Attempts to retrieve the given object's property value type by name. Fails if not found. More... | |
KAPI b8 | kson_object_property_value_get_int (const kson_object *object, const char *name, i64 *out_value) |
Attempts to retrieve the given object's property value by name as a signed integer. Fails if not found or on type mismatch. More... | |
KAPI b8 | kson_object_property_value_get_float (const kson_object *object, const char *name, f32 *out_value) |
Attempts to retrieve the given object's property value by name as a floating-point number. Fails if not found or on type mismatch. More... | |
KAPI b8 | kson_object_property_value_get_bool (const kson_object *object, const char *name, b8 *out_value) |
Attempts to retrieve the given object's property value by name as a boolean. Fails if not found or on type mismatch. More... | |
KAPI b8 | kson_object_property_value_get_string (const kson_object *object, const char *name, const char **out_value) |
Attempts to retrieve the given object's property value by name as a string. Fails if not found or on type mismatch. NOTE: This function always allocates new memory, so the string should be released afterward. More... | |
KAPI b8 | kson_object_property_value_get_mat4 (const kson_object *object, const char *name, mat4 *out_value) |
Attempts to retrieve the given object's property value by name as a mat4. Fails if not found or on type mismatch (these are always stored as strings). More... | |
KAPI b8 | kson_object_property_value_get_vec4 (const kson_object *object, const char *name, vec4 *out_value) |
Attempts to retrieve the given object's property value by name as a vec4. Fails if not found or on type mismatch (these are always stored as strings). More... | |
KAPI b8 | kson_object_property_value_get_vec3 (const kson_object *object, const char *name, vec3 *out_value) |
Attempts to retrieve the given object's property value by name as a vec3. Fails if not found or on type mismatch (these are always stored as strings). More... | |
KAPI b8 | kson_object_property_value_get_vec2 (const kson_object *object, const char *name, vec2 *out_value) |
Attempts to retrieve the given object's property value by name as a vec2. Fails if not found or on type mismatch (these are always stored as strings). More... | |
KAPI b8 | kson_object_property_value_get_string_as_kname (const kson_object *object, const char *name, kname *out_value) |
Attempts to retrieve the given object's property value by name as a kname. Fails if not found or on type mismatch. knames are always stored as thier original text format. More... | |
KAPI b8 | kson_object_property_value_get_string_as_kstring_id (const kson_object *object, const char *name, kstring_id *out_value) |
Attempts to retrieve the given object's property value by name as a kstring_id. Fails if not found or on type mismatch. kstring_ids are always stored as thier original text format. More... | |
KAPI b8 | kson_object_property_value_get_object (const kson_object *object, const char *name, kson_object *out_value) |
Attempts to retrieve the a copy given object's property value by name as an object. Fails if not found or on type mismatch. More... | |
KAPI b8 | kson_object_property_value_get_array (const kson_object *object, const char *name, kson_array *out_value) |
Attempts to retrieve the a copy given object's property value by name as an array. Fails if not found or on type mismatch. More... | |
KAPI kson_property | kson_object_property_create (const char *name) |
KAPI kson_property | kson_array_property_create (const char *name) |
KAPI kson_object | kson_object_create (void) |
Creates and returns a new kson object. More... | |
KAPI kson_array | kson_array_create (void) |
Creates and returns a new kson array. More... | |
This file contains the parser implementation for the KSON (Kohi Storage Object Notation) file format.
typedef kson_object kson_array |
typedef struct kson_object kson_object |
typedef enum kson_object_type kson_object_type |
typedef struct kson_parser kson_parser |
typedef struct kson_property kson_property |
typedef enum kson_property_type kson_property_type |
typedef union kson_property_value kson_property_value |
typedef struct kson_token kson_token |
typedef enum kson_token_type kson_token_type |
enum kson_object_type |
enum kson_property_type |
enum kson_token_type |
KAPI kson_array kson_array_create | ( | void | ) |
Creates and returns a new kson array.
KAPI b8 kson_array_element_count_get | ( | kson_array * | array, |
u32 * | out_count | ||
) |
Obtains the length of the given array.
array | The array to retrieve the length of. |
count | A pointer to hold the array element count, |
KAPI b8 kson_array_element_type_at | ( | kson_array * | array, |
u32 | index, | ||
kson_property_type * | out_type | ||
) |
Obtains the element type at the provided index of the given array. Fails if out of range.
array | The array to retrieve the type from. |
index | The index into the array to check the type of. Must be in range. |
count | A pointer to hold the array element type, |
KAPI b8 kson_array_element_value_get_array | ( | const kson_array * | array, |
u32 | index, | ||
kson_array * | out_value | ||
) |
Attempts to retrieve the array element's value at the provided index as an array. Fails if out of range. or on type mismatch.
array | A constant pointer to the array to search. Required. |
index | The array index to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_array_element_value_get_bool | ( | const kson_array * | array, |
u32 | index, | ||
b8 * | out_value | ||
) |
Attempts to retrieve the array element's value at the provided index as a boolean. Fails if out of range. or on type mismatch.
array | A constant pointer to the array to search. Required. |
index | The array index to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_array_element_value_get_float | ( | const kson_array * | array, |
u32 | index, | ||
f32 * | out_value | ||
) |
Attempts to retrieve the array element's value at the provided index as a floating-point number. Fails if out of range. or on type mismatch.
array | A constant pointer to the array to search. Required. |
index | The array index to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_array_element_value_get_int | ( | const kson_array * | array, |
u32 | index, | ||
i64 * | out_value | ||
) |
Attempts to retrieve the array element's value at the provided index as a signed integer. Fails if out of range. or on type mismatch.
array | A constant pointer to the array to search. Required. |
index | The array index to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_array_element_value_get_mat4 | ( | const kson_array * | array, |
u32 | index, | ||
mat4 * | out_value | ||
) |
Attempts to retrieve the array element's value at the provided index as a mat4. Fails if out of range or on type mismatch (these are stored as strings).
array | A constant pointer to the array to search. Required. |
index | The array index to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_array_element_value_get_object | ( | const kson_array * | array, |
u32 | index, | ||
kson_object * | out_value | ||
) |
Attempts to retrieve the array element's value at the provided index as an object. Fails if out of range. or on type mismatch.
array | A constant pointer to the array to search. Required. |
index | The array index to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_array_element_value_get_string | ( | const kson_array * | array, |
u32 | index, | ||
const char ** | out_value | ||
) |
Attempts to retrieve the array element's value at the provided index as a string. Fails if out of range or on type mismatch.
array | A constant pointer to the array to search. Required. |
index | The array index to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_array_element_value_get_string_as_kname | ( | const kson_array * | array, |
u32 | index, | ||
kname * | out_value | ||
) |
Attempts to retrieve the array element's value at the provided index as a kname. Fails if out of range or on type mismatch. knames are always stored as strings.
array | A constant pointer to the array to search. Required. |
index | The array index to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_array_element_value_get_string_as_kstring_id | ( | const kson_array * | array, |
u32 | index, | ||
kstring_id * | out_value | ||
) |
Attempts to retrieve the array element's value at the provided index as a kstring_id. Fails if out of range or on type mismatch. kstring_ids are always stored as strings.
array | A constant pointer to the array to search. Required. |
index | The array index to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_array_element_value_get_vec2 | ( | const kson_array * | array, |
u32 | index, | ||
vec2 * | out_value | ||
) |
Attempts to retrieve the array element's value at the provided index as a vec2. Fails if out of range or on type mismatch (these are stored as strings).
array | A constant pointer to the array to search. Required. |
index | The array index to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_array_element_value_get_vec3 | ( | const kson_array * | array, |
u32 | index, | ||
vec3 * | out_value | ||
) |
Attempts to retrieve the array element's value at the provided index as a vec3. Fails if out of range or on type mismatch (these are stored as strings).
array | A constant pointer to the array to search. Required. |
index | The array index to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_array_element_value_get_vec4 | ( | const kson_array * | array, |
u32 | index, | ||
vec4 * | out_value | ||
) |
Attempts to retrieve the array element's value at the provided index as a vec4. Fails if out of range or on type mismatch (these are stored as strings).
array | A constant pointer to the array to search. Required. |
index | The array index to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI kson_property kson_array_property_create | ( | const char * | name | ) |
Creates and returns a new property of the array type.
name | The name of the property. Pass 0 if later adding to an array. |
KAPI b8 kson_array_value_add_array | ( | kson_array * | array, |
kson_array | value | ||
) |
Adds an unnamed array value to the provided array.
array | A pointer to the array to add the property to. |
value | The value to be set. |
KAPI b8 kson_array_value_add_array_empty | ( | kson_array * | array | ) |
Adds an unnamed empty array value to the provided array.
array | A pointer to the array to add the property to. |
KAPI b8 kson_array_value_add_boolean | ( | kson_array * | array, |
b8 | value | ||
) |
Adds an unnamed boolean value to the provided array.
array | A pointer to the array to add the property to. |
value | The value to be set. |
KAPI b8 kson_array_value_add_float | ( | kson_array * | array, |
f32 | value | ||
) |
Adds an unnamed floating-point value to the provided array.
array | A pointer to the array to add the property to. |
value | The value to be set. |
KAPI b8 kson_array_value_add_int | ( | kson_array * | array, |
i64 | value | ||
) |
Adds an unnamed signed 64-bit integer value to the provided array.
array | A pointer to the array to add the property to. |
value | The value to be set. |
KAPI b8 kson_array_value_add_kname_as_string | ( | kson_array * | array, |
kname | value | ||
) |
Adds an unnamed kname value as a string to the provided array.
array | A pointer to the array to add the property to. |
value | The value to be set. |
KAPI b8 kson_array_value_add_kstring_id_as_string | ( | kson_array * | array, |
kstring_id | value | ||
) |
Adds an unnamed kstring_id value as a string to the provided array.
array | A pointer to the array to add the property to. |
value | The value to be set. |
KAPI b8 kson_array_value_add_mat4 | ( | kson_array * | array, |
mat4 | value | ||
) |
Adds an unnamed mat4 value to the provided array.
array | A pointer to the array to add the property to. |
value | The value to be set. |
KAPI b8 kson_array_value_add_object | ( | kson_array * | array, |
kson_object | value | ||
) |
Adds an unnamed object value to the provided array.
array | A pointer to the array to add the property to. |
value | The value to be set. |
KAPI b8 kson_array_value_add_object_empty | ( | kson_array * | array | ) |
Adds an unnamed empty object value to the provided array.
array | A pointer to the array to add the property to. |
KAPI b8 kson_array_value_add_string | ( | kson_array * | array, |
const char * | value | ||
) |
Adds an unnamed string value to the provided array.
array | A pointer to the array to add the property to. |
value | The value to be set. Required. Must not be null. |
KAPI b8 kson_array_value_add_vec2 | ( | kson_array * | array, |
vec2 | value | ||
) |
Adds an unnamed vec2 value to the provided array.
array | A pointer to the array to add the property to. |
value | The value to be set. |
KAPI b8 kson_array_value_add_vec3 | ( | kson_array * | array, |
vec3 | value | ||
) |
Adds an unnamed vec3 value to the provided array.
array | A pointer to the array to add the property to. |
value | The value to be set. |
KAPI b8 kson_array_value_add_vec4 | ( | kson_array * | array, |
vec4 | value | ||
) |
Adds an unnamed vec4 value to the provided array.
array | A pointer to the array to add the property to. |
value | The value to be set. |
KAPI void kson_object_cleanup | ( | kson_object * | obj | ) |
Cleans up the given kson object and its properties recursively.
obj | A pointer to the object to be cleaned up. Required. |
KAPI kson_object kson_object_create | ( | void | ) |
Creates and returns a new kson object.
KAPI b8 kson_object_property_count_get | ( | const kson_object * | object, |
u32 * | out_count | ||
) |
Obtains the count of properties of the given object.
object | The object to retrieve the property count of. |
out_count | A pointer to hold the object property count, |
KAPI kson_property kson_object_property_create | ( | const char * | name | ) |
Creates and returns a new property of the object type.
name | The name of the property. Pass 0 if later adding to an array. |
KAPI b8 kson_object_property_type_get | ( | const kson_object * | object, |
const char * | name, | ||
kson_property_type * | out_type | ||
) |
Obtains the type of the property with the given name. Fails if the name is not found.
object | The object to retrieve the type from. |
name | The name of the property to retrieve. |
out_type | A pointer to hold the object property type, |
KAPI b8 kson_object_property_value_get_array | ( | const kson_object * | object, |
const char * | name, | ||
kson_array * | out_value | ||
) |
Attempts to retrieve the a copy given object's property value by name as an array. Fails if not found or on type mismatch.
object | A constant pointer to the object to search. Required. |
name | The property name to search for. Required. |
out_value | A pointer to hold a copy of the object property's value. |
KAPI b8 kson_object_property_value_get_bool | ( | const kson_object * | object, |
const char * | name, | ||
b8 * | out_value | ||
) |
Attempts to retrieve the given object's property value by name as a boolean. Fails if not found or on type mismatch.
object | A constant pointer to the object to search. Required. |
name | The property name to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_object_property_value_get_float | ( | const kson_object * | object, |
const char * | name, | ||
f32 * | out_value | ||
) |
Attempts to retrieve the given object's property value by name as a floating-point number. Fails if not found or on type mismatch.
object | A constant pointer to the object to search. Required. |
name | The property name to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_object_property_value_get_int | ( | const kson_object * | object, |
const char * | name, | ||
i64 * | out_value | ||
) |
Attempts to retrieve the given object's property value by name as a signed integer. Fails if not found or on type mismatch.
object | A constant pointer to the object to search. Required. |
name | The property name to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_object_property_value_get_mat4 | ( | const kson_object * | object, |
const char * | name, | ||
mat4 * | out_value | ||
) |
Attempts to retrieve the given object's property value by name as a mat4. Fails if not found or on type mismatch (these are always stored as strings).
object | A constant pointer to the object to search. Required. |
name | The property name to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_object_property_value_get_object | ( | const kson_object * | object, |
const char * | name, | ||
kson_object * | out_value | ||
) |
Attempts to retrieve the a copy given object's property value by name as an object. Fails if not found or on type mismatch.
object | A constant pointer to the object to search. Required. |
name | The property name to search for. Required. |
out_value | A pointer to hold a copy of the object property's value. |
KAPI b8 kson_object_property_value_get_string | ( | const kson_object * | object, |
const char * | name, | ||
const char ** | out_value | ||
) |
Attempts to retrieve the given object's property value by name as a string. Fails if not found or on type mismatch. NOTE: This function always allocates new memory, so the string should be released afterward.
object | A constant pointer to the object to search. Required. |
name | The property name to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_object_property_value_get_string_as_kname | ( | const kson_object * | object, |
const char * | name, | ||
kname * | out_value | ||
) |
Attempts to retrieve the given object's property value by name as a kname. Fails if not found or on type mismatch. knames are always stored as thier original text format.
object | A constant pointer to the object to search. Required. |
name | The property name to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_object_property_value_get_string_as_kstring_id | ( | const kson_object * | object, |
const char * | name, | ||
kstring_id * | out_value | ||
) |
Attempts to retrieve the given object's property value by name as a kstring_id. Fails if not found or on type mismatch. kstring_ids are always stored as thier original text format.
object | A constant pointer to the object to search. Required. |
name | The property name to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_object_property_value_get_vec2 | ( | const kson_object * | object, |
const char * | name, | ||
vec2 * | out_value | ||
) |
Attempts to retrieve the given object's property value by name as a vec2. Fails if not found or on type mismatch (these are always stored as strings).
object | A constant pointer to the object to search. Required. |
name | The property name to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_object_property_value_get_vec3 | ( | const kson_object * | object, |
const char * | name, | ||
vec3 * | out_value | ||
) |
Attempts to retrieve the given object's property value by name as a vec3. Fails if not found or on type mismatch (these are always stored as strings).
object | A constant pointer to the object to search. Required. |
name | The property name to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_object_property_value_get_vec4 | ( | const kson_object * | object, |
const char * | name, | ||
vec4 * | out_value | ||
) |
Attempts to retrieve the given object's property value by name as a vec4. Fails if not found or on type mismatch (these are always stored as strings).
object | A constant pointer to the object to search. Required. |
name | The property name to search for. Required. |
out_value | A pointer to hold the object property's value. |
KAPI b8 kson_object_property_value_type_get | ( | const kson_object * | object, |
const char * | name, | ||
kson_property_type * | out_type | ||
) |
Attempts to retrieve the given object's property value type by name. Fails if not found.
object | A constant pointer to the object to search. Required. |
name | The property name to search for. Required. |
out_type | A pointer to hold the object property's type. |
KAPI b8 kson_object_value_add_array | ( | kson_object * | object, |
const char * | name, | ||
kson_array | value | ||
) |
Adds a named array value to the provided object.
object | A pointer to the object to add the property to. |
name | A constant pointer to the name to be used. Required. |
value | The value to be set. |
KAPI b8 kson_object_value_add_array_empty | ( | kson_object * | object, |
const char * | name | ||
) |
Adds a named empty array value to the provided object.
object | A pointer to the object to add the property to. |
name | A constant pointer to the name to be used. Required. |
KAPI b8 kson_object_value_add_boolean | ( | kson_object * | object, |
const char * | name, | ||
b8 | value | ||
) |
Adds a named boolean value to the provided object.
object | A pointer to the object to add the property to. |
name | A constant pointer to the name to be used. Required. |
value | The value to be set. |
KAPI b8 kson_object_value_add_float | ( | kson_object * | object, |
const char * | name, | ||
f32 | value | ||
) |
Adds a named floating-point value to the provided object.
object | A pointer to the object to add the property to. |
name | A constant pointer to the name to be used. Required. |
value | The value to be set. |
KAPI b8 kson_object_value_add_int | ( | kson_object * | object, |
const char * | name, | ||
i64 | value | ||
) |
Adds a named signed 64-bit integer value to the provided object.
object | A pointer to the object to add the property to. |
name | A constant pointer to the name to be used. Required. |
value | The value to be set. |
KAPI b8 kson_object_value_add_kname_as_string | ( | kson_object * | object, |
const char * | name, | ||
kname | value | ||
) |
Adds a named kname value as a string to the provided object.
object | A pointer to the object to add the property to. |
name | A constant pointer to the name to be used. Required. |
value | The value to be set. |
KAPI b8 kson_object_value_add_kstring_id_as_string | ( | kson_object * | object, |
const char * | name, | ||
kstring_id | value | ||
) |
Adds a named kstring_id value as a string to the provided object.
object | A pointer to the object to add the property to. |
name | A constant pointer to the name to be used. Required. |
value | The value to be set. |
KAPI b8 kson_object_value_add_mat4 | ( | kson_object * | object, |
const char * | name, | ||
mat4 | value | ||
) |
Adds a named mat4 value to the provided object.
object | A pointer to the object to add the property to. |
name | A constant pointer to the name to be used. Required. |
value | The value to be set. |
KAPI b8 kson_object_value_add_object | ( | kson_object * | object, |
const char * | name, | ||
kson_object | value | ||
) |
Adds a named object value to the provided object.
object | A pointer to the object to add the property to. |
name | A constant pointer to the name to be used. Required. |
value | The value to be set. |
KAPI b8 kson_object_value_add_object_empty | ( | kson_object * | object, |
const char * | name | ||
) |
Adds a named empty object value to the provided object.
object | A pointer to the object to add the property to. |
name | A constant pointer to the name to be used. Required. |
KAPI b8 kson_object_value_add_string | ( | kson_object * | object, |
const char * | name, | ||
const char * | value | ||
) |
Adds a named string value to the provided object.
object | A pointer to the object to add the property to. |
name | A constant pointer to the name to be used. Required. |
value | The value to be set. Required. Must not be null. |
KAPI b8 kson_object_value_add_vec2 | ( | kson_object * | object, |
const char * | name, | ||
vec2 | value | ||
) |
Adds a named vec2 value to the provided object.
object | A pointer to the object to add the property to. |
name | A constant pointer to the name to be used. Required. |
value | The value to be set. |
KAPI b8 kson_object_value_add_vec3 | ( | kson_object * | object, |
const char * | name, | ||
vec3 | value | ||
) |
Adds a named vec3 value to the provided object.
object | A pointer to the object to add the property to. |
name | A constant pointer to the name to be used. Required. |
value | The value to be set. |
KAPI b8 kson_object_value_add_vec4 | ( | kson_object * | object, |
const char * | name, | ||
vec4 | value | ||
) |
Adds a named vec4 value to the provided object.
object | A pointer to the object to add the property to. |
name | A constant pointer to the name to be used. Required. |
value | The value to be set. |
KAPI b8 kson_parser_create | ( | kson_parser * | out_parser | ) |
Creates a kson parser. Note that it is generally recommended to use the kson_tree_from_string() and kson_tree_to_string() functions instead of invoking this manually, as these also handle cleanup of the parser object.
out_parser | A pointer to hold the newly-created parser. |
KAPI void kson_parser_destroy | ( | kson_parser * | parser | ) |
Destroys the provided parser.
parser | A pointer to the parser to be destroyed. |
KAPI b8 kson_parser_parse | ( | kson_parser * | parser, |
kson_tree * | out_tree | ||
) |
Uses the given parser to build a kson_tree using the tokens previously parsed. This means that kson_parser_tokenize() must have been called and completed successfully for this function to work. It is recommended to use kson_tree_from_string() instead.
parser | A pointer to the parser to use. Required. Must be a valid parser that has already had kson_parser_tokenize() called against it successfully. |
out_tree | A pointer to hold the generated kson_tree. Required. |
KAPI b8 kson_parser_tokenize | ( | kson_parser * | parser, |
const char * | source | ||
) |
Uses the given parser to tokenize the provided source string. Note that it is recommended to use the kson_tree_from_string() function instead.
parser | A pointer to the parser to use. Required. Must be a valid parser. |
source | A constant pointer to the source string to tokenize. |
KAPI const char* kson_property_type_to_string | ( | kson_property_type | type | ) |
Gets the given property type as a constant string. NOTE: Caller should NOT attempt to free this string.
type | The KSON property type. |
Performs cleanup operations on the given tree, freeing memory and resources held by it.
tree | A pointer to the tree to cleanup. Required. |
Takes the provided source and tokenizes, then parses it in order to create a tree of kson_objects.
source | A pointer to the source string to be tokenized and parsed. Required. |
out_tree | A pointer to hold the generated kson_tree. Required. |