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

Function PullStringTable

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

Source from the content-addressed store, hash-verified

12}
13
14func PullStringTable(l *lua.State, idx int) (map[string]string, error) {
15 if !l.IsTable(idx) {
16 return nil, fmt.Errorf("need a table at index %d, got %s", idx, lua.TypeNameOf(l, idx))
17 }
18
19 // Table at idx
20 l.PushNil() // Add free slot for the value, +1
21
22 table := make(map[string]string)
23 // -1:nil, idx:table
24 for l.Next(idx) {
25 // -1:val, -2:key, idx:table
26 key, ok := l.ToString(-2)
27 if !ok {
28 return nil, fmt.Errorf("key should be a string (%v)", l.ToValue(-2))
29 }
30 val, ok := l.ToString(-1)
31 if !ok {
32 return nil, fmt.Errorf("value for key '%s' should be a string (%v)", key, l.ToValue(-1))
33 }
34 table[key] = val
35 l.Pop(1) // remove val from top, -1
36 // -1:key, idx: table
37 }
38
39 return table, nil
40}
41
42func PullTable(l *lua.State, idx int) (interface{}, error) {
43 if !l.IsTable(idx) {

Callers 2

testRandomMapFunction · 0.92

Calls

no outgoing calls

Tested by 2

testRandomMapFunction · 0.74