6a9b082f97
ui.lua and hints.lua are compiled to LUA_32BITS bytecode (matching the firmware's Lua build) and linked into the binary. A new package.searchers entry checks them as the fallback after the SD card, so a local /.lua/lib/ui.lua still shadows the packaged one for debugging. Bytecode is ~40% smaller than source and loads without parsing. A fresh SD card with no make sdcard now has the platform available.
37 lines
981 B
C
37 lines
981 B
C
// 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 <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#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;
|
|
}
|