From b8835a07e2ab5dad1da238b93c0e45dc60bafd0b Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Sun, 26 Jan 2025 08:07:10 +0100 Subject: [PATCH] Lua truthiness fixes --- common/space_lua/runtime.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/common/space_lua/runtime.ts b/common/space_lua/runtime.ts index b7214607..86a902d7 100644 --- a/common/space_lua/runtime.ts +++ b/common/space_lua/runtime.ts @@ -315,9 +315,12 @@ export class LuaTable implements ILuaSettable, ILuaGettable { return this.arrayPart.length; } - hasKeys(): boolean { - return !!(Object.keys(this.stringKeys).length > 0 || - this.arrayPart.length > 0 || (this.otherKeys && this.otherKeys.size > 0)); + empty(): boolean { + return ( + Object.keys(this.stringKeys).length === 0 && + this.arrayPart.length === 0 && + (this.otherKeys === null || this.otherKeys.size === 0) + ); } keys(): any[] { @@ -700,7 +703,10 @@ export function luaTruthy(value: any): boolean { return false; } if (value instanceof LuaTable) { - return value.hasKeys(); + return value.empty(); + } + if (value instanceof LuaMultiRes) { + return value.values.length > 0; } return true; }