lua-users home
lua-l archive

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


Mike, I've tried for a few days, and I can't figure out how to get
this working.  I have my make file generating the C files and
compiling them into my binary.  I can confirm that the strings are
available, but require can't find them.  Do I have to do something
special to register the modules?  I put printf statements in
ll_loadfunc and it never seems to be called.

I'm sure I'm missing something simple, but I can't figure it out.

-Tim Caswell

On Wed, Sep 28, 2011 at 2:22 AM, Mike Pall <mikelu-1109@mike.de> wrote:
> 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
>
>