diff --git a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala index 9eaee3f4b..4f8e41012 100644 --- a/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala +++ b/jvm/src/test/scala/io/kaitai/struct/translators/TranslatorSpec.scala @@ -672,7 +672,7 @@ class TranslatorSpec extends AnyFunSpec { GoCompiler -> "[]uint8{(0 + 1), 5}", JavaCompiler -> "new byte[] { (0 + 1), 5 }", JavaScriptCompiler -> "new Uint8Array([(0 + 1), 5])", - LuaCompiler -> "???", + LuaCompiler -> "string.char((0 + 1), 5)", PerlCompiler -> "pack('C*', ((0 + 1), 5))", PHPCompiler -> "pack('C*', (0 + 1), 5)", PythonCompiler -> "struct.pack('2b', (0 + 1), 5)", diff --git a/shared/src/main/scala/io/kaitai/struct/translators/LuaTranslator.scala b/shared/src/main/scala/io/kaitai/struct/translators/LuaTranslator.scala index 64bf14f99..c65d33210 100644 --- a/shared/src/main/scala/io/kaitai/struct/translators/LuaTranslator.scala +++ b/shared/src/main/scala/io/kaitai/struct/translators/LuaTranslator.scala @@ -67,10 +67,14 @@ class LuaTranslator(provider: TypeProvider, importList: ImportList) extends Base override def doBoolLiteral(n: Boolean): String = if (n) "true" else "false" + override def doArrayLiteral(t: DataType, value: Seq[Ast.expr]): String = "{" + value.map((v) => translate(v)).mkString(", ") + "}" override def doByteArrayLiteral(arr: Seq[Byte]): String = "\"" + decEscapeByteArray(arr) + "\"" + override def doByteArrayNonLiteral(values: Seq[Ast.expr]): String = + // It is assumed that every expression produces integer in the range [0; 255] + "string.char(" + values.map(translate).mkString(", ") + ")" override def doLocalName(s: String) = s match { case Identifier.ITERATOR => "_"