aboutsummaryrefslogtreecommitdiff
path: root/testes/api.lua
diff options
context:
space:
mode:
Diffstat (limited to 'testes/api.lua')
-rw-r--r--testes/api.lua14
1 files changed, 9 insertions, 5 deletions
diff --git a/testes/api.lua b/testes/api.lua
index 181c1d53..7d64cb22 100644
--- a/testes/api.lua
+++ b/testes/api.lua
@@ -528,13 +528,15 @@ do
528 local N = 1000 528 local N = 1000
529 -- create a somewhat "large" source 529 -- create a somewhat "large" source
530 for i = 1, N do source[i] = "X = X + 1; " end 530 for i = 1, N do source[i] = "X = X + 1; " end
531 -- add a long string to the source
532 source[#source + 1] = string.format("Y = '%s'", string.rep("a", N));
531 source = table.concat(source) 533 source = table.concat(source)
532 -- give chunk an explicit name to avoid using source as name 534 -- give chunk an explicit name to avoid using source as name
533 source = load(source, "name1") 535 source = load(source, "name1")
534 -- dump without debug information 536 -- dump without debug information
535 source = string.dump(source, true) 537 source = string.dump(source, true)
536 -- each "X=X+1" generates 4 opcodes with 4 bytes each 538 -- each "X=X+1" generates 4 opcodes with 4 bytes each, plus the string
537 assert(#source > N * 4 * 4) 539 assert(#source > N * 4 * 4 + N)
538 collectgarbage(); collectgarbage() 540 collectgarbage(); collectgarbage()
539 local m1 = collectgarbage"count" * 1024 541 local m1 = collectgarbage"count" * 1024
540 -- load dump using fixed buffer 542 -- load dump using fixed buffer
@@ -544,9 +546,11 @@ do
544 ]], source) 546 ]], source)
545 collectgarbage() 547 collectgarbage()
546 local m2 = collectgarbage"count" * 1024 548 local m2 = collectgarbage"count" * 1024
547 -- load used fewer than 300 bytes 549 -- load used fewer than 350 bytes. Code alone has more than 3*N bytes,
548 assert(m2 > m1 and m2 - m1 < 300) 550 -- and string literal has N bytes. Both were not loaded.
549 X = 0; code(); assert(X == N); X = nil 551 assert(m2 > m1 and m2 - m1 < 350)
552 X = 0; code(); assert(X == N and Y == string.rep("a", N))
553 X = nil; Y = nil
550end 554end
551 555
552 556