From 9607137cafdf5fe14dd4f33494eac90774089d8b Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 28 Apr 2017 15:05:28 +0200 Subject: os.rename --- src/loslib.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/loslib.js b/src/loslib.js index 8bf38d9..06abcb6 100644 --- a/src/loslib.js +++ b/src/loslib.js @@ -100,6 +100,17 @@ if (typeof require === "function") { return tmp.tmpNameSync(); }; + const os_rename = function(L) { + let fromname = lua.to_jsstring(lauxlib.luaL_checkstring(L, 1)); + let toname = lua.to_jsstring(lauxlib.luaL_checkstring(L, 2)); + try { + fs.renameSync(fromname, toname); + } catch (e) { + return lauxlib.luaL_fileresult(L, false, false, e); + } + return lauxlib.luaL_fileresult(L, true); + }; + const os_tmpname = function(L) { let name = lua_tmpname(); if (!name) @@ -109,6 +120,7 @@ if (typeof require === "function") { }; syslib.tmpname = os_tmpname; + syslib.rename = os_rename; } } -- cgit v1.2.3-70-g09d2