summaryrefslogtreecommitdiff
path: root/src/liolib.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-16 17:42:11 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-16 17:42:11 +1000
commit0422224def06db85f16d24a73b71b8d75e6f74a4 (patch)
tree260a03a9b02f5321af19907043a9100a67b74ec0 /src/liolib.js
parentb10668ce74316c8965a5b19a8b4365c90f75e17f (diff)
downloadfengari-0422224def06db85f16d24a73b71b8d75e6f74a4.tar.gz
fengari-0422224def06db85f16d24a73b71b8d75e6f74a4.tar.bz2
fengari-0422224def06db85f16d24a73b71b8d75e6f74a4.zip
src/liolib.js: Partial implementation of io.input and io.output
Diffstat (limited to 'src/liolib.js')
-rw-r--r--src/liolib.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/liolib.js b/src/liolib.js
index 6c7d945..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;
@@ -120,6 +137,8 @@ const f_flush = function (L) {
const iolib = {
"close": io_close,
"flush": io_flush,
+ "input": io_input,
+ "output": io_output,
"type": io_type,
"write": io_write
};