diff options
author | David Walter Seikel | 2012-02-05 14:09:41 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-02-05 14:09:41 +1000 |
commit | ea300ea32ade8b9dbe8a418b6cfb185b5ee446a0 (patch) | |
tree | 1a5b78a5b2639fcefae810158fb96b319bad2035 | |
parent | Get them in the right order. lol (diff) | |
download | SledjHamr-ea300ea32ade8b9dbe8a418b6cfb185b5ee446a0.zip SledjHamr-ea300ea32ade8b9dbe8a418b6cfb185b5ee446a0.tar.gz SledjHamr-ea300ea32ade8b9dbe8a418b6cfb185b5ee446a0.tar.bz2 SledjHamr-ea300ea32ade8b9dbe8a418b6cfb185b5ee446a0.tar.xz |
Use the internal Lua compile function instead of the external compile program, and actually write the result to a file.
-rw-r--r-- | LuaSL/src/LuaSL_compile.c | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index 140fafa..3da5632 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c | |||
@@ -2130,6 +2130,16 @@ boolean compilerSetup(gameGlobals *game) | |||
2130 | return FALSE; | 2130 | return FALSE; |
2131 | } | 2131 | } |
2132 | 2132 | ||
2133 | static int luaWriter(lua_State *L, const void* p, size_t sz, void* ud) | ||
2134 | { | ||
2135 | FILE *out = ud; | ||
2136 | int result = 0; | ||
2137 | |||
2138 | if (sz != fwrite(p, 1, sz, out)) | ||
2139 | result = -1; | ||
2140 | return result; | ||
2141 | } | ||
2142 | |||
2133 | boolean compileLSL(gameGlobals *game, char *script, boolean doConstants) | 2143 | boolean compileLSL(gameGlobals *game, char *script, boolean doConstants) |
2134 | { | 2144 | { |
2135 | boolean result = FALSE; | 2145 | boolean result = FALSE; |
@@ -2260,6 +2270,9 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants) | |||
2260 | // Generate the Lua source code. | 2270 | // Generate the Lua source code. |
2261 | if (out) | 2271 | if (out) |
2262 | { | 2272 | { |
2273 | lua_State *L; | ||
2274 | int err; | ||
2275 | |||
2263 | fprintf(out, "--// Generated code goes here.\n\n"); | 2276 | fprintf(out, "--// Generated code goes here.\n\n"); |
2264 | fprintf(out, "local _bit = require(\"bit\")\n"); | 2277 | fprintf(out, "local _bit = require(\"bit\")\n"); |
2265 | fprintf(out, "local _LSL = require(\"LSL\")\n\n"); | 2278 | fprintf(out, "local _LSL = require(\"LSL\")\n\n"); |
@@ -2267,12 +2280,39 @@ boolean compileLSL(gameGlobals *game, char *script, boolean doConstants) | |||
2267 | fprintf(out, "\n\n_LSL.stateChange(_defaultState)\n"); // This actually starts the script running. | 2280 | fprintf(out, "\n\n_LSL.stateChange(_defaultState)\n"); // This actually starts the script running. |
2268 | fprintf(out, "\n--// End of generated code.\n\n"); | 2281 | fprintf(out, "\n--// End of generated code.\n\n"); |
2269 | fclose(out); | 2282 | fclose(out); |
2270 | sprintf(buffer, "../../libraries/luajit-2.0/src/luajit \"%s\"", luaName); | 2283 | |
2271 | count = system(buffer); | 2284 | // Compile the Lua source code. |
2272 | if (0 != count) | 2285 | L = luaL_newstate(); |
2286 | luaL_openlibs(L); | ||
2287 | /* This ends up pushing a function onto the stack for a lua_pcall() to use. | ||
2288 | * The function is the compiled code. */ | ||
2289 | err = luaL_loadfile(L, luaName); | ||
2290 | if (err) | ||
2273 | { | 2291 | { |
2274 | compiler.script.bugCount++; | 2292 | compiler.script.bugCount++; |
2275 | PE("Lua compile stage failed for %s!", compiler.fileName); | 2293 | if (LUA_ERRSYNTAX == err) |
2294 | PE("Lua syntax error in %s: %s", luaName, lua_tostring(L, -1)); | ||
2295 | else if (LUA_ERRFILE == err) | ||
2296 | PE("Lua compile file error in %s: %s", luaName, lua_tostring(L, -1)); | ||
2297 | else if (LUA_ERRMEM == err) | ||
2298 | PE("Lua compile memory allocation error in %s: %s", luaName, lua_tostring(L, -1)); | ||
2299 | } | ||
2300 | else | ||
2301 | { | ||
2302 | strcat(luaName, ".lua.out"); | ||
2303 | out = fopen(luaName, "w"); | ||
2304 | if (out) | ||
2305 | { | ||
2306 | err = lua_dump(L, luaWriter, out); | ||
2307 | if (err) | ||
2308 | { | ||
2309 | compiler.script.bugCount++; | ||
2310 | PE("Lua compile file error writing to %s", luaName); | ||
2311 | } | ||
2312 | fclose(out); | ||
2313 | } | ||
2314 | else | ||
2315 | PC("Unable to open file %s for writing!", luaName); | ||
2276 | } | 2316 | } |
2277 | } | 2317 | } |
2278 | else | 2318 | else |