diff options
-rw-r--r-- | life.tlv | 17 | ||||
-rw-r--r-- | src/liolib.c | 28 |
2 files changed, 5 insertions, 40 deletions
diff --git a/life.tlv b/life.tlv index ed95760..245981e 100644 --- a/life.tlv +++ b/life.tlv @@ -161,21 +161,12 @@ > end >end - __teliva_timestamp: original - file_exists: - >function file_exists(filename) - > local f = io.open(filename, "r") - > if f ~= nil then - > io.close(f) - > return true - > else - > return false - > end - >end -- __teliva_timestamp: original load_file: >function load_file(window, filename) + > local infile = io.open(filename, 'r') + > if infile == nil then return end > local line_index = lines - > for line in io.lines(filename) do + > for line in infile:lines() do > if line:sub(1,1) ~= '!' then -- comment; plaintext files can't have whitespace before comments > local col_index = cols > for c in line:gmatch(".") do @@ -286,7 +277,7 @@ > grid[8][5] = 1 > grid[7][4] = 1 > grid[6][3] = 1 - > elseif file_exists(arg[1]) then + > else > -- Load a file in the standard "plaintext" format: https://www.conwaylife.com/wiki/Plaintext > -- > -- Each pattern page at https://www.conwaylife.com/wiki provides its diff --git a/src/liolib.c b/src/liolib.c index 82598b6..e85b097 100644 --- a/src/liolib.c +++ b/src/liolib.c @@ -38,12 +38,6 @@ static int pushresult (lua_State *L, int i, const char *filename) { } -static void fileerror (lua_State *L, int arg, const char *filename) { - lua_pushfstring(L, "%s: %s", filename, strerror(errno)); - luaL_argerror(L, arg, lua_tostring(L, -1)); -} - - #define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) @@ -171,26 +165,6 @@ static int f_lines (lua_State *L) { } -static int io_lines (lua_State *L) { - const char *filename = luaL_checkstring(L, 1); - FILE **pf = newfile(L); - static char buffer[1024] = {0}; - memset(buffer, '\0', 1024); - snprintf(buffer, 1020, "io.lines(\"%s\")", filename); - append_to_audit_log(L, buffer); - if (file_operation_permitted(caller(L), filename, "r")) - *pf = fopen(filename, "r"); - else { - snprintf(iolib_errbuf, 1024, "app tried to open file '%s'; adjust its permissions (ctrl-p) if that is expected", filename); - Previous_message = iolib_errbuf; - } - if (*pf == NULL) - fileerror(L, 1, filename); - aux_lines(L, lua_gettop(L), 1); - return 1; -} - - /* ** {====================================================== ** READ @@ -393,7 +367,7 @@ static const luaL_Reg iolib[] = { {"close", io_close}, /* no 'flush' since Teliva is ncurses-based */ /* no 'input' since Teliva is ncurses-based */ - {"lines", io_lines}, + /* no 'io.lines'; it can confusingly fail without showing sandboxing errors */ {"open", io_open}, /* no 'output' since Teliva is ncurses-based */ /* no 'popen' without sandboxing it */ |