update sprotoparser for lua 5.3

This commit is contained in:
Cloud Wu
2015-01-05 21:38:41 +08:00
parent cb41293320
commit 39cf6c99a2

View File

@@ -1,5 +1,4 @@
local lpeg = require "lpeg" local lpeg = require "lpeg"
local bit32 = require "bit32"
local table = require "table" local table = require "table"
local P = lpeg.P local P = lpeg.P
@@ -196,18 +195,14 @@ end
]] ]]
local function packbytes(str) local function packbytes(str)
local size = #str str = string.pack("<s4",str)
return string.char(bit32.extract(size,0,8)).. return str
string.char(bit32.extract(size,8,8))..
string.char(bit32.extract(size,16,8))..
string.char(bit32.extract(size,24,8))..
str
end end
local function packvalue(id) local function packvalue(id)
id = (id + 1) * 2 id = (id + 1) * 2
assert(id >=0 and id < 65536) local str = string.pack("<I2", id)
return string.char(bit32.extract(id, 0, 8)) .. string.char(bit32.extract(id, 8, 8)) return str
end end
local function packfield(f) local function packfield(f)