Moduuli:Translitteroija/yhteinen
Ulkoasu
Tämän moduulin ohjeistuksen voi tehdä sivulle Moduuli:Translitteroija/yhteinen/ohje
local export = {}
function export.log_conversion_table(tbl)
local row_size = tbl.pseudo_row_length
local vlen = #tbl / row_size
mw.log("CONVERSION TABLE:")
for i = 1, vlen do
mw.log(i, unpack(tbl, (i - 1) * row_size + 1, (i - 1) * row_size + row_size))
end
mw.log("* size:\t", #tbl)
mw.log("* prefix_max:\t", tbl.prefix_max)
mw.log("* in_max:\t", tbl.in_max)
mw.log("* out_max:\t", tbl.out_max)
mw.log("* pseudo length:", tbl.pseudo_length)
mw.log("* pseudo row length:", tbl.pseudo_row_length)
mw.log()
end
function export.tostring(tbl, start, length, to_chars)
local tmp = {}
local val
if not start or start < 1 then
start = 1
end
if not length or start + length - 1 > #tbl then
length = #tbl - start + 1
end
for i, val in ipairs(tbl) do
if i >= start and i <= start + length - 1 then
if val == nil then
tmp[i - start + 1] = 0
else
tmp[i - start + 1] = val
end
elseif i > start + length - 1 then
break
end
end
if to_chars then
return table.concat(tmp, ", ") .. ' "' .. string.char(unpack(tmp)) .. '"'
else
return table.concat(tmp, ", ")
end
end
-- Huom. vaikka size olisi isompi tekee aina korkeintaan 4-tavuisen
function export.get_index_key(buffer, row_offset, col_offset, size)
--tostring(buffer, row_offset + col_offset, row_offset + col_offset - 1, true)
local key = 0
local cell_offset = row_offset + col_offset - 1
if size > 0 then
key = buffer[cell_offset + 0] * 256 * 256 * 256
end
if size > 1 then
key = key + buffer[cell_offset + 1] * 256 * 256
end
if size > 2 then
key = key + buffer[cell_offset + 2] * 256
end
if size > 3 then
key = key + buffer[cell_offset + 3]
end
return key
end
return export