static int l_ffi_layer_begin(knot_layer_t *ctx, void *module_param)
{
    ctx->data = module_param;
    LAYER_FFI_CALL(ctx, "begin");
    lua_pushlightuserdata(L, module_param);
    return l_ffi_call(L, 2);
}
static int l_ffi_init(struct kr_module *module)
{
    lua_State *L = l_ffi_preface(module, "init");
    if (!L) {
        return 0;
    }
    return l_ffi_call(L, 1);
}
static int l_ffi_layer_fail(knot_layer_t *ctx, knot_pkt_t *pkt)
{
    LAYER_FFI_CALL(ctx, "fail");
    lua_pushlightuserdata(L, ctx->data);
    lua_pushlightuserdata(L, pkt);
    set_metatable(L, META_PKT);
    return l_ffi_call(L, 3);
}
Beispiel #4
0
static int l_ffi_layer_finish(knot_layer_t *ctx)
{
	struct kr_request *req = ctx->data;
	LAYER_FFI_CALL(ctx, finish);
	lua_pushlightuserdata(L, req);
	lua_pushlightuserdata(L, req->answer);
	return l_ffi_call(L, 3);
}
Beispiel #5
0
static int l_ffi_layer_produce(knot_layer_t *ctx, knot_pkt_t *pkt)
{
	if (ctx->state & (KNOT_STATE_FAIL)) {
		return ctx->state; /* Already failed or done, skip */
	}
	LAYER_FFI_CALL(ctx, produce);
	lua_pushlightuserdata(L, ctx->data);
	lua_pushlightuserdata(L, pkt);
	return l_ffi_call(L, 3);
}
static int l_ffi_layer_consume(knot_layer_t *ctx, knot_pkt_t *pkt)
{
    if (ctx->state & KNOT_STATE_FAIL) {
        return ctx->state; /* Already failed, skip */
    }
    LAYER_FFI_CALL(ctx, "consume");
    lua_pushlightuserdata(L, ctx->data);
    lua_pushlightuserdata(L, pkt);
    set_metatable(L, META_PKT);
    return l_ffi_call(L, 3);
}
static int l_ffi_deinit(struct kr_module *module)
{
    /* Deinit the module in Lua (if possible) */
    int ret = 0;
    lua_State *L = module->lib;
    if (l_ffi_preface(module, "deinit")) {
        ret = l_ffi_call(L, 1);
    }
    /* Free the layer API wrapper */
    lua_rawgeti(L, LUA_REGISTRYINDEX, (intptr_t)module->data);
    lua_getfield(L, -1, "_layer_capi");
    free(lua_touserdata(L, -1));
    lua_pop(L, 2);
    /* Unref module and unset 'lib', so the module
     * interface doesn't attempt to close it.
     */
    luaL_unref(L, LUA_REGISTRYINDEX, (intptr_t)module->data);
    module->lib = NULL;
    return ret;
}
Beispiel #8
0
static int l_ffi_deinit(struct kr_module *module)
{
	/* Deinit the module in Lua (if possible) */
	int ret = 0;
	lua_State *L = module->lib;
	if (l_ffi_preface(module, "deinit")) {
		ret = l_ffi_call(L, 1);
	}
	/* Free the layer API wrapper (unconst it) */
	knot_layer_api_t* api = module->data;
	if (api) {
		LAYER_UNREGISTER(L, api, begin);
		LAYER_UNREGISTER(L, api, finish);
		LAYER_UNREGISTER(L, api, consume);
		LAYER_UNREGISTER(L, api, produce);
		LAYER_UNREGISTER(L, api, reset);
		free(api);
	}
	module->lib = NULL;
	return ret;
}
static int l_ffi_layer_reset(knot_layer_t *ctx)
{
    LAYER_FFI_CALL(ctx, "reset");
    lua_pushlightuserdata(L, ctx->data);
    return l_ffi_call(L, 2);
}