-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakescript.lua
More file actions
34 lines (32 loc) · 1.01 KB
/
makescript.lua
File metadata and controls
34 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
--
-- makescript.lua Transforms mlslib.lua script into compiled form and
-- writes the result into mlslib_lua.c (in the form of hex-dump). Useful
-- for static linking with Lua and its modules.
--
-- (C) 2016-2017 Alexey Voskov (alvoskov@gmail.com)
-- License: MIT (X11) License
--
-- Compile script using Lua compiler (luac)
os.execute("luac -o mlslib.bin mlslib.lua")
-- Load binary (compiled) script
local inp = assert(io.open('mlslib.bin', "rb"))
local data = inp:read("*all")
inp:close()
-- Convert compiled script into C file
local out = assert(io.open('mlslib_lua.c', 'w'))
out:write("/* AUTOGENERATED: DON'T EDIT! */\n");
out:write(string.format("static const int mlslib_lua_len = %d;\n", #data));
out:write("static const char mlslib_lua_data[] = {\n");
for i = 1, #data do
if i == #data then
out:write(string.format("0x%.2X", data:byte(i)));
else
out:write(string.format("0x%.2X, ", data:byte(i)));
end
if i % 16 == 0 then
out:write("\n");
end
end
out:write("};\n");
out:close()
print('mlslib_lua.c file created')