(l *lua.State, idx int)
| 12 | } |
| 13 | |
| 14 | func 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 | |
| 42 | func PullTable(l *lua.State, idx int) (interface{}, error) { |
| 43 | if !l.IsTable(idx) { |
no outgoing calls