Skip to content

Commit 9e495cc

Browse files
committed
Fixed file.readAll, fixed #403 (probably)
1 parent cf304ac commit 9e495cc

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/apis/handles/fs_handle.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,15 @@ int fs_handle_readAll(lua_State *L) {
6969
lastCFunction = __func__;
7070
std::iostream * fp = *(std::iostream**)lua_touserdata(L, lua_upvalueindex(1));
7171
if (fp == NULL) return luaL_error(L, "attempt to use a closed file");
72-
if (fp->eof()) return 0;
73-
if (!fp->good()) luaL_error(L, "Could not read file");
72+
if (fp->eof()) {
73+
if (fp->tellg() < 1) return 0;
74+
lua_pushliteral(L, "");
75+
return 1;
76+
}
77+
if (!fp->good()) return 0;
7478
const long pos = (long)fp->tellg();
7579
fp->seekg(0, std::ios::end);
76-
if (!fp->good()) luaL_error(L, "Could not read file");
80+
if (!fp->good()) return 0;
7781
long size = (long)fp->tellg() - pos;
7882
char * retval = new char[size + 1];
7983
memset(retval, 0, size + 1);

src/apis/http.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,12 @@ static int http_request(lua_State *L) {
497497
lua_getfield(L, 1, "body");
498498
if (!lua_isnil(L, -1) && !lua_isstring(L, -1)) {delete param; return luaL_error(L, "bad field 'body' (string expected, got %s)", lua_typename(L, lua_type(L, -1)));}
499499
else if (lua_isstring(L, -1)) param->postData = tostring(L, -1);
500+
else param->postData = "";
500501
lua_pop(L, 1);
501502
lua_getfield(L, 1, "method");
502503
if (!lua_isnil(L, -1) && !lua_isstring(L, -1)) {delete param; return luaL_error(L, "bad field 'method' (string expected, got %s)", lua_typename(L, lua_type(L, -1)));}
503504
else if (lua_isstring(L, -1)) param->method = tostring(L, -1);
505+
else param->method = "";
504506
lua_pop(L, 1);
505507
lua_getfield(L, 1, "redirect");
506508
param->redirect = true;

src/terminal/SDLTerminal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ bool SDLTerminal::resize(unsigned w, unsigned h) {
480480
changed = true;
481481
}
482482
}
483-
while (gotResizeEvent) std::this_thread::yield(); // this should probably be a condition variable
483+
while (gotResizeEvent && (!singleWindowMode || *renderTarget == this)) std::this_thread::yield(); // this should probably be a condition variable
484484
return true;
485485
}
486486

0 commit comments

Comments
 (0)