]> git.decadent.org.uk Git - ion3.git/blob - libextl/luaextl.h
[svn-upgrade] Integrating new upstream version, ion3 (20070506)
[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  * a: ExtlAny
32  */
33
34 typedef int ExtlTab;
35 typedef int ExtlFn;
36
37 typedef union{
38     Obj *o;
39     int i;
40     double d;
41     bool b;
42     const char *s;
43     ExtlFn f;
44     ExtlTab t;
45 } ExtlL2Param;
46
47 typedef struct{
48     char type;
49     ExtlL2Param value;
50 } ExtlAny;
51
52 typedef bool ExtlL2CallHandler(void (*fn)(), ExtlL2Param *in,
53                                ExtlL2Param *out);
54
55 typedef void ExtlExportedFn(void);
56
57 typedef struct{
58     const char *name;
59     ExtlExportedFn *fn;
60     const char *ispec;
61     const char *ospec;
62     ExtlL2CallHandler *l2handler;
63     bool safe;
64     bool untraced;
65     bool registered;
66 } ExtlExportedFnSpec;
67
68 typedef struct ExtlSafelist_struct{
69     int count;
70     struct ExtlSafelist_struct *next, *prev;
71     ExtlExportedFn **list;
72 } ExtlSafelist;
73
74 #define EXTL_SAFELIST_INIT(L) {0, NULL, NULL, L}
75
76 extern ExtlFn extl_unref_fn(ExtlFn ref);
77 extern ExtlTab extl_unref_table(ExtlTab ref);
78 extern ExtlFn extl_fn_none();
79 extern ExtlTab extl_table_none();
80
81 extern bool extl_fn_eq(ExtlFn fn1, ExtlFn fn2);
82 extern bool extl_table_eq(ExtlTab fn1, ExtlTab fn2);
83
84 /* These should be called to store function and table references gotten
85  * as arguments to functions.
86  */
87 extern ExtlFn extl_ref_fn(ExtlFn ref);
88 extern ExtlTab extl_ref_table(ExtlTab ref);
89
90 extern ExtlTab extl_create_table();
91
92 /* Table/get */
93 extern bool extl_table_get_vararg(ExtlTab ref, char itype, char type, 
94                                   va_list *args);
95 extern bool extl_table_get(ExtlTab ref, char itype, char type, ...);
96
97 extern bool extl_table_gets_a(ExtlTab ref, const char *entry, ExtlAny *ret);
98 extern bool extl_table_gets_o(ExtlTab ref, const char *entry, Obj **ret);
99 extern bool extl_table_gets_i(ExtlTab ref, const char *entry, int *ret);
100 extern bool extl_table_gets_d(ExtlTab ref, const char *entry, double *ret);
101 extern bool extl_table_gets_b(ExtlTab ref, const char *entry, bool *ret);
102 extern bool extl_table_gets_s(ExtlTab ref, const char *entry, char **ret);
103 extern bool extl_table_gets_f(ExtlTab ref, const char *entry, ExtlFn *ret);
104 extern bool extl_table_gets_t(ExtlTab ref, const char *entry, ExtlTab *ret);
105
106 extern int extl_table_get_n(ExtlTab ref);
107 extern bool extl_table_geti_a(ExtlTab ref, int entry, ExtlAny *ret);
108 extern bool extl_table_geti_o(ExtlTab ref, int entry, Obj **ret);
109 extern bool extl_table_geti_i(ExtlTab ref, int entry, int *ret);
110 extern bool extl_table_geti_d(ExtlTab ref, int entry, double *ret);
111 extern bool extl_table_geti_b(ExtlTab ref, int entry, bool *ret);
112 extern bool extl_table_geti_s(ExtlTab ref, int entry, char **ret);
113 extern bool extl_table_geti_f(ExtlTab ref, int entry, ExtlFn *ret);
114 extern bool extl_table_geti_t(ExtlTab ref, int entry, ExtlTab *ret);
115
116 /* Table/set */
117 extern bool extl_table_set_vararg(ExtlTab ref, char itype, char type, 
118                                   va_list *args);
119 extern bool extl_table_set(ExtlTab ref, char itype, char type, ...);
120
121 extern bool extl_table_sets_a(ExtlTab ref, const char *entry, const ExtlAny *ret);
122 extern bool extl_table_sets_o(ExtlTab ref, const char *entry, Obj *val);
123 extern bool extl_table_sets_i(ExtlTab ref, const char *entry, int val);
124 extern bool extl_table_sets_d(ExtlTab ref, const char *entry, double val);
125 extern bool extl_table_sets_b(ExtlTab ref, const char *entry, bool val);
126 extern bool extl_table_sets_s(ExtlTab ref, const char *entry, const char *val);
127 extern bool extl_table_sets_f(ExtlTab ref, const char *entry, ExtlFn val);
128 extern bool extl_table_sets_t(ExtlTab ref, const char *entry, ExtlTab val);
129
130 extern bool extl_table_seti_a(ExtlTab ref, int entry, const ExtlAny *ret);
131 extern bool extl_table_seti_o(ExtlTab ref, int entry, Obj *val);
132 extern bool extl_table_seti_i(ExtlTab ref, int entry, int val);
133 extern bool extl_table_seti_d(ExtlTab ref, int entry, double val);
134 extern bool extl_table_seti_b(ExtlTab ref, int entry, bool val);
135 extern bool extl_table_seti_s(ExtlTab ref, int entry, const char *val);
136 extern bool extl_table_seti_f(ExtlTab ref, int entry, ExtlFn val);
137 extern bool extl_table_seti_t(ExtlTab ref, int entry, ExtlTab val);
138
139 /* Table/clear */
140
141 extern bool extl_table_clear_vararg(ExtlTab ref, char itype, va_list *args);
142 extern bool extl_table_clear(ExtlTab ref, char itype, ...);
143
144 extern bool extl_table_clears(ExtlTab ref, const char *entry);
145 extern bool extl_table_cleari(ExtlTab ref, int entry);
146
147 /* Table/iterate */
148
149 typedef bool ExtlIterFn(ExtlAny k, ExtlAny v, void *d);
150
151 extern void extl_table_iter(ExtlTab ref, ExtlIterFn *fn, void *d);
152
153 /* Call */
154
155 extern void extl_protect(ExtlSafelist *sl);
156 extern void extl_unprotect(ExtlSafelist *sl);
157
158 extern bool extl_call_vararg(ExtlFn fnref, const char *spec,
159                              const char *rspec, va_list *args);
160 extern bool extl_call(ExtlFn fnref, const char *spec,
161                       const char *rspec, ...);
162
163 /* Files */
164
165 extern bool extl_loadfile(const char *file, ExtlFn *ret);
166 extern bool extl_loadstring(const char *str, ExtlFn *ret);
167 extern bool extl_serialise(const char *file, ExtlTab tab);
168
169 /* Register */
170
171 extern bool extl_register_function(ExtlExportedFnSpec *spec);
172 extern void extl_unregister_function(ExtlExportedFnSpec *spec);
173 extern bool extl_register_functions(ExtlExportedFnSpec *spec);
174 extern void extl_unregister_functions(ExtlExportedFnSpec *spec);
175
176 bool extl_register_class(const char *cls, ExtlExportedFnSpec *fns,
177                          const char *parent);
178 void extl_unregister_class(const char *cls, ExtlExportedFnSpec *fns);
179
180 bool extl_register_module(const char *cls, ExtlExportedFnSpec *fns);
181 void extl_unregister_module(const char *cls, ExtlExportedFnSpec *fns);
182
183 /* Misc. */
184
185 extern bool extl_init();
186 extern void extl_deinit();
187
188 #endif /* LIBEXTL_LUAEXTL_H */