aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-28 15:05:28 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-28 15:11:01 +0200
commit9607137cafdf5fe14dd4f33494eac90774089d8b (patch)
tree32f94a4ebc4e4d673f9c3dbc1511cc3a3361dee9
parent51084a2959951aefd416bc3f2f6cd9952616fd16 (diff)
downloadfengari-9607137cafdf5fe14dd4f33494eac90774089d8b.tar.gz
fengari-9607137cafdf5fe14dd4f33494eac90774089d8b.tar.bz2
fengari-9607137cafdf5fe14dd4f33494eac90774089d8b.zip
os.rename
-rw-r--r--README.md4
-rw-r--r--src/loslib.js12
2 files changed, 14 insertions, 2 deletions
diff --git a/README.md b/README.md
index 6e7cf5c..f1ec601 100644
--- a/README.md
+++ b/README.md
@@ -25,16 +25,16 @@
- [ ] Package
- [ ] os
- [x] `os.exit()`
+ - [x] `os.rename()`
- [x] `os.time()`
+ - [x] `os.tmpname()`
- [ ] `os.clock()`
- [ ] `os.date()`
- [ ] `os.difftime()`
- [ ] `os.execute()`
- [ ] `os.getenv()`
- [ ] `os.remove()`
- - [ ] `os.rename()`
- [ ] `os.setlocale()`
- - [ ] `os.tmpname()`
- [ ] io
- [ ] `io.stdin`
- [ ] `io.stdout`
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;
}
}