inkcpp
Loading...
Searching...
No Matches
Clib Interface

C bindings for inkcpp More...

Classes

struct  InkListIter
 Iterater used to iterate flags of a HInkList. More...
 
struct  InkValue
 Repserentation of a ink variable. More...
 
class  HInkSnapshot
 Handler for a ink snapshot. More...
 
class  HInkChoice
 Handler for a ink choice. More...
 
class  HInkList
 Handler for a ink list. More...
 
class  HInkRunner
 A handle for an ink runner. More...
 
class  HInkGlobals
 Handle for the global variable store shared among ink runners. More...
 
class  HInkStory
 Handle for a loaded ink story. More...
 

Functions

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.
 

Detailed Description

C bindings for inkcpp

There are two different ways to get the C bindings.

  1. Use the distributed <os>-lib.zip for a C++ and C lib combined, then use CMake for the linkadge (or do it manually)
  2. Use the distrubuted <os>-clib.zip for a C only lib, then use CMake, or pkg-config.

Please note that the included header is different between this two installation methods.

  1. #include <ink/c/inkcpp.h>
  2. #include <ink/inkcpp.h>

Example

To setup an example for option 1. and 2. if you use cmake checkout CMAKE usage and replace target_link_libraries with target_link_libraries(main inkcpp_c) The story and source file can be used as noted down

For setup an example for option 2. without cmake create a directory with the files below:

And extract <os>-clib.zip from the release page to /MY/INKCPP/EXAMPLE_INSTALL/PATH.
To run the example do the following:

As a sideproduct a file named test.bin should be created coaining the binary format used by inkCPP.

main.c

#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <ink/c/inkcpp.h> // if <os>-lib.zip was used for the installation
// #include <ink/inkcpp.h> // if <os>-clib.zip was used for the installation
InkValue ink_add(int argc, const InkValue argv[])
{
assert(argc == 2);
assert(argv[0].type == ValueTypeInt32 && argv[1].type == ValueTypeInt32);
return (InkValue){.type = ValueTypeInt32, .int32_v = argv[0].int32_v + argv[1].int32_v};
}
int main()
{
ink_compile_json("test.ink.json", "test.bin", NULL);
HInkStory* story = ink_story_from_file("test.bin");
HInkRunner* runner = ink_story_new_runner(story, NULL);
ink_runner_bind(runner, "my_ink_function", ink_add, 1);
while (1) {
while (ink_runner_can_continue(runner)) {
printf("%s", ink_runner_get_line(runner));
}
if (ink_runner_num_choices(runner) == 0)
break;
for (int i = 0; i < ink_runner_num_choices(runner); ++i) {
printf("%i. %s\n", i, ink_choice_text(ink_runner_get_choice(runner, i)));
}
int id;
scanf("%i", &id);
ink_runner_choose(runner, id);
}
}
A handle for an ink runner.
Handle for a loaded ink story.
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.
story_ptr< runner_interface > runner
alias for an managed ink::runtime::runner_interface pointer
Definition types.h:22
Repserentation of a ink variable.
Definition inkcpp.h:167
int32_t int32_v
contains value if type == ValueTypeInt32
Definition inkcpp.h:172

Function Documentation

◆ ink_compile_json()

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.

Parameters
input_filenamepath to file contaning input data (.ink.json)
output_filenamepath to file output data will be written (.bin)
errorif not NULL will contain a error message if an error occures (else will be set to NULL)