From 5fa26cdb219aee4c9b01f444526d7de110b5860c Mon Sep 17 00:00:00 2001 From: XmiliaH Date: Sun, 23 Nov 2025 15:47:17 +0100 Subject: [PATCH] Rewrite concat to call metamethods --- the-tiny-lua-compiler.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/the-tiny-lua-compiler.lua b/the-tiny-lua-compiler.lua index c2d3370..dbf3455 100644 --- a/the-tiny-lua-compiler.lua +++ b/the-tiny-lua-compiler.lua @@ -3927,13 +3927,11 @@ function VirtualMachine:executeClosure(...) -- OP_CONCAT [A, B, C] R(A) := R(B).. ... ..R(C) -- Concatenate a range of registers and store the result in a register. elseif opcode == "CONCAT" then - local values = {} - for reg = b, c do - table.insert(values, stack[reg]) + for reg = c - 1, b, -1 do + -- We cannot use table.concat as it does not call metamethods + stack[reg] = stack[reg] .. stack[reg + 1] end - - -- Optimization: use table.concat for efficient string concatenation. - stack[a] = table.concat(values) + stack[a] = stack[b] -- OP_JMP [A, sBx] pc+=sBx -- Jump to a new instruction offset.