lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

The bin2c program I use is available here:

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

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