diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bin2c.lua | 63 | ||||
-rw-r--r-- | src/imlua5.mak | 1 | ||||
-rw-r--r-- | src/imlua_fftw5.mak | 1 | ||||
-rw-r--r-- | src/imlua_process5.mak | 1 |
4 files changed, 66 insertions, 0 deletions
diff --git a/src/bin2c.lua b/src/bin2c.lua new file mode 100644 index 0000000..1e3b53f --- /dev/null +++ b/src/bin2c.lua @@ -0,0 +1,63 @@ +local description = [=[ +Usage: lua bin2c.lua [+]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 +]=] + +if not arg or not arg[1] then + io.stderr:write(description) + return +end + +local compile, filename = arg[1]:match"^(+?)(.*)" +local status = arg[2] + +local content = compile=="+" + and string.dump(assert(loadfile(filename))) + or assert(io.open(filename,"rb")):read"*a" + +local function boilerplate(fmt) + return string.format(fmt, + status and "("..status.."=" or "", + filename, + status and ")" or "", + status and status.."=" or "", + filename) +end + +local dump do + local numtab={}; for i=0,255 do numtab[string.char(i)]=("%3d,"):format(i) end + function dump(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); +} +]=]) diff --git a/src/imlua5.mak b/src/imlua5.mak index e1412e5..4f355e8 100644 --- a/src/imlua5.mak +++ b/src/imlua5.mak @@ -23,4 +23,5 @@ endif USE_IM = YES NO_LUALINK = Yes +USE_BIN2C_LUA=Yes IM = .. diff --git a/src/imlua_fftw5.mak b/src/imlua_fftw5.mak index d97744d..c19fabc 100644 --- a/src/imlua_fftw5.mak +++ b/src/imlua_fftw5.mak @@ -25,6 +25,7 @@ endif USE_IMLUA = YES NO_LUALINK = Yes +USE_BIN2C_LUA=Yes IM = .. ifneq ($(findstring MacOS, $(TEC_UNAME)), ) diff --git a/src/imlua_process5.mak b/src/imlua_process5.mak index 22bb0e4..c7aacab 100644 --- a/src/imlua_process5.mak +++ b/src/imlua_process5.mak @@ -24,6 +24,7 @@ endif USE_IMLUA = YES NO_LUALINK = Yes +USE_BIN2C_LUA=Yes IM = .. ifneq ($(findstring MacOS, $(TEC_UNAME)), ) |