summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;