Beispiel #1
0
static liHandlerResult filter_lua_handle(liVRequest *vr, liFilter *f) {
	liServer *srv = NULL != vr ? vr->wrk->srv : NULL;
	filter_lua_state *state = (filter_lua_state*) f->param;
	lua_State *L = state->LL->L;
	liHandlerResult res;

	li_lua_lock(state->LL);

	lua_rawgeti(L, LUA_REGISTRYINDEX, state->object_ref); /* +1 */
	li_lua_push_vrequest(L, vr); /* +1 */
	li_lua_push_chunkqueue(L, f->out); /* +1 */
	li_lua_push_chunkqueue(L, f->in); /* +1 */
	if (li_lua_call_object(srv, vr, L, "handle", 4, 1, FALSE)) { /* -4, +1 on success */
		res = LI_HANDLER_GO_ON;
		if (!lua_isnil(L, -1)) {
			int rc = lua_tointeger(L, -1);
			switch (rc) {
			case LI_HANDLER_GO_ON:
			case LI_HANDLER_COMEBACK:
			case LI_HANDLER_WAIT_FOR_EVENT:
			case LI_HANDLER_ERROR:
				res = rc;
				break;
			default:
				VR_ERROR(vr, "lua filter returned an error or an unknown value (%i)", rc);
				res = LI_HANDLER_ERROR;
			}
		}
		lua_pop(L, 1);
	} else {
		res = LI_HANDLER_ERROR;
	}

	li_lua_unlock(state->LL);

	return res;
}
Beispiel #2
0
static int lua_filter_attr_read_out(liFilter *f, lua_State *L) {
	li_lua_push_chunkqueue(L, f->out);
	return 1;
}
Beispiel #3
0
static int lua_vrequest_attr_read_out(liVRequest *vr, lua_State *L) {
	li_lua_push_chunkqueue(L, vr->out);
	return 1;
}