| 255 | } |
| 256 | |
| 257 | int cliLuaWriteFile(lua_State* L) { |
| 258 | auto path = fs::path(cliGetString(L, 1)); |
| 259 | size_t len = 0; |
| 260 | auto data = luaL_checklstring(L, 2, &len); |
| 261 | if (auto parent = path.parent_path(); !parent.empty()) { |
| 262 | std::error_code err; |
| 263 | fs::create_directories(parent, err); |
| 264 | if (err) { |
| 265 | lua_pushboolean(L, false); |
| 266 | lua_pushstring(L, err.message().c_str()); |
| 267 | return 2; |
| 268 | } |
| 269 | } |
| 270 | std::ofstream out(path, std::ios::binary); |
| 271 | if (!out) { |
| 272 | lua_pushboolean(L, false); |
| 273 | lua_pushstring(L, ("failed to write file: " + path.string()).c_str()); |
| 274 | return 2; |
| 275 | } |
| 276 | out.write(data, s_cast<std::streamsize>(len)); |
| 277 | lua_pushboolean(L, true); |
| 278 | return 1; |
| 279 | } |
| 280 | |
| 281 | int cliLuaListDir(lua_State* L) { |
| 282 | auto path = cliGetString(L, 1); |
nothing calls this directly
no test coverage detected