getSlot<T> method

T getSlot<T>(
  1. int index
)

Gets the value of the slot at index as a T

Implementation

T getSlot<T>(int index) {
  if (T == double) {
    if (getSlotType(index) != WType.number) {
      throw TypeError();
    }
    return _bindings.wrenGetSlotDouble(_ptrVm, index) as T;
  } else if (T == bool) {
    if (getSlotType(index) != WType.boolean) {
      throw TypeError();
    }
    return _bindings.wrenGetSlotBool(_ptrVm, index) as T;
  } else if (T == String) {
    if (getSlotType(index) != WType.string) {
      throw TypeError();
    }
    return _bindings
        .wrenGetSlotString(_ptrVm, index)
        .cast<Utf8>()
        .toDartString() as T;
  } else {
    throw ArgumentError('Invalid type for getSlot');
  }
}