aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-04-25 18:57:53 +1000
committerdaurnimator <quae@daurnimator.com>2017-04-26 21:28:39 +1000
commit31c5b59ab91fa94a62bc958d30060625acff4afe (patch)
tree31f30733b626fd14ce856b9f802703eaed92512a
parent0f8028b68116c05dc0452cce74015b220525cf3c (diff)
downloadfengari-31c5b59ab91fa94a62bc958d30060625acff4afe.tar.gz
fengari-31c5b59ab91fa94a62bc958d30060625acff4afe.tar.bz2
fengari-31c5b59ab91fa94a62bc958d30060625acff4afe.zip
lauxlib: Add luaL_fileresult
-rw-r--r--README.md1
-rw-r--r--src/lauxlib.js18
2 files changed, 18 insertions, 1 deletions
diff --git a/README.md b/README.md
index 578ac7c..a7f6905 100644
--- a/README.md
+++ b/README.md
@@ -45,7 +45,6 @@
- [ ] luaL_dofile
- [ ] luaL_dostring
- [ ] luaL_execresult
- - [ ] luaL_fileresult
- [ ] luaL_gsub
- [ ] luaL_newlibtable
- [ ] luaL_optnumber
diff --git a/src/lauxlib.js b/src/lauxlib.js
index 1df04f0..8bf9a37 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -195,6 +195,23 @@ const luaL_error = function(L, fmt, ...args) {
return lua.lua_error(L);
};
+/* Unlike normal lua, we pass in an error object */
+const luaL_fileresult = function(L, stat, fname, e) {
+ if (stat) {
+ lua.lua_pushboolean(L, 1);
+ return 1;
+ }
+ else {
+ lua.lua_pushnil(L);
+ if (fname)
+ lua.lua_pushstring(L, lua.to_luastring(`${lobject.jsstring(fname)}: ${e.message}`));
+ else
+ lua.lua_pushstring(L, lua.to_luastring(e.message));
+ lua.lua_pushinteger(L, -e.errno);
+ return 3;
+ }
+};
+
const luaL_getmetatable = function(L, n) {
return lua.lua_getfield(L, lua.LUA_REGISTRYINDEX, n);
@@ -697,6 +714,7 @@ module.exports.luaL_checkstring = luaL_checkstring;
module.exports.luaL_checktype = luaL_checktype;
module.exports.luaL_checkudata = luaL_checkudata;
module.exports.luaL_error = luaL_error;
+module.exports.luaL_fileresult = luaL_fileresult;
module.exports.luaL_getmetafield = luaL_getmetafield;
module.exports.luaL_getmetatable = luaL_getmetatable;
module.exports.luaL_getsubtable = luaL_getsubtable;