Crates.io | bink-ffi |
lib.rs | bink-ffi |
version | 0.2.0 |
source | src |
created_at | 2023-10-13 11:01:49.443014 |
updated_at | 2023-10-13 11:01:49.443014 |
description | C bindings for the Blade Ink Rust library. |
homepage | |
repository | https://github.com/bladecoder/blade-ink-ffi.git |
max_upload_size | |
id | 1002219 |
size | 395,231 |
A wrapper library providing a C FFI for Blade Ink. Now you can call Blade Ink Rust library from C!
Here we have an example of use extracted from the test that can be found in tests/binc_test.c
:
int main(void) {
uint32_t ret = BINK_OK;
BINK_Story *story = NULL;
BINK_Choices *choices = NULL;
char *err_msg = NULL;
char *line = NULL;
char *json_string = read_json_file("./inkfiles/TheIntercept.ink.json");
if(json_string == NULL)
exit(EXIT_FAILURE);
ret = bink_story_new(&story, json_string, &err_msg);
check_ret(ret, story, err_msg);
free(json_string);
bool end = false;
while(!end) {
bool can_continue;
ret = bink_story_can_continue(story, &can_continue);
check_ret(ret, story, err_msg);
while (can_continue) {
ret = bink_story_cont(story, &line, &err_msg);
check_ret(ret, story, err_msg);
puts(line);
bink_cstring_free(line);
ret = bink_story_can_continue(story, &can_continue);
check_ret(ret, story, err_msg);
}
// Obtain and print choices
size_t len = 0;
ret = bink_story_get_current_choices(story, &choices, &len);
check_ret(ret, story, NULL);
//printf("Num. choices: %lu\n", len);
if (len !=0) {
print_choices(choices, len);
printf("\n");
bink_choices_free(choices);
// Always choose the first option
ret = bink_story_choose_choice_index(story, 0);
check_ret(ret, story, NULL);
} else {
end = true;
}
}
printf("Story ended ok.\n");
finish(EXIT_SUCCESS, story, err_msg);
}
For more examples, check the tests
folder in this repository.
Check the Blade Ink library source code for more info.
Compiled packages for the more common platforms containing the library for static and dynamic linking can be downloaded in the Releases section.
If there is no version of the library compiled for the platform you need, you can compile it by yourself:
$ rustup target add <your_platform_name>
$ cargo build --target <your_platform_name>
We can execute the C tests in the tests
folder using the tests/Makefile
file. From the project root folder, execute:
$ make -f tests/Makefile test
By now, tests can only be executed on Linux or Macos and you need to have installed a C tool chain.