| 14 | // *********************************************************************** |
| 15 | |
| 16 | bool WriteLuaTableToFile(lua_State* L, u8 format, String output) { |
| 17 | // we assume the table to be written out is on the top of the stack |
| 18 | lua_getglobal(L, "serialize"); |
| 19 | lua_pushvalue(L, -2); // copy the table |
| 20 | lua_pushnumber(L, format); |
| 21 | lua_pcall(L, 2, 1, 0); |
| 22 | { |
| 23 | String result; |
| 24 | size_t len; |
| 25 | result.pData = (char*)lua_tolstring(L, -1, &len); |
| 26 | result.length = (i64)len; |
| 27 | |
| 28 | if (WriteWholeFile(output, result.pData, result.length)) { |
| 29 | Log::Info(" Exported %S", output); |
| 30 | } |
| 31 | else { |
| 32 | Log::Info(" Failed to export %S, is the path correct?", output); |
| 33 | return false; |
| 34 | } |
| 35 | } |
| 36 | return true; |
| 37 | } |
| 38 | |
| 39 | // *********************************************************************** |
| 40 | |