Lua truthiness fixes

pull/1224/head
Zef Hemel 2025-01-26 08:07:10 +01:00
parent 265aa8dab6
commit b8835a07e2
1 changed files with 10 additions and 4 deletions

View File

@ -315,9 +315,12 @@ export class LuaTable implements ILuaSettable, ILuaGettable {
return this.arrayPart.length; return this.arrayPart.length;
} }
hasKeys(): boolean { empty(): boolean {
return !!(Object.keys(this.stringKeys).length > 0 || return (
this.arrayPart.length > 0 || (this.otherKeys && this.otherKeys.size > 0)); Object.keys(this.stringKeys).length === 0 &&
this.arrayPart.length === 0 &&
(this.otherKeys === null || this.otherKeys.size === 0)
);
} }
keys(): any[] { keys(): any[] {
@ -700,7 +703,10 @@ export function luaTruthy(value: any): boolean {
return false; return false;
} }
if (value instanceof LuaTable) { if (value instanceof LuaTable) {
return value.hasKeys(); return value.empty();
}
if (value instanceof LuaMultiRes) {
return value.values.length > 0;
} }
return true; return true;
} }