-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathExternalFunction.c
More file actions
59 lines (49 loc) · 1.4 KB
/
ExternalFunction.c
File metadata and controls
59 lines (49 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <inkcpp.h>
#undef NDEBUG
#include <assert.h>
int cnt_my_sqrt = 0;
InkValue my_sqrt(int argc, const InkValue argv[])
{
cnt_my_sqrt += 1;
assert(argc == 1);
InkValue v = argv[0];
switch (v.type) {
case ValueTypeFloat: v.float_v = sqrtf(v.float_v); break;
case ValueTypeInt32: v.int32_v = ( int32_t ) sqrt(v.int32_v); break;
case ValueTypeUint32: v.uint32_v = ( uint32_t ) sqrt(v.uint32_v); break;
default: assert(0);
}
return v;
}
int cnt_greeting = 0;
InkValue greeting(int argc, const InkValue* argv)
{
( void ) argv;
cnt_greeting += 1;
assert(argc == 0);
InkValue v;
v.type = ValueTypeString;
v.string_v = "Hohooh";
return v;
}
int main(int argc, const char* argv[])
{
( void ) argc;
( void ) argv;
HInkStory* story = ink_story_from_file(INK_TEST_RESOURCE_DIR "FallBack.bin");
HInkRunner* runner = ink_story_new_runner(story, NULL);
ink_runner_bind(runner, "greeting", greeting, 0);
ink_runner_bind(runner, "sqrt", my_sqrt, 0);
const char* res = ink_runner_get_line(runner);
assert(strcmp(res, "Hohooh ! A small demonstration of my power:\n") == 0);
assert(ink_runner_can_continue(runner));
assert(strcmp(ink_runner_get_line(runner), "Math 4 * 4 = 16, stunning i would say\n") == 0);
assert(ink_runner_can_continue(runner) == 0);
assert(cnt_my_sqrt == 2);
assert(cnt_greeting == 1);
return 0;
}