Add error reporting to redbean Slurp (#268)

This should allow `content = assert(Slurp(filename))` to work as
expected and report an error if file doesn't exist or can't be read.
This commit is contained in:
Paul Kulchenko 2021-09-06 08:21:37 -07:00 committed by GitHub
parent 44c87b83ff
commit 1eed7d47bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4639,12 +4639,18 @@ static int LuaEncodeLatin1(lua_State *L) {
}
static int LuaSlurp(lua_State *L) {
char *p;
char *p, *f;
size_t n;
p = xslurp(luaL_checkstring(L, 1), &n);
lua_pushlstring(L, p, n);
free(p);
return 1;
f = luaL_checkstring(L, 1);
if ((p = xslurp(f, &n))) {
lua_pushlstring(L, p, n);
free(p);
return 1;
} else {
lua_pushnil(L);
lua_pushstring(L, gc(xasprintf("Can't slurp file %`'s: %m", f)));
return 2;
}
}
static int LuaIndentLines(lua_State *L) {