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

View File

@ -5,8 +5,8 @@ class Slots {
foreign static slotTypes(bool, foreignObj, list, nullObj, num, string, unknown)
foreign static ensure()
foreign static ensureOutsideForeign()
foreign static getListSize(list)
foreign static getListValue(list, index)
foreign static getListCount(list)
foreign static getListElement(list, index)
}
foreign class ForeignType {
@ -34,5 +34,6 @@ System.print(Slots.ensureOutsideForeign())
// expect: 0 -> 20 (190)
var ducks = ["Huey", "Dewey", "Louie"]
System.print(Slots.getListSize(ducks)) // expect: 3
System.print(Slots.getListValue(ducks, 1)) // expect: Dewey
System.print(Slots.getListCount(ducks)) // expect: 3
System.print(Slots.getListElement(ducks, 0)) // expect: Huey
System.print(Slots.getListElement(ducks, 1)) // expect: Dewey