(l *lua.State, idx int)
| 48 | } |
| 49 | |
| 50 | func 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 | |
| 86 | const arrayMarkerField = "_is_array" |
| 87 |
no test coverage detected