Debian Codegraph @

lua/include/convert.lua

raw symbols SCIP
1 --[[
2 Copyright (C) 2014 HarpyWar ([email protected])
3
4 This file is a part of the PvPGN Project http://pvpgn.pro
5 Licensed under the same terms as Lua itself.
6 ]]--
7
8 -- Convert bytes table to integer
9 function bytes_to_int(bytes, offset, length)
10
11 local t = table.slice(bytes, offset, length)
12 local n = 0
13 for k = 0, #t do
14 n = n + byte_to_utf8(t[k]) * 2^((k)*8)
15 end
16 return n
17 end
18
19 -- Convert bytes table to string
20 function bytes_to_string(bytes)
21 local t = bytes;
22 local bytearr = {}
23 for k = 0, #t do
24 table.insert( bytearr, string.char(byte_to_utf8(t[k])) )
25 end
26 return string:trim( table.concat(bytearr) )
27 end
28
29 -- Convert C byte to Dec
30 function byte_to_utf8(v)
31 return v < 0 and (0xff + v + 1) or v
32 end