-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtable-object.go
More file actions
52 lines (45 loc) · 863 Bytes
/
table-object.go
File metadata and controls
52 lines (45 loc) · 863 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package luajit
type Table struct {
L *State
ref Ref
}
// ToTable must later be .Release, otherwise the registry ref will leak.
// TODO: define a runtime.SetFinalizer() on *Table
func (L *State) ToTable(index Index) (t *Table) {
t = &Table{
L: L,
ref: L.RegistryRefIndex(index),
}
return
}
func (t *Table) Release() {
t.L.RegistryUnref(t.ref)
t.ref = RefNil
t.L = nil
}
func (t *Table) GetAssocAll() (rows []map[string]any) {
var (
L = t.L
)
L.RegistryGet(t.ref)
defer L.Pop(1) // remove table ref
if L.IsTable(-1) == false {
return nil
}
L._table_iterate(-1, func() {
var (
rowId = L.ToIntSafe(-2)
_ = rowId
row = make(map[string]any)
)
L._table_iterate(-1, func() {
var (
colName = L.ToStringSafe(-2)
val = L.ToAny(-1)
)
row[colName] = val
})
rows = append(rows, row)
})
return
}