Dump uses varints also for integer constants

Unlike sizes, these constants can be negative, so it encodes those
integers into unsigned integers in a way that keeps small numbers
small.
This commit is contained in:
Roberto Ierusalimschy
2025-06-13 14:14:50 -03:00
parent e657a48ea5
commit 0cecf1ab6d
3 changed files with 48 additions and 18 deletions

View File

@@ -482,5 +482,23 @@ do -- basic check for SETLIST
assert(count == 1)
end
do print("testing code for integer limits")
local function checkints (n)
local source = string.format(
"local a = {[true] = 0X%x}; return a[true]", n)
local f = assert(load(source))
checkKlist(f, {n})
assert(f() == n)
f = load(string.dump(f))
assert(f() == n)
end
checkints(math.maxinteger)
checkints(math.mininteger)
checkints(-1)
end
print 'OK'