// Dumps a Lua source file as bytecode, linked against the same vendored Lua the firmware // runs (LUA_32BITS), so the header matches. Stand-in for luac when only the library is // vendored. #include #include #include "lauxlib.h" #include "lua.h" static int writer(lua_State*, const void* p, size_t size, void* ud) { return fwrite(p, 1, size, (FILE*)ud) != size ? 1 : 0; } int main(int argc, char** argv) { if (argc != 3) { fprintf(stderr, "usage: %s input.lua output.luac\n", argv[0]); return 1; } lua_State* L = luaL_newstate(); if (luaL_loadfilex(L, argv[1], "t") != LUA_OK) { fprintf(stderr, "%s: %s\n", argv[1], lua_tostring(L, -1)); lua_close(L); return 1; } FILE* out = fopen(argv[2], "wb"); if (!out) { fprintf(stderr, "cannot open %s\n", argv[2]); lua_close(L); return 1; } const int err = lua_dump(L, writer, out, 1); // strip debug info fclose(out); lua_close(L); return err ? 1 : 0; }