]> git.decadent.org.uk Git - ion3.git/blob - libextl/luaextl.h
[svn-inject] Installing original source of ion3
[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 } ExtlExportedFnSpec;
60
61 typedef struct ExtlSafelist_struct{
62     int count;
63     struct ExtlSafelist_struct *next, *prev;
64     ExtlExportedFn **list;
65 } ExtlSafelist;
66
67 #define EXTL_SAFELIST_INIT(L) {0, NULL, NULL, L}
68
69 extern ExtlFn extl_unref_fn(ExtlFn ref);
70 extern ExtlTab extl_unref_table(ExtlTab ref);
71 extern ExtlFn extl_fn_none();
72 extern ExtlTab extl_table_none();
73
74 extern bool extl_fn_eq(ExtlFn fn1, ExtlFn fn2);
75 extern bool extl_table_eq(ExtlTab fn1, ExtlTab fn2);
76
77 /* These should be called to store function and table references gotten
78  * as arguments to functions.
79  */
80 extern ExtlFn extl_ref_fn(ExtlFn ref);
81 extern ExtlTab extl_ref_table(ExtlTab ref);
82
83 extern ExtlTab extl_create_table();
84
85 /* Table/get */
86 extern bool extl_table_get_vararg(ExtlTab ref, char itype, char type, 
87                                   va_list *args);
88 extern bool extl_table_get(ExtlTab ref, char itype, char type, ...);
89
90 extern bool extl_table_gets_o(ExtlTab ref, const char *entry, Obj **ret);
91 extern bool extl_table_gets_i(ExtlTab ref, const char *entry, int *ret);
92 extern bool extl_table_gets_d(ExtlTab ref, const char *entry, double *ret);
93 extern bool extl_table_gets_b(ExtlTab ref, const char *entry, bool *ret);
94 extern bool extl_table_gets_s(ExtlTab ref, const char *entry, char **ret);
95 extern bool extl_table_gets_f(ExtlTab ref, const char *entry, ExtlFn *ret);
96 extern bool extl_table_gets_t(ExtlTab ref, const char *entry, ExtlTab *ret);
97
98 extern int extl_table_get_n(ExtlTab ref);
99 extern bool extl_table_geti_o(ExtlTab ref, int entry, Obj **ret);
100 extern bool extl_table_geti_i(ExtlTab ref, int entry, int *ret);
101 extern bool extl_table_geti_d(ExtlTab ref, int entry, double *ret);
102 extern bool extl_table_geti_b(ExtlTab ref, int entry, bool *ret);
103 extern bool extl_table_geti_s(ExtlTab ref, int entry, char **ret);
104 extern bool extl_table_geti_f(ExtlTab ref, int entry, ExtlFn *ret);
105 extern bool extl_table_geti_t(ExtlTab ref, int entry, ExtlTab *ret);
106
107 /* Table/set */
108 extern bool extl_table_set_vararg(ExtlTab ref, char itype, char type, 
109                                   va_list *args);
110 extern bool extl_table_set(ExtlTab ref, char itype, char type, ...);
111
112 extern bool extl_table_sets_o(ExtlTab ref, const char *entry, Obj *val);
113 extern bool extl_table_sets_i(ExtlTab ref, const char *entry, int val);
114 extern bool extl_table_sets_d(ExtlTab ref, const char *entry, double val);
115 extern bool extl_table_sets_b(ExtlTab ref, const char *entry, bool val);
116 extern bool extl_table_sets_s(ExtlTab ref, const char *entry, const char *val);
117 extern bool extl_table_sets_f(ExtlTab ref, const char *entry, ExtlFn val);
118 extern bool extl_table_sets_t(ExtlTab ref, const char *entry, ExtlTab val);
119
120 extern bool extl_table_seti_o(ExtlTab ref, int entry, Obj *val);
121 extern bool extl_table_seti_i(ExtlTab ref, int entry, int val);
122 extern bool extl_table_seti_d(ExtlTab ref, int entry, double val);
123 extern bool extl_table_seti_b(ExtlTab ref, int entry, bool val);
124 extern bool extl_table_seti_s(ExtlTab ref, int entry, const char *val);
125 extern bool extl_table_seti_f(ExtlTab ref, int entry, ExtlFn val);
126 extern bool extl_table_seti_t(ExtlTab ref, int entry, ExtlTab val);
127
128 /* Table/clear */
129
130 extern bool extl_table_clear_vararg(ExtlTab ref, char itype, va_list *args);
131 extern bool extl_table_clear(ExtlTab ref, char itype, ...);
132
133 extern bool extl_table_clears(ExtlTab ref, const char *entry);
134 extern bool extl_table_cleari(ExtlTab ref, int entry);
135
136 /* Call */
137
138 extern void extl_protect(ExtlSafelist *sl);
139 extern void extl_unprotect(ExtlSafelist *sl);
140
141 extern bool extl_call_vararg(ExtlFn fnref, const char *spec,
142                              const char *rspec, va_list *args);
143 extern bool extl_call(ExtlFn fnref, const char *spec,
144                       const char *rspec, ...);
145
146 /* Files */
147
148 extern bool extl_loadfile(const char *file, ExtlFn *ret);
149 extern bool extl_loadstring(const char *str, ExtlFn *ret);
150 extern bool extl_serialise(const char *file, ExtlTab tab);
151
152 /* Register */
153
154 extern bool extl_register_function(ExtlExportedFnSpec *spec);
155 extern void extl_unregister_function(ExtlExportedFnSpec *spec);
156 extern bool extl_register_functions(ExtlExportedFnSpec *spec);
157 extern void extl_unregister_functions(ExtlExportedFnSpec *spec);
158
159 bool extl_register_class(const char *cls, ExtlExportedFnSpec *fns,
160                          const char *parent);
161 void extl_unregister_class(const char *cls, ExtlExportedFnSpec *fns);
162
163 bool extl_register_module(const char *cls, ExtlExportedFnSpec *fns);
164 void extl_unregister_module(const char *cls, ExtlExportedFnSpec *fns);
165
166 /* Misc. */
167
168 extern bool extl_init();
169 extern void extl_deinit();
170
171 #endif /* LIBEXTL_LUAEXTL_H */