Add support for retrieving list values from a slot

This PR adds support for retrieving list information from a slot. Rather
than take the whole list, two different methods are provided for
retrieving a) the length of the list, and b) a specific value in the
list.
This commit is contained in:
Damien Radtke
2016-05-19 13:26:01 -05:00
parent befe90501b
commit cf258b9074
5 changed files with 49 additions and 1 deletions

View File

@ -153,6 +153,19 @@ static void foreignClassAllocate(WrenVM* vm)
wrenSetSlotNewForeign(vm, 0, 0, 4);
}
static void getListSize(WrenVM* vm)
{
wrenSetSlotDouble(vm, 0, wrenGetSlotListSize(vm, 1));
}
static void getListValue(WrenVM* vm)
{
int index = (int)wrenGetSlotDouble(vm, 2);
WrenValue* value = wrenGetSlotListValue(vm, 1, index);
wrenSetSlotValue(vm, 0, value);
wrenReleaseValue(vm, value);
}
WrenForeignMethodFn slotsBindMethod(const char* signature)
{
if (strcmp(signature, "static Slots.noSet") == 0) return noSet;
@ -161,6 +174,8 @@ WrenForeignMethodFn slotsBindMethod(const char* signature)
if (strcmp(signature, "static Slots.slotTypes(_,_,_,_,_,_,_)") == 0) return slotTypes;
if (strcmp(signature, "static Slots.ensure()") == 0) return ensure;
if (strcmp(signature, "static Slots.ensureOutsideForeign()") == 0) return ensureOutsideForeign;
if (strcmp(signature, "static Slots.getListSize(_)") == 0) return getListSize;
if (strcmp(signature, "static Slots.getListValue(_,_)") == 0) return getListValue;
return NULL;
}
@ -168,4 +183,4 @@ WrenForeignMethodFn slotsBindMethod(const char* signature)
void slotsBindClass(const char* className, WrenForeignClassMethods* methods)
{
methods->allocate = foreignClassAllocate;
}
}