Files
wren/test/api/returns.c
Bob Nystrom 01e8f9053e Add a benchmark to test the Wren C API.
I've got some ideas on how to tweak the embedding API, but I want to
see what performance impact they have first, so this adds a little
benchmark that just calls a foreign method a ton of times.
2015-12-15 16:02:13 -08:00

52 lines
1.2 KiB
C

#include <string.h>
#include "returns.h"
static void implicitNull(WrenVM* vm)
{
// Do nothing.
}
static void returnInt(WrenVM* vm)
{
wrenReturnDouble(vm, 123456);
}
static void returnFloat(WrenVM* vm)
{
wrenReturnDouble(vm, 123.456);
}
static void returnTrue(WrenVM* vm)
{
wrenReturnBool(vm, true);
}
static void returnFalse(WrenVM* vm)
{
wrenReturnBool(vm, false);
}
static void returnString(WrenVM* vm)
{
wrenReturnString(vm, "a string", -1);
}
static void returnBytes(WrenVM* vm)
{
wrenReturnString(vm, "a\0b\0c", 5);
}
WrenForeignMethodFn returnsBindMethod(const char* signature)
{
if (strcmp(signature, "static Returns.implicitNull") == 0) return implicitNull;
if (strcmp(signature, "static Returns.returnInt") == 0) return returnInt;
if (strcmp(signature, "static Returns.returnFloat") == 0) return returnFloat;
if (strcmp(signature, "static Returns.returnTrue") == 0) return returnTrue;
if (strcmp(signature, "static Returns.returnFalse") == 0) return returnFalse;
if (strcmp(signature, "static Returns.returnString") == 0) return returnString;
if (strcmp(signature, "static Returns.returnBytes") == 0) return returnBytes;
return NULL;
}