[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: bin2c
- From: ramsdell@... (John D. Ramsdell)
- Date: 27 Feb 2006 20:19:17 -0500
The bin2c program I use is available here:
http://www.ccs.neu.edu/home/ramsdell/tools/bin2c.c
It's not Lua specific--it generates no calls to Lua library functions.
Instead, the generated C source file defines a string with the file
name of the source of data, and an unsigned character array containing
the binary data.
For example, if the source file is dl.lua, the generated file
contains:
static const char dl_lua_source[] = "dl.lua";
static const unsigned char dl_lua_bytes[] = {
...
};
For a Lua application, some C file would contain something like:
#include "dl.h"
static int
dl_lua(lua_State *L) {
return lua_dobuffer(L, (const char*)dl_lua_bytes,
sizeof(dl_lua_bytes), dl_lua_source);
}
The header file may be generated with the following GNUMakefile rule:
%.h: %.lua
luac -o $*.luo $<
bin2c -o $@ -n $< $*.luo
rm $*.luo
John