MCPcopy Create free account
hub / github.com/Shopify/goluago / pullTableRec

Function pullTableRec

util/deep_pull.go:50–84  ·  view source on GitHub ↗
(l *lua.State, idx int)

Source from the content-addressed store, hash-verified

48}
49
50func pullTableRec(l *lua.State, idx int) (interface{}, error) {
51 if !l.CheckStack(2) {
52 return nil, errors.New("pull table, stack exhausted")
53 }
54
55 idx = l.AbsIndex(idx)
56 if isArray(l, idx) {
57 return pullArrayRec(l, idx)
58 }
59
60 table := make(map[string]interface{})
61
62 l.PushNil()
63 for l.Next(idx) {
64 // -1: value, -2: key, ..., idx: table
65 key, ok := l.ToString(-2)
66 if !ok {
67 err := fmt.Errorf("key should be a string (%s)", lua.TypeNameOf(l, -2))
68 l.Pop(2)
69 return nil, err
70 }
71
72 value, err := toGoValue(l, -1)
73 if err != nil {
74 l.Pop(2)
75 return nil, err
76 }
77
78 table[key] = value
79
80 l.Pop(1)
81 }
82
83 return table, nil
84}
85
86const arrayMarkerField = "_is_array"
87

Callers 2

PullTableFunction · 0.85
toGoValueFunction · 0.85

Calls 3

isArrayFunction · 0.85
pullArrayRecFunction · 0.85
toGoValueFunction · 0.85

Tested by

no test coverage detected