[Lua] manipulate byte array as string (#6624)

* [Lua] manipulate byte array as string

Sometimes it would be more effective than reading byte by byte

* change according to the review

* update
This commit is contained in:
罗泽轩
2021-05-08 13:57:13 +08:00
committed by GitHub
parent 47361baf61
commit 4525cd9c56
5 changed files with 84 additions and 0 deletions

View File

@@ -76,6 +76,17 @@ function mt:Vector(off)
return off + self:Get(N.UOffsetT, off) + 4
end
function mt:VectorAsString(off, start, stop)
local o = self:Offset(off)
if o ~= 0 then
start = start or 1
stop = stop or self:VectorLen(o)
local a = self:Vector(o) + start - 1
return self.bytes:Slice(a, a + stop - start + 1)
end
return nil
end
function mt:Union(t2, off)
assert(getmetatable(t2) == mt_name)
enforceOffset(off)