summaryrefslogtreecommitdiff
path: root/src/liolib.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/liolib.js')
-rw-r--r--src/liolib.js9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/liolib.js b/src/liolib.js
index 51e18ee..a87309a 100644
--- a/src/liolib.js
+++ b/src/liolib.js
@@ -80,7 +80,14 @@ const getiofile = function(L, findex) {
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"));
+ let filename = lua.lua_tostring(L, 1);
+ if (filename)
+ lauxlib.luaL_error(L, lua.to_luastring("opening files not yet implemented"));
+ else {
+ tofile(L); /* check that it's a valid file handle */
+ lua.lua_pushvalue(L, 1);
+ }
+ lua.lua_setfield(L, lua.LUA_REGISTRYINDEX, f);
}
/* return current value */
lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, f);