Ejemplo n.º 1
0
// Get gets an element form the Array by index.
//
// This does not copy the element. This is a pointer/reference directly
// to the element in the array.
func (v *Array) Get(idx int) (*MrbValue, error) {
	result := C.mrb_ary_entry(v.value, C.mrb_int(idx))

	val := newValue(v.state, result)
	if val.Type() == TypeNil {
		val = nil
	}

	return val, nil
}
Ejemplo n.º 2
0
// Get gets an element form the Array by index.
//
// This does not copy the element. This is a pointer/reference directly
// to the element in the array.
func (v *Array) Get(idx int) (*MrbValue, error) {
	result := C.mrb_ary_entry(v.value, C.mrb_int(idx))
	if v.state.exc != nil {
		return nil, newExceptionValue(v.state)
	}

	val := newValue(v.state, result)
	if val.Type() == TypeFalse {
		val = nil
	}

	return val, nil
}