Files
wren/test/api/slots.wren
Damien Radtke cf258b9074 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.
2016-05-19 14:11:48 -05:00

39 lines
1.1 KiB
Plaintext

class Slots {
foreign static noSet
foreign static getSlots(bool, num, string, bytes, value)
foreign static setSlots(a, b, c, d)
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 class ForeignType {
construct new() {}
}
// If nothing is set in the return slot, it retains its previous value, the
// receiver.
System.print(Slots.noSet == Slots) // expect: true
var value = ["value"]
System.print(Slots.getSlots(true, "by\0te", 12.34, "str", value) == value)
// expect: true
System.print(Slots.setSlots(value, 0, 0, 0) == value)
// expect: true
System.print(Slots.slotTypes(false, ForeignType.new(), [], null, 1.2, "str", 1..2))
// expect: true
System.print(Slots.ensure())
// expect: 1 -> 20 (190)
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