fix(plugins): empty Lua tables now serialize as [] instead of {} in luaValueToGo
Empty Lua tables from DB queries (e.g. get_events with no results)
are ambiguous — they could be [] or {}. Frontend expects arrays
(with .length), so we default empty tables to [] instead of {}.
This commit is contained in:
parent
21130c6f1e
commit
7a95943ad7
|
|
@ -81,6 +81,16 @@ func luaValueToGo(v lua.LValue) interface{} {
|
|||
}
|
||||
return arr
|
||||
}
|
||||
// Check if table has any keys at all — empty tables are ambiguous.
|
||||
// DB queries return empty tables when no rows match; the frontend
|
||||
// expects a valid array [] (with .length), not {} (where .length is undefined).
|
||||
hasKeys := false
|
||||
val.ForEach(func(k lua.LValue, v lua.LValue) {
|
||||
hasKeys = true
|
||||
})
|
||||
if !hasKeys {
|
||||
return make([]interface{}, 0)
|
||||
}
|
||||
m := make(map[string]interface{})
|
||||
val.ForEach(func(k lua.LValue, v lua.LValue) {
|
||||
m[fmt.Sprintf("%v", k)] = luaValueToGo(v)
|
||||
|
|
|
|||
Loading…
Reference in New Issue