Clean up and improve docs in embedder API. Fix #133.

This commit is contained in:
Bob Nystrom
2015-01-22 07:05:55 -08:00
parent 8ce58ec3c4
commit 2cee4c83bd
2 changed files with 46 additions and 35 deletions
+8 -12
View File
@@ -1193,7 +1193,8 @@ bool wrenGetArgumentBool(WrenVM* vm, int index)
ASSERT(index >= 0, "index cannot be negative.");
ASSERT(index < vm->foreignCallNumArgs, "Not that many arguments.");
// TODO: Check actual value type first.
if (!IS_BOOL(*(vm->foreignCallSlot + index))) return false;
return AS_BOOL(*(vm->foreignCallSlot + index));
}
@@ -1203,7 +1204,8 @@ double wrenGetArgumentDouble(WrenVM* vm, int index)
ASSERT(index >= 0, "index cannot be negative.");
ASSERT(index < vm->foreignCallNumArgs, "Not that many arguments.");
// TODO: Check actual value type first.
if (!IS_NUM(*(vm->foreignCallSlot + index))) return 0.0;
return AS_NUM(*(vm->foreignCallSlot + index));
}
@@ -1213,7 +1215,8 @@ const char* wrenGetArgumentString(WrenVM* vm, int index)
ASSERT(index >= 0, "index cannot be negative.");
ASSERT(index < vm->foreignCallNumArgs, "Not that many arguments.");
// TODO: Check actual value type first.
if (!IS_STRING(*(vm->foreignCallSlot + index))) return NULL;
return AS_CSTRING(*(vm->foreignCallSlot + index));
}
@@ -1233,18 +1236,11 @@ void wrenReturnDouble(WrenVM* vm, double value)
vm->foreignCallSlot = NULL;
}
void wrenReturnNull(WrenVM* vm)
{
ASSERT(vm->foreignCallSlot != NULL, "Must be in foreign call.");
*vm->foreignCallSlot = NULL_VAL;
vm->foreignCallSlot = NULL;
}
void wrenReturnString(WrenVM* vm, const char* text, int length)
{
ASSERT(vm->foreignCallSlot != NULL, "Must be in foreign call.");
ASSERT(text != NULL, "String cannot be NULL.");
size_t size = length;
if (length == -1) size = strlen(text);