add map array support to pushvalue
This commit is contained in:
parent
c22638b51f
commit
4e59fc6e5c
14
wrapper.go
14
wrapper.go
@ -249,6 +249,8 @@ func (s *State) PushValue(v any) error {
|
|||||||
return s.pushFloatSlice(val)
|
return s.pushFloatSlice(val)
|
||||||
case []any:
|
case []any:
|
||||||
return s.pushAnySlice(val)
|
return s.pushAnySlice(val)
|
||||||
|
case []map[string]any:
|
||||||
|
return s.pushMapSlice(val)
|
||||||
case map[string]string:
|
case map[string]string:
|
||||||
return s.pushStringMap(val)
|
return s.pushStringMap(val)
|
||||||
case map[string]int:
|
case map[string]int:
|
||||||
@ -810,3 +812,15 @@ func (s *State) CallGlobal(name string, args ...any) ([]any, error) {
|
|||||||
s.SetTop(baseTop)
|
s.SetTop(baseTop)
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *State) pushMapSlice(arr []map[string]any) error {
|
||||||
|
s.CreateTable(len(arr), 0)
|
||||||
|
for i, m := range arr {
|
||||||
|
s.PushNumber(float64(i + 1))
|
||||||
|
if err := s.PushValue(m); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.SetTable(-3)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user