forked from mitchellh/go-mruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.go
More file actions
31 lines (25 loc) · 686 Bytes
/
array.go
File metadata and controls
31 lines (25 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package mruby
// #include "gomruby.h"
import "C"
// Array represents an MrbValue that is a Array in Ruby.
//
// A Array can be obtained by calling the Array function on MrbValue.
type Array struct {
*MrbValue
}
// Len returns the length of the array.
func (v *Array) Len() int {
return int(C.mrb_ary_len(v.state, v.value))
}
// 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
}