Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Nov 20, 2020. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbin2c
More file actions
Latest commit
67 lines (54 loc) · 1.92 KB
/
Copy pathbin2c
File metadata and controls
67 lines (54 loc) · 1.92 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env lua
localdescription=[=[
Usage: bin2c [+]filename [status]
Write a C source file to standard output. When this C source file is
included in another C source file, it has the effect of loading and
running the specified file at that point in the program.
The file named by 'filename' contains either Lua byte code or Lua source.
Its contents are used to generate the C output. If + is used, then the
contents of 'filename' are first compiled before being used to generate
the C output. If given, 'status' names a C variable used to store the
return value of either luaL_loadbuffer() or lua_pcall(). Otherwise,
the return values of these functions will be unavailable.
This program is (overly) careful to generate output identical to the
output generated by bin2c5.1 from LuaBinaries.
http://lua-users.org/wiki/BinTwoCee
Original author: Mark Edgar
Licensed under the same terms as Lua (MIT license).
]=]
ifnotargornotarg[1] then
io.stderr:write(description)
return
end
localcompile, filename=arg[1]:match"^(+?)(.*)"
localstatus=arg[2]
localcontent=compile=="+"
andstring.dump(assert(loadfile(filename)))
orassert(io.open(filename,"rb")):read"*a"
localfunctionboilerplate(fmt)
returnstring.format(fmt,
statusand"("..status.."=" or"",
filename,
statusand")" or"",
statusandstatus.."=" or"",
filename)
end
localdumpdo
localnumtab={}; fori=0,255donumtab[string.char(i)]=("%3d,"):format(i) end
functiondump(str)
return (str:gsub(".", numtab):gsub(("."):rep(80), "%0\n"))
end
end
io.write(boilerplate[=[
/* code automatically generated by bin2c -- DO NOT EDIT */
{
/* #include'ing this file in a C program is equivalent to calling
if (%sluaL_loadfile(L,%q)%s==0) %slua_pcall(L, 0, 0, 0);
*/
/* %s */
static const unsigned char B1[]={
]=], dump(content), boilerplate[=[
};
if (%sluaL_loadbuffer(L,(const char*)B1,sizeof(B1),%q)%s==0) %slua_pcall(L, 0, 0, 0);
}
]=])