Sha256: 26e6ccda9529b6544b2c1955a2a25faf5839ab936bf930805e318cbbc031d257

Contents?: true

Size: 886 Bytes

Versions: 4

Compression:

Stored size: 886 Bytes

Contents

#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>

#include <inkcpp.h>

#undef NDEBUG
#include <assert.h>

int cnt = 0;

void observer(InkValue new_value, InkValue old_value)
{
	if (cnt++ == 0) {
		assert(new_value.type == ValueTypeInt32 && new_value.int32_v == 1);
		assert(old_value.type == ValueTypeNone);
	} else {
		assert(new_value.type == ValueTypeInt32 && new_value.int32_v == 5);
		assert(old_value.type == ValueTypeInt32 && old_value.int32_v == 1);
	}
}

int main()
{
	HInkStory*   story  = ink_story_from_file(INK_TEST_RESOURCE_DIR "ObserverStory.bin");
	HInkGlobals* store  = ink_story_new_globals(story);
	HInkRunner*  thread = ink_story_new_runner(story, store);

	ink_globals_observe(store, "var1", observer);

	assert(strcmp(ink_runner_get_line(thread), "hello line 1 1 hello line 2 5 test line 3 5\n") == 0);
	assert(cnt == 2);

	return 0;
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
inkcpp_rb-0.1.3 ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Observer.c
inkcpp_rb-0.1.2 ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Observer.c
inkcpp_rb-0.1.1 ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Observer.c
inkcpp_rb-0.1.0 ext/inkcpp_rb/inkcpp/inkcpp_c/tests/Observer.c