[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Embedding scripts in executable
- From: Mike Pall <mikelu-1109@...>
- Date: Wed, 28 Sep 2011 11:22:23 +0200
Tim Caswell wrote:
> I have a folder full of lua modules (written in lua) and I want them
> embedded in my binary at compile/link time in such a way that the require
> system can find them.
>
> Is there a cross-platform way to embed these scripts and make
> them accessible to require?
>
> I'm using luajit, but I think this question is generic.
The latest LuaJIT from git HEAD makes this really easy:
luajit -b foo.lua foo.o
luajit -b bar.lua bar.o
This generates actual object files you can link against your
application! These use the default file format for the platform
that LuaJIT has been compiled for (see doc/running.html in git
HEAD for more options).
Currently only ELF for Linux etc. or PE/COFF for Windows is
supported. If someone has got the time and expertise, support for
Mach-O on OSX would be nice to have.
Another option is to generate C source code for the bytecode of a
module (luajit -b foo.lua foo.c) and compile that together with
your application code. This ought to work on all platforms.
Also, require() has been extended to search for the symbols these
object files provide and load them. E.g. you can then do:
local foo = require("foo")
local bar = require("bar")
[You may even call require() via the Lua/C API to load the main
Lua module of your application.]
--Mike