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
8#ifdef __cplusplus
9extern "C" {
10#else
11typedef struct HInkSnapshot HInkSnapshot;
12typedef struct HInkChoice HInkChoice;
13typedef struct HInkList HInkList;
14typedef struct InkListIter InkListIter;
15typedef struct InkFlag InkFlag;
16typedef struct InkValue InkValue;
17typedef struct HInkRunner HInkRunner;
18typedef struct HInkGlobals HInkGlobals;
19typedef struct HInkSTory HInkStory;
20#endif
21 typedef uint32_t ink_hash_t;
22
68 struct HInkSnapshot;
74 HInkSnapshot* ink_snapshot_from_file(const char* filename);
79 ink_snapshot_from_binary(const unsigned char* data, size_t length, bool freeOnDestroy);
91 void ink_snapshot_write_to_file(const HInkSnapshot* self, const char* filename);
98 const HInkSnapshot* self, const unsigned char** data, size_t* data_length
99 );
100
106 struct HInkChoice;
111 const char* ink_choice_text(const HInkChoice* self);
121 const char* ink_choice_get_tag(const HInkChoice* self, int index);
122
127 struct HInkList;
128
145 struct InkListIter {
146 const void* _data;
147 int _i;
148 int _single_list;
149 const char* flag_name;
150 const char* list_name;
151 };
152
153 void ink_list_add(HInkList* self, const char* flag_name);
154 void ink_list_remove(HInkList* self, const char* flag_name);
155 int ink_list_contains(const HInkList* self, const char* flag_name);
162 int ink_list_flags(const HInkList* self, InkListIter* iter);
172 int ink_list_flags_from(const HInkList* self, const char* list_name, InkListIter* iter);
179
213
214 // const char* ink_value_to_string(const InkValue* self);
215
221 typedef InkValue (*InkExternalFunction)(int argc, const InkValue argv[]);
228 typedef void (*InkExternalFunctionVoid)(int argc, const InkValue argv[]);
229
235 struct HInkRunner;
253 const char* ink_runner_get_line(HInkRunner* self);
262 const char* ink_runner_tag(const HInkRunner* self, int index);
272 ink_hash_t ink_runner_current_knot(const HInkRunner* self);
278 bool ink_runner_move_to(HInkRunner* self, ink_hash_t path);
285 ink_hash_t ink_hash_string(const char* str);
290 const char* ink_runner_knot_tag(const HInkRunner* self, int index);
300 const char* ink_runner_global_tag(const HInkRunner* self, int index);
310 const HInkChoice* ink_runner_get_choice(const HInkRunner* self, int index);
315 void ink_runner_choose(HInkRunner* self, int index);
316
328 HInkRunner* self, const char* function_name, InkExternalFunctionVoid callback,
329 int lookaheadSafe
330 );
342 HInkRunner* self, const char* function_name, InkExternalFunction callback, int lookaheadSafe
343 );
344
345
352 struct HInkGlobals;
358 typedef void (*InkObserver)(InkValue new_value, InkValue old_value);
375 void ink_globals_observe(HInkGlobals* self, const char* variable_name, InkObserver observer);
382 InkValue ink_globals_get(const HInkGlobals* self, const char* variable_name);
391 int ink_globals_set(HInkGlobals* self, const char* variable_name, InkValue value);
392
400 struct HInkStory;
406 HInkStory* ink_story_from_file(const char* filename);
410 HInkStory* ink_story_from_binary(const unsigned char* data, size_t length, bool freeOnDestroy);
438 HInkStory* self, const HInkSnapshot* obj, HInkGlobals* store, int runner_id
439 );
440
449 void
450 ink_compile_json(const char* input_filename, const char* output_filename, const char** error);
451
452
453#ifdef __cplusplus
454}
455#endif
456
457#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:358
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:221
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:228
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
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:145
const char * list_name
name of the list the flag corresponds to
Definition inkcpp.h:150
int ink_list_iter_next(InkListIter *self)
const char * flag_name
Name of the current flag.
Definition inkcpp.h:149
Repserentation of a ink variable.
Definition inkcpp.h:187
int32_t int32_v
contains value if type == ValueTypeInt32
Definition inkcpp.h:192
const char * string_v
contains value if type == ValueTypeString
Definition inkcpp.h:194
enum InkValue::Type type
indicates type contained in value
Type
indicates which type is contained in the value
Definition inkcpp.h:203
@ ValueTypeString
a string
Definition inkcpp.h:208
@ ValueTypeNone
the Value does not contain any value
Definition inkcpp.h:204
@ ValueTypeList
a ink list
Definition inkcpp.h:210
@ ValueTypeFloat
a floating point number
Definition inkcpp.h:209
@ ValueTypeBool
a boolean
Definition inkcpp.h:205
@ ValueTypeInt32
a signed integer
Definition inkcpp.h:207
@ ValueTypeUint32
a unsigned integer
Definition inkcpp.h:206
int bool_v
contains value if type == ValueTypeBool
Definition inkcpp.h:189
float float_v
contains value if type == ValueTypeFloat
Definition inkcpp.h:196
HInkList * list_v
contains value if type == ValueTypeList
Definition inkcpp.h:199
uint32_t uint32_v
contains value if type == ValueTypeUint32
Definition inkcpp.h:190