OC-Tsuki/utils/mkvelx.lua
2020-05-24 23:50:51 -04:00

64 lines
1.1 KiB
Lua

local f = io.popen("luacomp "..arg[1], "r")
local prog = f:read("*a")
f:close()
local function struct(tbl)
local pat = tbl.endian or "="
local args = {}
for i=1, #tbl do
local a, b = pairs(tbl[i])
local k, v = a(b)
args[i] = k
pat = pat .. v
end
return setmetatable({}, {__call=function(_, arg)
--checkArg(1, arg, "string", "table")
if (type(arg) == "string") then
local sval = {string.unpack(pat, arg)}
local rtn = {}
for i=1, #args do
rtn[args[i]] = sval[i]
end
return rtn, sval[#sval]
elseif (type(arg) == "table") then
local sval = {}
for i=1, #args do
sval[i] = arg[args[i]]
end
return string.pack(pat, unpack(sval))
end
end, __len=function()
return string.packsize(pat)
end})
end
local velx_spec = struct {
endian = "<",
{magic="c5"},
{fver="B"},
{compression="B"},
{lver="B"},
{os="B"},
{arctype="c4"},
{psize="I3"},
{lsize="I3"},
{ssize="I3"},
{rsize="I4"}
}
f = io.open(arg[2], "wb")
f:write(velx_spec({
magic="\27VelX",
fver=1,
compression=0,
lver=0x53,
os=127,
arctype="",
psize=#prog,
lsize=0,
ssize=0,
rsize=0,
}))
f:write(prog)
f:close()