2017-03-22 07:26:19 -07:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "user_data.h"
|
|
|
|
|
|
|
|
|
|
static const char* data = "my user data";
|
|
|
|
|
static const char* otherData = "other user data";
|
|
|
|
|
|
|
|
|
|
static void test(WrenVM* vm)
|
|
|
|
|
{
|
|
|
|
|
WrenConfiguration configuration;
|
|
|
|
|
wrenInitConfiguration(&configuration);
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2017-03-22 07:26:19 -07:00
|
|
|
// Should default to NULL.
|
|
|
|
|
if (configuration.userData != NULL)
|
|
|
|
|
{
|
|
|
|
|
wrenSetSlotBool(vm, 0, false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2017-03-22 07:26:19 -07:00
|
|
|
configuration.userData = (void*)data;
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2017-03-22 07:26:19 -07:00
|
|
|
WrenVM* otherVM = wrenNewVM(&configuration);
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2017-03-22 07:26:19 -07:00
|
|
|
// Should be able to get it.
|
|
|
|
|
if (wrenGetUserData(otherVM) != data)
|
|
|
|
|
{
|
|
|
|
|
wrenSetSlotBool(vm, 0, false);
|
|
|
|
|
wrenFreeVM(otherVM);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2017-03-22 07:26:19 -07:00
|
|
|
// Should be able to set it.
|
|
|
|
|
wrenSetUserData(otherVM, (void*)otherData);
|
2020-06-05 14:57:20 -07:00
|
|
|
|
2017-03-22 07:26:19 -07:00
|
|
|
if (wrenGetUserData(otherVM) != otherData)
|
|
|
|
|
{
|
|
|
|
|
wrenSetSlotBool(vm, 0, false);
|
|
|
|
|
wrenFreeVM(otherVM);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wrenSetSlotBool(vm, 0, true);
|
|
|
|
|
wrenFreeVM(otherVM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WrenForeignMethodFn userDataBindMethod(const char* signature)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp(signature, "static UserData.test") == 0) return test;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|