lua-users home
lua-l archive

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


On Tuesday, March 24, 2015 01:57:37 PM Sean Conner wrote:
>   I use the GNU compiler chain.  In my Makefile, I have an implicit rule to
> compile Lua files into object files (warning:  uses GNU features):

If you're using GCC (and maybe Clang?) you can skip the bin2c step and write 
the Lua source into an object file as a data segment. 

    %.o: %.lua
        objcopy -I binary -O $(BIN_TARGET) -B $(ARCH) $< $@

The bin target is elf32-i386 or elf64-x86-64 or pe-i386 or whatever. And arch 
is the architecture of course. Then in your C/C++ source you have

    extern const char binary_Startup_lua_start[];

Objcopy creates the symbols "binary_filename_start" "binary_filename_end" and 
"binary_filename_size". If you don't like that you can use the flags 
--redefine-sym or --strip-symbol to whatever name you want. (Don't forget the 
leading underscore on C symbols.) You may also want to put it in its own named 
section: --rename-section .data=lua,data,alloc,load,contents,readonly,share

-- 
tom <telliamed@whoopdedo.org>