MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / cliLuaWriteFile

Function cliLuaWriteFile

Source/Basic/Application.cpp:257–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255}
256
257int 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
281int cliLuaListDir(lua_State* L) {
282 auto path = cliGetString(L, 1);

Callers

nothing calls this directly

Calls 12

cliGetStringFunction · 0.85
create_directoriesFunction · 0.85
parent_pathMethod · 0.80
pathClass · 0.50
luaL_checklstringFunction · 0.50
lua_pushbooleanFunction · 0.50
lua_pushstringFunction · 0.50
emptyMethod · 0.45
c_strMethod · 0.45
messageMethod · 0.45
stringMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected