From 879bfb811ae37eb7f133ee4a397ef384a25006fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Jan=20Fialka?= Date: Wed, 4 Mar 2026 11:47:28 +0100 Subject: [PATCH] [LIQ] `group by`: Convert plain JS objects to LuaTable in results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Items from `index.tag` are stored as plain JS objects when no metatable is defined. The `group by` clause wraps rows in `LuaTable` (`key`, `group`) but leaves the individual `group` items as plain JS objects. This causes `t.keys is not a function` errors when passing `row.group` to APIs like `template.each` that expect `LuaTable` instances. Signed-off-by: Matouš Jan Fialka --- client/space_lua/query_collection.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/space_lua/query_collection.ts b/client/space_lua/query_collection.ts index f9193ad0..9713fc19 100644 --- a/client/space_lua/query_collection.ts +++ b/client/space_lua/query_collection.ts @@ -12,6 +12,7 @@ import type { } from "./ast.ts"; import { + jsToLuaValue, luaCall, LuaEnv, LuaFunction, @@ -730,7 +731,14 @@ export async function applyQuery( for (const { key, items } of groups.values()) { const groupTable = new LuaTable(); for (let i = 0; i < items.length; i++) { - groupTable.rawSetArrayIndex(i + 1, items[i]); + const item = items[i]; + groupTable.rawSetArrayIndex( + i + 1, + (item instanceof LuaTable || typeof item !== "object" || + item === null) + ? item + : jsToLuaValue(item), + ); } const row = new LuaTable(); row.rawSet("key", key);