aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto I <roberto@inf.puc-rio.br>2026-04-23 17:57:42 -0300
committerRoberto I <roberto@inf.puc-rio.br>2026-04-23 17:57:42 -0300
commit3228a97c6a953dcf397944161bb64b12f1ff5384 (patch)
tree6497f6f8e93ba3bb381c0b48aed71646fca3f9b0 /testes
parent0c16a42d61d08266033ff63bc5dfade6312b7359 (diff)
downloadlua-3228a97c6a953dcf397944161bb64b12f1ff5384.tar.gz
lua-3228a97c6a953dcf397944161bb64b12f1ff5384.tar.bz2
lua-3228a97c6a953dcf397944161bb64b12f1ff5384.zip
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.
Diffstat (limited to 'testes')
-rw-r--r--testes/calls.lua26
1 files changed, 26 insertions, 0 deletions
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)
372end 372end
373 373
374 374
375if T then
376 -- check stack level when calling reader function
377 local function get (str)
378 local pos = 0
379 local level = nil
380 return function ()
381 pos = pos + 1
382 local c = string.sub(str, pos, pos)
383 local newlevel = T.stacklevel()
384 if not level then
385 level = newlevel
386 else
387 assert(level == newlevel)
388 end
389 return #c > 0 and c or nil
390 end
391 end
392
393 local str = "local function foo () end; return 121"
394 assert(assert(load(get(str)))() == 121)
395
396 str = string.dump(load(str))
397 assert(assert(load(get(str)))() == 121)
398end
399
400
375x = string.dump(load("x = 1; return x")) 401x = string.dump(load("x = 1; return x"))
376a = assert(load(read1(x), nil, "b")) 402a = assert(load(read1(x), nil, "b"))
377assert(a() == 1 and _G.x == 1) 403assert(a() == 1 and _G.x == 1)