fca6cb7f2cfdcc9dcfed711fac16ac8da4e33b10
[project/luci.git] / libs / lucittpd / src / include / lib / luaplugin.h
1 /*
2  * luaplugin - fast lua plugin indexing
3  * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2
7  * as published by the Free Software Foundation
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14 #ifndef __LUAPLUGIN_H
15 #define __LUAPLUGIN_H
16
17 #include <sys/time.h>
18 #include <lualib.h>
19 #include <lauxlib.h>
20 #include <stdbool.h>
21 #include "list.h"
22
23 struct luaplugin_entry {
24         struct luaplugin_ctx *ctx;
25         struct list_head list;
26         time_t timestamp;
27         int checked;
28         bool loaded;
29         bool reload;
30         char *name;
31         char *module;
32
33         /* privdata for the caller */
34         void *priv;
35 };
36
37 struct luaplugin_ctx {
38         const char *path;
39         const struct luaplugin_ops *ops;
40         lua_State *L;
41         int checked;
42         struct list_head *last;
43         struct list_head entries;
44 };
45
46 /** luaplugin_init:
47  * initialize the luaplugin context (allocates a new lua context)
48  */
49 extern int luaplugin_init(struct luaplugin_ctx *ctx, const char *path);
50
51 /** luaplugin_scan:
52  * rescan the plugin cache
53  */
54 extern void luaplugin_scan(struct luaplugin_ctx *ctx);
55
56 /** luaplugin_call:
57  * call out to a lua function.
58  * to be able to use this, you need to push the function name on the lua stack (ctx->L)
59  * and then narg function arguments afterwards.
60  * this call pops (narg + 1) arguments from the stack
61  * returns -ENOENT if the function was not found
62  */
63 extern int luaplugin_call(struct luaplugin_entry *e, int narg);
64
65 /** luaplugin_done:
66  * drop the luaplugin context (and associated lua context)
67  * frees all memory allocated by the library
68  */
69 extern void luaplugin_done(struct luaplugin_ctx *ctx);
70
71 #endif