aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-04-26 23:30:30 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-03 18:28:22 +1000
commit9a24308b0f8bb04d533d9abae39bd7546cf92377 (patch)
tree1afc612de03c8c8fc9b4080588713806f074f577 /src
parent56b5adb7f3683cd9e88f8d2cabd885e49a3d2398 (diff)
downloadfengari-9a24308b0f8bb04d533d9abae39bd7546cf92377.tar.gz
fengari-9a24308b0f8bb04d533d9abae39bd7546cf92377.tar.bz2
fengari-9a24308b0f8bb04d533d9abae39bd7546cf92377.zip
src/iolib.js: Add file:__tostring()
Diffstat (limited to 'src')
-rw-r--r--src/liolib.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/liolib.js b/src/liolib.js
index 247baef..f753f91 100644
--- a/src/liolib.js
+++ b/src/liolib.js
@@ -12,6 +12,19 @@ const tolstream = function(L) {
return lauxlib.luaL_checkudata(L, 1, lauxlib.LUA_FILEHANDLE);
};
+const isclosed = function(p) {
+ return p.closef === null;
+};
+
+const f_tostring = function(L) {
+ let p = tolstream(L);
+ if (isclosed(p))
+ lua.lua_pushliteral(L, "file (closed)");
+ else
+ lua.lua_pushstring(L, lua.to_luastring(`file (${p.f.toString()})`));
+ return 1;
+};
+
const newprefile = function(L) {
let p = lua.lua_newuserdata(L);
p.f = null;
@@ -24,6 +37,7 @@ const iolib = {
};
const flib = {
+ "__tostring": f_tostring
};
const createmeta = function(L) {