From 31c5b59ab91fa94a62bc958d30060625acff4afe Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 25 Apr 2017 18:57:53 +1000 Subject: lauxlib: Add luaL_fileresult --- README.md | 1 - src/lauxlib.js | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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; -- cgit v1.2.3-70-g09d2