Hacker News new | past | comments | ask | show | jobs | submit | milani's favorites login

You can do this in Luajit with the following trick:

    for f in *.lua; do
        luajit -b $f `basename $f .lua`.o
    done
    
    ar rcus libmylib.a *.o
    gcc -o myexe main-stub.c -I/usr/local/include/luajit-2.0 -L/usr/local/lib -lluajit-5.1 -Wl,--whole-archive libmylib.a -Wl,--no-whole-archive -Wl,-E
Where main-stub.c looks like this:

    #include <lua.h>
    #include <lauxlib.h>
    #include <stdlib.h>
    #include <stdio.h>


    int
    main(void)
    {
        int status, result, i;
        lua_State *L;

        L = luaL_newstate();

        luaL_openlibs(L);

        /* load your lua entry point here */
        status = luaL_loadfile(L, "mainluafile.lua");
        if (status) {
            fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));
            exit(1);
        }


        result = lua_pcall(L, 0, LUA_MULTRET, 0);
        if (result) {
            fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1));
            exit(1);
        }

        lua_close(L);

        return 0;
    }
The executables produced are very small because you dynamically link to Luajit and statically link to your own Lua code. I have a full media scheduler running at 100 sites which is only 40k. And it runs like a demon on ARM too.

Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: