From 3228a97c6a953dcf397944161bb64b12f1ff5384 Mon Sep 17 00:00:00 2001 From: Roberto I Date: Thu, 23 Apr 2026 17:57:42 -0300 Subject: Bug: 'lua_load' does not preserve the stack 'lua_load' does not preserve the stack through the calls to the reader function, as it should. Immediately after the first call (to detect whether chunk is binary) it adds stuff, and it also adds a new table when starting the compilation of each new function. --- testes/calls.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'testes') diff --git a/testes/calls.lua b/testes/calls.lua index 0dacb85a..cd4510a2 100644 --- a/testes/calls.lua +++ b/testes/calls.lua @@ -372,6 +372,32 @@ do -- another bug (in 5.4.0) end +if T then + -- check stack level when calling reader function + local function get (str) + local pos = 0 + local level = nil + return function () + pos = pos + 1 + local c = string.sub(str, pos, pos) + local newlevel = T.stacklevel() + if not level then + level = newlevel + else + assert(level == newlevel) + end + return #c > 0 and c or nil + end + end + + local str = "local function foo () end; return 121" + assert(assert(load(get(str)))() == 121) + + str = string.dump(load(str)) + assert(assert(load(get(str)))() == 121) +end + + x = string.dump(load("x = 1; return x")) a = assert(load(read1(x), nil, "b")) assert(a() == 1 and _G.x == 1) -- cgit v1.2.3-55-g6feb