Get number constant reading working

This commit is contained in:
Enrico Lumetti 2022-05-12 11:57:48 +02:00
parent 5aa1a031fa
commit 283be71809
2 changed files with 16 additions and 2 deletions

View File

@ -1,6 +1,8 @@
-- module for reading serialized lua bytecode
local bit=require('bit')
local bit = require('bit')
local lunaclib = require('lunaclib')
local u64_to_num = lunaclib.u64_to_num
local HEADER_MAGIC = {27, string.byte('L'), string.byte('J')}
local FLAG_STRIP = 0x02
@ -125,7 +127,16 @@ local function read_proto(fp)
local bcins = read_u32n(fp, numbc)
local uvdata = read_u16n(fp, numuv)
-- local kgc
-- local numkn
local num = {}
for i = 1, numkn do
local x = read_uleb128(fp)
if bit.band(x, 1) == 1 then
local y = read_uleb128(fp)
num[i] = u64_to_num(x, y)
else
num[i] = (x/2)-1
end
end
-- local debug = fp:read(debugLen)
-- TODO: remove when reading of kgc, numkn and debug is implemented

3
snippets/test5.lua Normal file
View File

@ -0,0 +1,3 @@
local num = 2^15+1
local num64 = 2^32
local fp = 0.75