aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-21 22:41:17 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-21 23:53:52 +1000
commitcc3e3c93585d81304954131a9a3982f0786426b7 (patch)
tree27d8728e8b96e9f37255f8169f8bd8d53ad9778d
parent1dc341ee119d6a997df9978be5d6eeb91fe11939 (diff)
downloadfengari-cc3e3c93585d81304954131a9a3982f0786426b7.tar.gz
fengari-cc3e3c93585d81304954131a9a3982f0786426b7.tar.bz2
fengari-cc3e3c93585d81304954131a9a3982f0786426b7.zip
src/liolib.js: Do more argument checking before bailing out of opening a file
-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);