1 /* -*- mode: C; indent-tabs-mode: t; tab-width: 8; c-basic-offset: 2; -*- */
4 * This file is part of Seed, the GObject Introspection<->Javascript bindings.
6 * Seed is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation, either version 3 of
9 * the License, or (at your option) any later version.
10 * Seed is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with Seed. If not, see <http://www.gnu.org/licenses/>.
17 * Copyright (C) Robert Carr 2009 <carrr@rpi.edu>
21 #include <glib-object.h>
22 #include <girepository.h>
27 typedef gpointer SeedString;
28 typedef gpointer SeedValue;
29 typedef gpointer SeedObject;
30 typedef gpointer SeedClass;
31 typedef gpointer SeedException;
33 typedef gpointer SeedContext;
34 typedef gpointer SeedGlobalContext;
35 typedef gpointer SeedContextGroup;
49 SEED_PROPERTY_ATTRIBUTE_NONE = 0,
50 SEED_PROPERTY_ATTRIBUTE_READ_ONLY = 1 << 1,
51 SEED_PROPERTY_ATTRIBUTE_DONT_ENUM = 1 << 2,
52 SEED_PROPERTY_ATTRIBUTE_DONT_DELETE = 1 << 3
53 } SeedPropertyAttributes;
57 SEED_CLASS_ATTRIBUTE_NONE = 0,
58 SEED_CLASS_ATTRIBUTE_NO_SHARED_PROTOTYPE = 1 << 1
59 } SeedClassAttributes;
61 typedef struct _SeedScript SeedScript;
63 typedef struct _SeedEngine
65 SeedGlobalContext context;
69 SeedContextGroup group;
75 SeedEngine *seed_init (gint *argc, gchar ***argv);
76 SeedEngine *seed_init_with_context_group (gint *argc, gchar ***argv,
77 SeedContextGroup group);
79 void seed_engine_destroy (SeedEngine *eng);
81 SeedValue seed_simple_evaluate (SeedContext ctx,
83 SeedException *exception);
85 SeedScript *seed_make_script (SeedContext ctx,
87 const gchar * source_url,
89 SeedScript *seed_script_new_from_file (SeedContext ctx, gchar * file);
90 SeedException seed_script_exception (SeedScript * s);
91 void seed_script_destroy (SeedScript *s);
92 void seed_make_exception (SeedContext ctx, SeedException exception,
93 const gchar * name, const gchar * message, ...) G_GNUC_PRINTF (4,5);
94 gchar *seed_exception_get_name (SeedContext ctx, SeedException exception);
95 gchar *seed_exception_get_message (SeedContext ctx, SeedException exception);
96 guint seed_exception_get_line (SeedContext ctx, SeedException exception);
97 gchar *seed_exception_get_file (SeedContext ctx, SeedException exception);
98 gchar *seed_exception_to_string (SeedContext ctx, SeedException exception);
100 SeedValue seed_evaluate (SeedContext ctx, SeedScript * s, SeedObject this);
102 GOptionGroup * seed_get_option_group (void);
108 SeedGlobalContext seed_context_create (SeedContextGroup group,
109 SeedClass global_class);
110 SeedGlobalContext seed_context_ref (SeedGlobalContext ctx);
111 void seed_context_unref (SeedGlobalContext ctx);
112 void seed_context_collect (SeedGlobalContext ctx);
114 SeedObject seed_context_get_global_object (SeedContext ctx);
116 void seed_importer_add_global(SeedContext ctx, gchar *name);
117 void seed_importer_set_search_path (SeedContext ctx,
118 gchar **search_path);
119 void seed_prepare_global_context (SeedContext ctx);
123 SeedValue seed_make_null (SeedContext ctx);
124 SeedValue seed_make_undefined (SeedContext ctx);
126 SeedString seed_string_ref (SeedString string);
127 void seed_string_unref (SeedString string);
129 gsize seed_string_get_maximum_size (SeedString string);
130 gsize seed_string_to_utf8_buffer (SeedString string, gchar * buffer,
133 gboolean seed_string_is_equal (SeedString a, SeedString b);
134 gboolean seed_string_is_equal_utf8 (SeedString a, const gchar * b);
136 gboolean seed_value_is_null (SeedContext ctx, SeedValue value);
137 gboolean seed_value_is_undefined (SeedContext ctx, SeedValue value);
138 gboolean seed_value_is_object (SeedContext ctx, SeedValue value);
139 gboolean seed_value_is_object_of_class (SeedContext ctx, SeedValue value, SeedClass klass);
140 gboolean seed_value_is_function (SeedContext ctx, SeedObject value);
141 gboolean seed_value_is_string (SeedContext ctx, SeedValue value);
142 gboolean seed_value_is_number (SeedContext ctx, SeedValue value);
144 void seed_value_unprotect (SeedContext ctx, SeedValue value);
145 void seed_value_protect (SeedContext ctx, SeedValue value);
147 gboolean seed_value_to_boolean (SeedContext ctx,
148 SeedValue val, SeedException * exception);
150 SeedValue seed_value_from_boolean (SeedContext ctx,
151 gboolean val, SeedException * exception);
153 guint seed_value_to_uint (SeedContext ctx,
154 SeedValue val, SeedException * exception);
156 SeedValue seed_value_from_uint (SeedContext ctx,
157 guint val, SeedException * exception);
159 gint seed_value_to_int (SeedContext ctx,
160 SeedValue val, SeedException * exception);
162 SeedValue seed_value_from_int (SeedContext ctx,
163 gint val, SeedException * exception);
165 gchar seed_value_to_char (SeedContext ctx,
166 SeedValue val, SeedException * exception);
167 SeedValue seed_value_from_char (SeedContext ctx,
168 gchar val, SeedException * exception);
170 guchar seed_value_to_uchar (SeedContext ctx,
171 SeedValue val, SeedException * exception);
172 SeedValue seed_value_from_uchar (SeedContext ctx,
173 guchar val, SeedException * exception);
175 glong seed_value_to_long (SeedContext ctx,
176 SeedValue val, SeedException * exception);
177 SeedValue seed_value_from_long (SeedContext ctx,
178 glong val, SeedException * exception);
180 gulong seed_value_to_ulong (SeedContext ctx,
181 SeedValue val, SeedException * exception);
182 SeedValue seed_value_from_ulong (SeedContext ctx,
183 gulong val, SeedException * exception);
185 gint64 seed_value_to_int64 (SeedContext ctx,
186 SeedValue val, SeedException * exception);
187 SeedValue seed_value_from_int64 (SeedContext ctx,
188 gint64 val, SeedException * exception);
190 guint64 seed_value_to_uint64 (SeedContext ctx,
191 SeedValue val, SeedException * exception);
192 SeedValue seed_value_from_uint64 (SeedContext ctx,
193 guint64 val, SeedException * exception);
195 gfloat seed_value_to_float (SeedContext ctx,
196 SeedValue val, SeedException * exception);
197 SeedValue seed_value_from_float (SeedContext ctx,
198 gfloat val, SeedException * exception);
200 gdouble seed_value_to_double (SeedContext ctx,
201 SeedValue val, SeedException * exception);
202 SeedValue seed_value_from_double (SeedContext ctx,
203 gdouble val, SeedException * exception);
205 gchar *seed_value_to_string (SeedContext ctx,
206 SeedValue val, SeedException * exception);
207 SeedValue seed_value_from_string (SeedContext ctx,
208 const gchar * val, SeedException * exception);
210 gchar *seed_value_to_filename (SeedContext ctx,
211 SeedValue val, SeedValue *exception);
212 SeedValue seed_value_from_filename (SeedContext ctx,
213 SeedValue val, SeedValue *exception);
215 SeedValue seed_value_from_binary_string (SeedContext ctx,
218 SeedException *exception);
220 SeedType seed_value_get_type (SeedContext ctx, SeedValue value);
223 seed_value_to_format (SeedContext ctx,
226 SeedValue *exception,
229 typedef SeedObject (*SeedModuleInitCallback) (SeedEngine * eng);
231 gboolean seed_object_set_property (SeedContext ctx,
233 const gchar * name, SeedValue value);
234 SeedValue seed_object_get_property (SeedContext ctx,
235 SeedObject object, const gchar * name);
237 void seed_object_set_property_at_index (SeedContext ctx,
241 SeedException * exception);
243 SeedValue seed_object_get_property_at_index (SeedContext ctx,
246 SeedException *exception);
248 SeedValue seed_object_call (SeedContext ctx,
251 gsize argument_count,
252 const SeedValue arguments[],
253 SeedException * exception);
255 GObject *seed_value_to_object (SeedContext ctx,
256 SeedValue val, SeedException * exception);
257 SeedValue seed_value_from_object (SeedContext ctx,
258 GObject * val, SeedException * exception);
260 SeedObject seed_make_object (SeedContext ctx, SeedClass class,
263 gpointer seed_object_get_private (SeedObject object);
264 void seed_object_set_private (SeedObject object, gpointer value);
266 gchar **seed_object_copy_property_names(SeedContext ctx, SeedObject object);
268 gpointer seed_pointer_get_pointer (SeedContext ctx, SeedValue pointer);
271 seed_object_get_prototype (SeedContext ctx, SeedObject obj);
274 seed_object_is_of_class (SeedContext ctx, SeedObject obj, SeedClass class);
276 SeedValue seed_make_pointer (SeedContext ctx, gpointer pointer);
278 typedef SeedValue (*SeedFunctionCallback) (SeedContext ctx,
280 SeedObject this_object,
281 gsize argument_count,
282 const SeedValue arguments[],
283 SeedException * exception);
285 void seed_create_function (SeedContext ctx,
286 gchar * name, SeedFunctionCallback func,
288 SeedObject seed_make_function (SeedContext ctx, SeedFunctionCallback func, const gchar *name);
291 SeedObject seed_make_array (SeedContext ctx, const SeedValue elements,
292 gsize num_elements, SeedException *exception);
296 typedef void (*SeedObjectInitializeCallback) (SeedContext ctx,
299 /* Using any functions that require a context from
300 *this callback has undefined results */
301 typedef void (*SeedObjectFinalizeCallback) (SeedObject object);
303 typedef gboolean (*SeedObjectHasPropertyCallback) (SeedContext ctx,
306 typedef SeedValue (*SeedObjectGetPropertyCallback) (SeedContext ctx,
308 SeedString property_name,
310 typedef gboolean (*SeedObjectSetPropertyCallback) (SeedContext ctx,
312 SeedString property_name,
315 typedef gboolean (*SeedObjectDeletePropertyCallback) (SeedContext ctx,
321 /* TODO: Have to decide on accumulator API
322 //typedef void (*SeedObjectGetPropertyNamesCallback) (SeedContext ctx, */
324 typedef void (*SeedObjectGetPropertyNamesCallback) (void);
326 typedef SeedValue (*SeedObjectCallAsFunctionCallback) (SeedContext ctx,
328 SeedObject this_object,
329 gsize argument_count,
334 typedef SeedValue (*SeedObjectCallAsConstructorCallback) (SeedContext ctx,
344 typedef gboolean (*SeedObjectHasInstanceCallback) (SeedContext ctx,
345 SeedObject constructor,
346 SeedObject instance_p,
347 SeedException * exception);
349 typedef SeedValue (*SeedObjectConvertToTypeCallback) (SeedContext ctx,
355 typedef struct _seed_static_value
357 const gchar *const name;
358 SeedObjectGetPropertyCallback get_property;
359 SeedObjectSetPropertyCallback set_property;
360 SeedPropertyAttributes attributes;
363 typedef struct _seed_static_function
365 const gchar *const name;
366 SeedObjectCallAsFunctionCallback callback;
367 SeedPropertyAttributes attributes;
368 } seed_static_function;
370 typedef struct _seed_class_definition
372 int version; /* Always 0 */
373 SeedClassAttributes attributes;
375 const gchar *class_name;
376 SeedClass parent_class;
378 const seed_static_value *static_values;
379 const seed_static_function *static_functions;
381 SeedObjectInitializeCallback initialize;
382 SeedObjectFinalizeCallback finalize;
383 SeedObjectHasPropertyCallback has_property;
384 SeedObjectGetPropertyCallback get_property;
385 SeedObjectSetPropertyCallback set_property;
386 SeedObjectDeletePropertyCallback delete_property;
387 SeedObjectGetPropertyNamesCallback get_property_names;
388 SeedObjectCallAsFunctionCallback call_as_function;
389 SeedObjectCallAsConstructorCallback call_as_constructor;
390 SeedObjectHasInstanceCallback has_instance;
391 SeedObjectConvertToTypeCallback convert_to_type;
392 } seed_class_definition;
394 #define seed_empty_class { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
396 SeedClass seed_create_class (seed_class_definition * def);
398 SeedObject seed_make_constructor (SeedContext ctx,
400 SeedObjectCallAsConstructorCallback constructor);
402 void seed_engine_set_search_path (SeedEngine * eng, const gchar * path);
403 gchar **seed_engine_get_search_path (SeedEngine * eng);
406 seed_signal_connect (SeedContext ctx,
409 const gchar *script);
412 seed_signal_connect_value (SeedContext ctx,
416 SeedValue user_data);
418 GClosure *seed_closure_new (SeedContext ctx,
420 SeedObject user_data,
421 const gchar *description);
425 seed_closure_get_callable (GClosure *c);
428 seed_closure_invoke (GClosure *closure, SeedValue *args, guint argc, SeedException *exception);
431 seed_closure_invoke_with_context (SeedContext ctx, GClosure *closure, SeedValue *args, guint argc, SeedException *exception);
434 seed_closure_warn_exception (GClosure *c, SeedContext ctx, SeedException exception);