aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-17 07:51:27 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-17 07:51:27 +0200
commit238106fbfba60a23800c1038ec7b1a04e0682119 (patch)
treecb5045904cc16d091b61f993f3cbab50992a4128
parent3a7f9d85b91530f7f151f536a0aab2455486262d (diff)
parent0422224def06db85f16d24a73b71b8d75e6f74a4 (diff)
downloadfengari-238106fbfba60a23800c1038ec7b1a04e0682119.tar.gz
fengari-238106fbfba60a23800c1038ec7b1a04e0682119.tar.bz2
fengari-238106fbfba60a23800c1038ec7b1a04e0682119.zip
Merge remote-tracking branch 'daurnimator/iolib'
-rw-r--r--README.md8
-rw-r--r--src/liolib.js33
2 files changed, 37 insertions, 4 deletions
diff --git a/README.md b/README.md
index 6d94e2e..75959f2 100644
--- a/README.md
+++ b/README.md
@@ -29,6 +29,7 @@
- [x] Package
- [ ] io
- [x] `file:__tostring()`
+ - [x] `file:flush()`
- [x] `file:write()`
- [x] `io.close()`
- [x] `io.stderr`
@@ -36,15 +37,14 @@
- [x] `io.stdout`
- [x] `io.type()`
- [x] `io.write()`
- - [ ] `io.flush()`
- - [ ] `io.input()`
+ - [x] `io.flush()`
+ - [ ] `io.input()`: partially implemented
- [ ] `io.lines()`
- [ ] `io.open()`
- - [ ] `io.output()`
+ - [ ] `io.output()`: partially implemented
- [ ] `io.popen()`
- [ ] `io.read()`
- [ ] `io.tmpfile()`
- - [ ] `file:flush()`
- [ ] `file:lines()`
- [ ] `file:read()`
- [ ] `file:setvbuf()`
diff --git a/src/liolib.js b/src/liolib.js
index 575b3ec..51e18ee 100644
--- a/src/liolib.js
+++ b/src/liolib.js
@@ -78,6 +78,23 @@ const getiofile = function(L, findex) {
return p.f;
};
+const g_iofile = function(L, f, mode) {
+ if (!lua.lua_isnoneornil(L, 1)) {
+ lauxlib.luaL_error(L, lua.to_luastring("opening files not yet implemented"));
+ }
+ /* return current value */
+ lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, f);
+ return 1;
+};
+
+const io_input = function(L) {
+ return g_iofile(L, IO_INPUT, "r");
+};
+
+const io_output = function(L) {
+ return g_iofile(L, IO_OUTPUT, "w");
+};
+
const g_write = function(L, f, arg) {
let nargs = lua.lua_gettop(L) - arg;
let status = true;
@@ -105,14 +122,30 @@ const f_write = function(L) {
return g_write(L, f, 2);
};
+const io_flush = function (L) {
+ /* stub, as node doesn't have synchronized buffered IO */
+ getiofile(L, IO_OUTPUT);
+ return lauxlib.luaL_fileresult(L, true, null, null);
+};
+
+const f_flush = function (L) {
+ /* stub, as node doesn't have synchronized buffered IO */
+ tofile(L);
+ return lauxlib.luaL_fileresult(L, true, null, null);
+};
+
const iolib = {
"close": io_close,
+ "flush": io_flush,
+ "input": io_input,
+ "output": io_output,
"type": io_type,
"write": io_write
};
const flib = {
"close": io_close,
+ "flush": f_flush,
"write": f_write,
"__tostring": f_tostring
};