Tweak list C API:

- Rename "size" -> "count" to be consistent with other usage.
- Remove "Slot" from the function names, since that's implicit.
- Make the getListElement() just move the element to another slot. This
  matches other APIs where we distinguish accessing a value and
  converting it to some specific type.
This commit is contained in:
Bob Nystrom
2016-07-28 08:06:36 -07:00
parent b8675e2d91
commit 60a0353a27
4 changed files with 37 additions and 38 deletions
+7 -6
View File
@@ -359,12 +359,6 @@ double wrenGetSlotDouble(WrenVM* vm, int slot);
// foreign class.
void* wrenGetSlotForeign(WrenVM* vm, int slot);
// Returns the size of the list stored in [slot].
int wrenGetSlotListSize(WrenVM* vm, int slot);
// Reads a value from the list in [slot].
WrenValue* wrenGetSlotListValue(WrenVM* vm, int slot, int index);
// Reads a string from [slot].
//
// The memory for the returned string is owned by Wren. You can inspect it
@@ -431,6 +425,13 @@ void wrenSetSlotString(WrenVM* vm, int slot, const char* text);
// This does not release the handle for the value.
void wrenSetSlotHandle(WrenVM* vm, int slot, WrenHandle* handle);
// Returns the number of elements in the list stored in [slot].
int wrenGetListCount(WrenVM* vm, int slot);
// Reads element [index] from the list in [listSlot] and stores it in
// [elementSlot].
void wrenGetListElement(WrenVM* vm, int listSlot, int index, int elementSlot);
// Takes the value stored at [elementSlot] and inserts it into the list stored
// at [listSlot] at [index].
//
+19 -20
View File
@@ -1553,26 +1553,6 @@ void* wrenGetSlotForeign(WrenVM* vm, int slot)
return AS_FOREIGN(vm->apiStack[slot])->data;
}
int wrenGetSlotListSize(WrenVM* vm, int slot)
{
validateApiSlot(vm, slot);
ASSERT(IS_LIST(vm->apiStack[slot]),
"Slot must hold a list instance.");
ValueBuffer elements = AS_LIST(vm->apiStack[slot])->elements;
return elements.count;
}
WrenValue* wrenGetSlotListValue(WrenVM* vm, int slot, int index)
{
validateApiSlot(vm, slot);
ASSERT(IS_LIST(vm->apiStack[slot]),
"Slot must hold a list instance.");
ValueBuffer elements = AS_LIST(vm->apiStack[slot])->elements;
return wrenCaptureValue(vm, elements.data[index]);
}
const char* wrenGetSlotString(WrenVM* vm, int slot)
{
validateApiSlot(vm, slot);
@@ -1649,6 +1629,25 @@ void wrenSetSlotHandle(WrenVM* vm, int slot, WrenHandle* handle)
setSlot(vm, slot, handle->value);
}
int wrenGetListCount(WrenVM* vm, int slot)
{
validateApiSlot(vm, slot);
ASSERT(IS_LIST(vm->apiStack[slot]), "Slot must hold a list.");
ValueBuffer elements = AS_LIST(vm->apiStack[slot])->elements;
return elements.count;
}
void wrenGetListElement(WrenVM* vm, int listSlot, int index, int elementSlot)
{
validateApiSlot(vm, listSlot);
validateApiSlot(vm, elementSlot);
ASSERT(IS_LIST(vm->apiStack[listSlot]), "Slot must hold a list.");
ValueBuffer elements = AS_LIST(vm->apiStack[listSlot])->elements;
vm->apiStack[elementSlot] = elements.data[index];
}
void wrenInsertInList(WrenVM* vm, int listSlot, int index, int elementSlot)
{
validateApiSlot(vm, listSlot);