2015-12-16 13:00:13 -08:00
|
|
|
class Slots {
|
|
|
|
|
foreign static noSet
|
|
|
|
|
foreign static getSlots(bool, num, string, bytes, value)
|
2017-03-03 07:57:50 -08:00
|
|
|
foreign static setSlots(a, b, c, d, e)
|
2020-06-14 22:45:23 +01:00
|
|
|
foreign static slotTypes(bool, foreignObj, list, map, nullObj, num, string, unknown)
|
2015-12-16 16:28:26 -08:00
|
|
|
foreign static ensure()
|
2015-12-28 07:43:17 -08:00
|
|
|
foreign static ensureOutsideForeign()
|
2016-07-28 08:06:36 -07:00
|
|
|
foreign static getListCount(list)
|
|
|
|
|
foreign static getListElement(list, index)
|
2020-06-14 22:45:23 +01:00
|
|
|
foreign static getMapValue(map, key)
|
2015-12-16 13:00:13 -08:00
|
|
|
}
|
|
|
|
|
|
2016-02-19 07:18:00 -08:00
|
|
|
foreign class ForeignType {
|
|
|
|
|
construct new() {}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 13:00:13 -08:00
|
|
|
// 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"]
|
2016-10-09 09:18:27 +01:00
|
|
|
System.print(Slots.getSlots(true, "by\0te", 1.5, "str", value) == value)
|
2015-12-28 07:43:17 -08:00
|
|
|
// expect: true
|
2015-12-16 13:00:13 -08:00
|
|
|
|
2017-03-03 07:57:50 -08:00
|
|
|
System.print(Slots.setSlots(value, 0, 0, 0, 0) == value)
|
2015-12-28 07:43:17 -08:00
|
|
|
// expect: true
|
2015-12-16 16:28:26 -08:00
|
|
|
|
2020-06-14 22:45:23 +01:00
|
|
|
System.print(Slots.slotTypes(false, ForeignType.new(), [], {}, null, 1.2, "str", 1..2))
|
2016-02-19 07:18:00 -08:00
|
|
|
// expect: true
|
|
|
|
|
|
2015-12-28 07:43:17 -08:00
|
|
|
System.print(Slots.ensure())
|
|
|
|
|
// expect: 1 -> 20 (190)
|
|
|
|
|
|
|
|
|
|
System.print(Slots.ensureOutsideForeign())
|
|
|
|
|
// expect: 0 -> 20 (190)
|
2016-05-19 13:26:01 -05:00
|
|
|
|
|
|
|
|
var ducks = ["Huey", "Dewey", "Louie"]
|
2016-07-28 08:06:36 -07:00
|
|
|
System.print(Slots.getListCount(ducks)) // expect: 3
|
|
|
|
|
System.print(Slots.getListElement(ducks, 0)) // expect: Huey
|
|
|
|
|
System.print(Slots.getListElement(ducks, 1)) // expect: Dewey
|
2020-06-14 22:45:23 +01:00
|
|
|
|
|
|
|
|
var capitals = {
|
|
|
|
|
"England": "London",
|
|
|
|
|
"Scotland": "Edinburgh",
|
|
|
|
|
"Wales": "Cardiff",
|
|
|
|
|
"N. Ireland": "Belfast"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.print(Slots.getMapValue(capitals, "England")) // expect: London
|
|
|
|
|
System.print(Slots.getMapValue(capitals, "Wales")) // expect: Cardiff
|
|
|
|
|
System.print(Slots.getMapValue(capitals, "S. Ireland")) // expect: null
|