From 1a0b2c07e5ced55319c18f62d41876159e1b1a62 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Thu, 4 Apr 2024 21:19:25 +0200 Subject: [PATCH] Lua: use `self` as default `_root` only in top-level types See the same change in Python: e776c982f8ba5b039bdcacd1db48ecbe77588df6 Fixes the `NestedTypesImport` test for Lua. --- .../main/scala/io/kaitai/struct/languages/LuaCompiler.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/shared/src/main/scala/io/kaitai/struct/languages/LuaCompiler.scala b/shared/src/main/scala/io/kaitai/struct/languages/LuaCompiler.scala index 46d6e7fd2..89b45f292 100644 --- a/shared/src/main/scala/io/kaitai/struct/languages/LuaCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/languages/LuaCompiler.scala @@ -87,7 +87,11 @@ class LuaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig) out.inc out.puts(s"$kstructName._init(self, io)") out.puts("self._parent = parent") - out.puts("self._root = root or self") + if (name == rootClassName) { + out.puts("self._root = root or self") + } else { + out.puts("self._root = root") + } if (isHybrid) out.puts("self._is_le = is_le")