summaryrefslogtreecommitdiffstats
path: root/daemon/ffimodule.h
blob: beb1bf122493e636ef63e1d4bcc62a42f159a82e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*  Copyright (C) CZ.NIC, z.s.p.o. <knot-resolver@labs.nic.cz>
 *  SPDX-License-Identifier: GPL-3.0-or-later
 */

#pragma once

#include "lib/defines.h"
#include "lib/layer.h"
#include <lua.h>
struct engine;
struct kr_module;

/**
 * Register Lua module as a FFI module.
 * This fabricates a standard module interface,
 * that trampolines to the Lua module methods.
 *
 * @note Lua module is loaded in it's own coroutine,
 *       so it's possible to yield and resume at arbitrary
 *       places except deinit()
 *
 * @param  engine daemon engine
 * @param  module prepared module
 * @param  name   module name
 * @return        0 or an error
 */
int ffimodule_register_lua(struct engine *engine, struct kr_module *module, const char *name);

int ffimodule_init(lua_State *L);
void ffimodule_deinit(lua_State *L);

/** Static storage for faster passing of layer function parameters to lua callbacks.
 *
 * We don't need to declare it in a header, but let's give it visibility. */
KR_EXPORT extern kr_layer_t kr_layer_t_static;