]> git.decadent.org.uk Git - ion3.git/blob - libextl/luaextl.h
f31cc97583c79d3a91382a9a74280a9b22c74821
[ion3.git] / libextl / luaextl.h
1 /*
2  * libextl/luaextl.h
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2005.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  */
11
12 #ifndef LIBEXTL_LUAEXTL_H
13 #define LIBEXTL_LUAEXTL_H
14
15 #include <stdarg.h>
16
17 #include "types.h"
18
19 #define EXTL_EXTENSION "lua"
20 #define EXTL_COMPILED_EXTENSION "lc"
21 #define EXTL_MAX_SERIALISE_DEPTH 128
22
23 /* o: userdata/Obj
24  * i: integer
25  * d: double
26  * b: boolean
27  * s: string
28  * t: table
29  * f: function (c or lua)
30  * v: void
31  */
32
33 typedef int ExtlTab;
34 typedef int ExtlFn;
35
36 typedef union{
37     Obj *o;
38     int i;
39     double d;
40     bool b;
41     const char *s;
42     ExtlFn f;
43     ExtlTab t;
44 } ExtlL2Param;
45
46 typedef bool ExtlL2CallHandler(void (*fn)(), ExtlL2Param *in,
47                                ExtlL2Param *out);
48
49 typedef void ExtlExportedFn(void);
50
51 typedef struct{
52     const char *name;
53     ExtlExportedFn *fn;
54     const char *ispec;
55     const char *ospec;
56     ExtlL2CallHandler *l2handler;
57     bool safe;
58     bool untraced;
59     bool registered;
60 } ExtlExportedFnSpec;
61
62 typedef struct ExtlSafelist_struct{
63     int count;
64     struct ExtlSafelist_struct *next, *prev;
65     ExtlExportedFn **list;
66 } ExtlSafelist;
67
68 #define EXTL_SAFELIST_INIT(L) {0, NULL, NULL, L}
69
70 extern ExtlFn extl_unref_fn(ExtlFn ref);
71 extern ExtlTab extl_unref_table(ExtlTab ref);
72 extern ExtlFn extl_fn_none();
73 extern ExtlTab extl_table_none();
74
75 extern bool extl_fn_eq(ExtlFn fn1, ExtlFn fn2);
76 extern bool extl_table_eq(ExtlTab fn1, ExtlTab fn2);
77
78 /* These should be called to store function and table references gotten
79  * as arguments to functions.
80  */
81 extern ExtlFn extl_ref_fn(ExtlFn ref);
82 extern ExtlTab extl_ref_table(ExtlTab ref);
83
84 extern ExtlTab extl_create_table();
85
86 /* Table/get */
87 extern bool extl_table_get_vararg(ExtlTab ref, char itype, char type, 
88                                   va_list *args);
89 extern bool extl_table_get(ExtlTab ref, char itype, char type, ...);
90
91 extern bool extl_table_gets_o(ExtlTab ref, const char *entry, Obj **ret);
92 extern bool extl_table_gets_i(ExtlTab ref, const char *entry, int *ret);
93 extern bool extl_table_gets_d(ExtlTab ref, const char *entry, double *ret);
94 extern bool extl_table_gets_b(ExtlTab ref, const char *entry, bool *ret);
95 extern bool extl_table_gets_s(ExtlTab ref, const char *entry, char **ret);
96 extern bool extl_table_gets_f(ExtlTab ref, const char *entry, ExtlFn *ret);
97 extern bool extl_table_gets_t(ExtlTab ref, const char *entry, ExtlTab *ret);
98
99 extern int extl_table_get_n(ExtlTab ref);
100 extern bool extl_table_geti_o(ExtlTab ref, int entry, Obj **ret);
101 extern bool extl_table_geti_i(ExtlTab ref, int entry, int *ret);
102 extern bool extl_table_geti_d(ExtlTab ref, int entry, double *ret);
103 extern bool extl_table_geti_b(ExtlTab ref, int entry, bool *ret);
104 extern bool extl_table_geti_s(ExtlTab ref, int entry, char **ret);
105 extern bool extl_table_geti_f(ExtlTab ref, int entry, ExtlFn *ret);
106 extern bool extl_table_geti_t(ExtlTab ref, int entry, ExtlTab *ret);
107
108 /* Table/set */
109 extern bool extl_table_set_vararg(ExtlTab ref, char itype, char type, 
110                                   va_list *args);
111 extern bool extl_table_set(ExtlTab ref, char itype, char type, ...);
112
113 extern bool extl_table_sets_o(ExtlTab ref, const char *entry, Obj *val);
114 extern bool extl_table_sets_i(ExtlTab ref, const char *entry, int val);
115 extern bool extl_table_sets_d(ExtlTab ref, const char *entry, double val);
116 extern bool extl_table_sets_b(ExtlTab ref, const char *entry, bool val);
117 extern bool extl_table_sets_s(ExtlTab ref, const char *entry, const char *val);
118 extern bool extl_table_sets_f(ExtlTab ref, const char *entry, ExtlFn val);
119 extern bool extl_table_sets_t(ExtlTab ref, const char *entry, ExtlTab val);
120
121 extern bool extl_table_seti_o(ExtlTab ref, int entry, Obj *val);
122 extern bool extl_table_seti_i(ExtlTab ref, int entry, int val);
123 extern bool extl_table_seti_d(ExtlTab ref, int entry, double val);
124 extern bool extl_table_seti_b(ExtlTab ref, int entry, bool val);
125 extern bool extl_table_seti_s(ExtlTab ref, int entry, const char *val);
126 extern bool extl_table_seti_f(ExtlTab ref, int entry, ExtlFn val);
127 extern bool extl_table_seti_t(ExtlTab ref, int entry, ExtlTab val);
128
129 /* Table/clear */
130
131 extern bool extl_table_clear_vararg(ExtlTab ref, char itype, va_list *args);
132 extern bool extl_table_clear(ExtlTab ref, char itype, ...);
133
134 extern bool extl_table_clears(ExtlTab ref, const char *entry);
135 extern bool extl_table_cleari(ExtlTab ref, int entry);
136
137 /* Call */
138
139 extern void extl_protect(ExtlSafelist *sl);
140 extern void extl_unprotect(ExtlSafelist *sl);
141
142 extern bool extl_call_vararg(ExtlFn fnref, const char *spec,
143                              const char *rspec, va_list *args);
144 extern bool extl_call(ExtlFn fnref, const char *spec,
145                       const char *rspec, ...);
146
147 /* Files */
148
149 extern bool extl_loadfile(const char *file, ExtlFn *ret);
150 extern bool extl_loadstring(const char *str, ExtlFn *ret);
151 extern bool extl_serialise(const char *file, ExtlTab tab);
152
153 /* Register */
154
155 extern bool extl_register_function(ExtlExportedFnSpec *spec);
156 extern void extl_unregister_function(ExtlExportedFnSpec *spec);
157 extern bool extl_register_functions(ExtlExportedFnSpec *spec);
158 extern void extl_unregister_functions(ExtlExportedFnSpec *spec);
159
160 bool extl_register_class(const char *cls, ExtlExportedFnSpec *fns,
161                          const char *parent);
162 void extl_unregister_class(const char *cls, ExtlExportedFnSpec *fns);
163
164 bool extl_register_module(const char *cls, ExtlExportedFnSpec *fns);
165 void extl_unregister_module(const char *cls, ExtlExportedFnSpec *fns);
166
167 /* Misc. */
168
169 extern bool extl_init();
170 extern void extl_deinit();
171
172 #endif /* LIBEXTL_LUAEXTL_H */