| 85 | } |
| 86 | |
| 87 | s32 compile(CompileOptions &opts) |
| 88 | { |
| 89 | TempAllocator1024 ta; |
| 90 | DynamicString lua_src(ta); |
| 91 | DynamicString lua_out(ta); |
| 92 | opts.absolute_path(lua_src, opts.source_path()); |
| 93 | opts.temporary_path(lua_out, "lua"); |
| 94 | |
| 95 | #if CROWN_PLATFORM_LINUX |
| 96 | #define CROWN_32BIT_BIN_DIR "linux32" |
| 97 | #elif CROWN_PLATFORM_WINDOWS |
| 98 | #define CROWN_32BIT_BIN_DIR "windows32" |
| 99 | #else |
| 100 | #error "Unsupported platform" |
| 101 | #endif |
| 102 | |
| 103 | #if CROWN_DEBUG |
| 104 | #define LUAJIT_FLAGS "-bg" // Keep debug info |
| 105 | #else |
| 106 | #define LUAJIT_FLAGS "-b" |
| 107 | #endif |
| 108 | |
| 109 | const char *argv[16]; |
| 110 | |
| 111 | if (opts._platform == Platform::HTML5) { |
| 112 | argv[0] = EXE_PATH("../../" CROWN_32BIT_BIN_DIR "/bin/luac"); |
| 113 | argv[1] = "-o"; |
| 114 | argv[2] = lua_out.c_str(); |
| 115 | argv[3] = lua_src.c_str(); |
| 116 | argv[4] = NULL; |
| 117 | } else { |
| 118 | const char *luajit = EXE_PATH("luajit"); |
| 119 | if (opts._platform == Platform::ANDROID) |
| 120 | luajit = EXE_PATH("../../" CROWN_32BIT_BIN_DIR "/bin/luajit"); |
| 121 | |
| 122 | argv[0] = luajit; |
| 123 | argv[1] = LUAJIT_FLAGS; |
| 124 | argv[2] = lua_src.c_str(); |
| 125 | argv[3] = lua_out.c_str(); |
| 126 | argv[4] = NULL; |
| 127 | } |
| 128 | |
| 129 | Process pr; |
| 130 | s32 sc; |
| 131 | sc = pr.spawn(argv, CROWN_PROCESS_STDOUT_PIPE | CROWN_PROCESS_STDERR_MERGE); |
| 132 | RETURN_IF_FALSE(LUA_RESOURCE, sc == 0 |
| 133 | , opts |
| 134 | , "Failed to spawn `%s`" |
| 135 | , argv[0] |
| 136 | ); |
| 137 | |
| 138 | // Scan the .lua code for requirements. |
| 139 | Buffer lua_code = opts.read(); |
| 140 | HashSet<StringView> requirements(default_allocator()); |
| 141 | lua_resource_internal::find_requirements(requirements, array::begin(lua_code)); |
| 142 | |
| 143 | auto cur = hash_set::begin(requirements); |
| 144 | auto end = hash_set::end(requirements); |