Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
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 */
    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;
}
Ejemplo n.º 3
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;
}