inkcpp
Loading...
Searching...
No Matches
inkcpp.h
1#ifndef _INKCPP_H
2#define _INKCPP_H
3
4#include <stdbool.h>
5#include <stdint.h>
6#include <stdlib.h>
7#include <stddef.h>
8
9#ifdef __cplusplus
10extern "C" {
11#else
12typedef struct HInkSnapshot HInkSnapshot;
13typedef struct HInkChoice HInkChoice;
14typedef struct HInkList HInkList;
15typedef struct InkListIter InkListIter;
16typedef struct InkFlag InkFlag;
17typedef struct InkValue InkValue;
18typedef struct HInkRunner HInkRunner;
19typedef struct HInkGlobals HInkGlobals;
20typedef struct HInkSTory HInkStory;
21#endif
22 typedef uint32_t ink_hash_t;
23
69 struct HInkSnapshot;
75 HInkSnapshot* ink_snapshot_from_file(const char* filename);
80 ink_snapshot_from_binary(const unsigned char* data, size_t length, bool freeOnDestroy);
92 void ink_snapshot_write_to_file(const HInkSnapshot* self, const char* filename);
99 const HInkSnapshot* self, const unsigned char** data, size_t* data_length
100 );
107
113 struct HInkChoice;
118 const char* ink_choice_text(const HInkChoice* self);
128 const char* ink_choice_get_tag(const HInkChoice* self, int index);
129
134 struct HInkList;
135
152 struct InkListIter {
153 const void* _data;
154 int _i;
155 int _single_list;
156 const char* flag_name;
157 const char* list_name;
158 };
159
160 void ink_list_add(HInkList* self, const char* flag_name);
161 void ink_list_remove(HInkList* self, const char* flag_name);
162 int ink_list_contains(const HInkList* self, const char* flag_name);
169 int ink_list_flags(const HInkList* self, InkListIter* iter);
179 int ink_list_flags_from(const HInkList* self, const char* list_name, InkListIter* iter);
186
220
221 // const char* ink_value_to_string(const InkValue* self);
222
228 typedef InkValue (*InkExternalFunction)(int argc, const InkValue argv[]);
235 typedef void (*InkExternalFunctionVoid)(int argc, const InkValue argv[]);
236
242 struct HInkRunner;
260 const char* ink_runner_get_line(HInkRunner* self);
269 const char* ink_runner_tag(const HInkRunner* self, int index);
279 ink_hash_t ink_runner_current_knot(const HInkRunner* self);
285 bool ink_runner_move_to(HInkRunner* self, ink_hash_t path);
292 ink_hash_t ink_hash_string(const char* str);
297 const char* ink_runner_knot_tag(const HInkRunner* self, int index);
307 const char* ink_runner_global_tag(const HInkRunner* self, int index);
317 const HInkChoice* ink_runner_get_choice(const HInkRunner* self, int index);
322 void ink_runner_choose(HInkRunner* self, int index);
323
335 HInkRunner* self, const char* function_name, InkExternalFunctionVoid callback,
336 int lookaheadSafe
337 );
349 HInkRunner* self, const char* function_name, InkExternalFunction callback, int lookaheadSafe
350 );
351
352
359 struct HInkGlobals;
365 typedef void (*InkObserver)(InkValue new_value, InkValue old_value);
382 void ink_globals_observe(HInkGlobals* self, const char* variable_name, InkObserver observer);
389 InkValue ink_globals_get(const HInkGlobals* self, const char* variable_name);
398 int ink_globals_set(HInkGlobals* self, const char* variable_name, InkValue value);
399
407 struct HInkStory;
413 HInkStory* ink_story_from_file(const char* filename);
417 HInkStory* ink_story_from_binary(const unsigned char* data, size_t length, bool freeOnDestroy);
445 HInkStory* self, const HInkSnapshot* obj, HInkGlobals* store, int runner_id
446 );
447
456 void
457 ink_compile_json(const char* input_filename, const char* output_filename, const char** error);
458
459
460#ifdef __cplusplus
461}
462#endif
463
464#endif
Handler for a ink choice.
int ink_choice_num_tags(const HInkChoice *self)
number of tags associated with this choice
const char * ink_choice_get_tag(const HInkChoice *self, int index)
Access a tag by index.
const char * ink_choice_text(const HInkChoice *self)
Choice text.
Handle for the global variable store shared among ink runners.
int ink_globals_set(HInkGlobals *self, const char *variable_name, InkValue value)
Sets the value of a globals variable.
void(* InkObserver)(InkValue new_value, InkValue old_value)
Definition inkcpp.h:365
void ink_globals_observe(HInkGlobals *self, const char *variable_name, InkObserver observer)
assignes a observer to the variable with the corresponding name.
void ink_globals_delete(HInkGlobals *self)
Deconstructs the globals store and frees all assoziated memories.
HInkSnapshot * ink_globals_create_snapshot(const HInkGlobals *self)
Creates a snapshot for later reloading.
InkValue ink_globals_get(const HInkGlobals *self, const char *variable_name)
Gets the value of a global variable.
Handler for a ink list.
int ink_list_flags_from(const HInkList *self, const char *list_name, InkListIter *iter)
Creates an Iterator over all flags contained in a list assziated with a defined list.
int ink_list_flags(const HInkList *self, InkListIter *iter)
Creates an Iterator over all flags contained in a list.
A handle for an ink runner.
const HInkChoice * ink_runner_get_choice(const HInkRunner *self, int index)
Gets a choice.
void ink_runner_bind(HInkRunner *self, const char *function_name, InkExternalFunction callback, int lookaheadSafe)
Binds a external function which is called from the runtime, with a return vallue.
HInkSnapshot * ink_runner_create_snapshot(const HInkRunner *self)
Creates a snapshot, for later reloading.
InkValue(* InkExternalFunction)(int argc, const InkValue argv[])
Callback for a Ink external function which returns void.
Definition inkcpp.h:228
int ink_runner_num_tags(const HInkRunner *self)
Returns the number of tags on the current line.
const char * ink_runner_tag(const HInkRunner *self, int index)
Access a tag by index.
const char * ink_runner_knot_tag(const HInkRunner *self, int index)
void ink_runner_bind_void(HInkRunner *self, const char *function_name, InkExternalFunctionVoid callback, int lookaheadSafe)
Binds a external function which is called form the runtime, with no return value.
void ink_runner_choose(HInkRunner *self, int index)
Make a choice.
const char * ink_runner_get_line(HInkRunner *self)
Continue execution until the next newline, then allocate a c-style string with the output.
int ink_runner_num_knot_tags(const HInkRunner *self)
Get Number of knot/stitch tags.
ink_hash_t ink_runner_current_knot(const HInkRunner *self)
Get hash of current knot/stitch name.
bool ink_runner_move_to(HInkRunner *self, ink_hash_t path)
Moves the runner to the specified path.
int ink_runner_num_choices(const HInkRunner *self)
Returns the number of choices currently available.
void(* InkExternalFunctionVoid)(int argc, const InkValue argv[])
Callback for a Ink external function wihich returns a value.
Definition inkcpp.h:235
int ink_runner_num_global_tags(const HInkRunner *self)
Get Number of global tags.
int ink_runner_can_continue(const HInkRunner *self)
Can the runner continue?
const char * ink_runner_global_tag(const HInkRunner *self, int index)
void ink_runner_delete(HInkRunner *self)
Deconstructs the Runner and all frees assoziated resources.
Handler for a ink snapshot.
HInkSnapshot * ink_snapshot_from_binary(const unsigned char *data, size_t length, bool freeOnDestroy)
Construct snapshot from blob.
int ink_snapshot_num_runners(const HInkSnapshot *self)
number of runners which are stored inside this snapshot
HInkSnapshot * ink_snapshot_from_file(const char *filename)
deserialize snapshot from file.
void ink_snapshot_write_to_file(const HInkSnapshot *self, const char *filename)
serialize snapshot to file
bool ink_snapshot_can_be_migrated(const HInkSnapshot *self)
if this snapshot can be migrated, if the story file changes (slightly).
void ink_snapshot_get_binary(const HInkSnapshot *self, const unsigned char **data, size_t *data_length)
Handle for a loaded ink story.
HInkGlobals * ink_story_new_globals_from_snapshot(HInkStory *self, const HInkSnapshot *obj)
Reconstructs globals from snapshot.
void ink_story_delete(HInkStory *self)
deletes a story and all assoziated resources
HInkStory * ink_story_from_binary(const unsigned char *data, size_t length, bool freeOnDestroy)
Create a new story object from binary buffer.
HInkRunner * ink_story_new_runner(HInkStory *self, HInkGlobals *store)
Creates a new runner.
HInkGlobals * ink_story_new_globals(HInkStory *self)
Creates a new global store.
HInkStory * ink_story_from_file(const char *filename)
Creates a new story object from a file.
HInkRunner * ink_story_new_runner_from_snapshot(HInkStory *self, const HInkSnapshot *obj, HInkGlobals *store, int runner_id)
reconstruct runner from a snapshot
void ink_compile_json(const char *input_filename, const char *output_filename, const char **error)
Compiles a .ink.json file to an inkCPP .bin file.
ink_hash_t ink_hash_string(const char *str)
Hash a string, this hash is used inside inkcpp instead of the string actual value.
unsigned int uint32_t
define basic numeric type
Definition system.h:58
Iterater used to iterate flags of a HInkList.
Definition inkcpp.h:152
const char * list_name
name of the list the flag corresponds to
Definition inkcpp.h:157
int ink_list_iter_next(InkListIter *self)
const char * flag_name
Name of the current flag.
Definition inkcpp.h:156
Repserentation of a ink variable.
Definition inkcpp.h:194
int32_t int32_v
contains value if type == ValueTypeInt32
Definition inkcpp.h:199
const char * string_v
contains value if type == ValueTypeString
Definition inkcpp.h:201
enum InkValue::Type type
indicates type contained in value
Type
indicates which type is contained in the value
Definition inkcpp.h:210
@ ValueTypeString
a string
Definition inkcpp.h:215
@ ValueTypeNone
the Value does not contain any value
Definition inkcpp.h:211
@ ValueTypeList
a ink list
Definition inkcpp.h:217
@ ValueTypeFloat
a floating point number
Definition inkcpp.h:216
@ ValueTypeBool
a boolean
Definition inkcpp.h:212
@ ValueTypeInt32
a signed integer
Definition inkcpp.h:214
@ ValueTypeUint32
a unsigned integer
Definition inkcpp.h:213
int bool_v
contains value if type == ValueTypeBool
Definition inkcpp.h:196
float float_v
contains value if type == ValueTypeFloat
Definition inkcpp.h:203
HInkList * list_v
contains value if type == ValueTypeList
Definition inkcpp.h:206
uint32_t uint32_v
contains value if type == ValueTypeUint32
Definition inkcpp.h:197