Rebasing against master

Mostly to pick up the changes in the way paths now have a tryhandler, which will slightly change the way we want to call the Lua handler.
This commit is contained in:
James Milne 2021-04-11 13:09:04 +10:00
parent 4effa23528
commit a20a1f6853

View file

@ -2547,6 +2547,13 @@ static int LuaReleaseRegex(lua_State *L) {
return 0;
}
static bool HasLuaHandler() {
bool r = lua_getglobal(L, "Handler") == LUA_TFUNCTION;
lua_pop(L, 1);
return r;
}
static void LuaRun(const char *path) {
struct Asset *a;
const char *code;
@ -2688,6 +2695,29 @@ static void LuaReload(void) {
#endif
}
const char *CallLuaHandler(const char *path, size_t pathlen) {
lua_getglobal(L, "Handler");
char *p;
luaheaderp = NULL;
sauce = FreeLater(strndup(request.path.p + 1, request.path.n - 1));
if(lua_pcall(L, 0, 0, 0) == LUA_OK) {
if (!(p = luaheaderp)) {
p = SetStatus(200, "OK");
p = AppendContentType(p, "text/html");
}
if (outbuf.n) {
p = CommitOutput(p);
}
return p;
} else {
WARNF("%s %s", clientaddrstr, lua_tostring(L, -1));
lua_pop(L, 1); /* remove message */
connectionclose = true;
return ServeError(500, "Internal Server Error");
}
}
static char *ServeLua(struct Asset *a) {
char *p, *code;
luaheaderp = NULL;