aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-28 15:24:31 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-28 15:24:31 +0200
commit247cd4cc52f48d3d16ad6230eec3b4e94aa03c69 (patch)
tree5aef611534aa3af330eeee03f0f4b543c93470d2
parent9607137cafdf5fe14dd4f33494eac90774089d8b (diff)
downloadfengari-247cd4cc52f48d3d16ad6230eec3b4e94aa03c69.tar.gz
fengari-247cd4cc52f48d3d16ad6230eec3b4e94aa03c69.tar.bz2
fengari-247cd4cc52f48d3d16ad6230eec3b4e94aa03c69.zip
os.remove
-rw-r--r--README.md2
-rw-r--r--src/loslib.js17
2 files changed, 17 insertions, 2 deletions
diff --git a/README.md b/README.md
index f1ec601..98874ec 100644
--- a/README.md
+++ b/README.md
@@ -25,6 +25,7 @@
- [ ] Package
- [ ] os
- [x] `os.exit()`
+ - [x] `os.remove()`
- [x] `os.rename()`
- [x] `os.time()`
- [x] `os.tmpname()`
@@ -33,7 +34,6 @@
- [ ] `os.difftime()`
- [ ] `os.execute()`
- [ ] `os.getenv()`
- - [ ] `os.remove()`
- [ ] `os.setlocale()`
- [ ] io
- [ ] `io.stdin`
diff --git a/src/loslib.js b/src/loslib.js
index 06abcb6..aa868f5 100644
--- a/src/loslib.js
+++ b/src/loslib.js
@@ -100,6 +100,20 @@ if (typeof require === "function") {
return tmp.tmpNameSync();
};
+ const os_remove = function(L) {
+ let filename = lauxlib.luaL_checkstring(L, 1);
+ try {
+ if (fs.lstatSync(lua.to_jsstring(filename)).isDirectory()) {
+ fs.rmdirSync(lua.to_jsstring(filename));
+ } else {
+ fs.unlinkSync(lua.to_jsstring(filename));
+ }
+ } catch (e) {
+ return lauxlib.luaL_fileresult(L, false, filename, e);
+ }
+ return lauxlib.luaL_fileresult(L, true);
+ };
+
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));
@@ -119,8 +133,9 @@ if (typeof require === "function") {
return 1;
};
- syslib.tmpname = os_tmpname;
+ syslib.remove = os_remove;
syslib.rename = os_rename;
+ syslib.tmpname = os_tmpname;
}
}