2 * Copyright (C) 2007-2008 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
20 #ifndef _SWFDEC_AS_OBJECT_H_
21 #define _SWFDEC_AS_OBJECT_H_
23 #include <glib-object.h>
24 #include <swfdec/swfdec_as_types.h>
25 #include <swfdec/swfdec_gc_object.h>
29 /* NB: matches ASSetPropFlags */
31 SWFDEC_AS_VARIABLE_HIDDEN
= (1 << 0),
32 SWFDEC_AS_VARIABLE_PERMANENT
= (1 << 1),
33 SWFDEC_AS_VARIABLE_CONSTANT
= (1 << 2),
35 SWFDEC_AS_VARIABLE_VERSION_6_UP
= (1 << 7),
36 SWFDEC_AS_VARIABLE_VERSION_NOT_6
= (1 << 8),
37 SWFDEC_AS_VARIABLE_VERSION_7_UP
= (1 << 10),
38 SWFDEC_AS_VARIABLE_VERSION_8_UP
= (1 << 12),
39 SWFDEC_AS_VARIABLE_VERSION_9_UP
= (1 << 13),
40 } SwfdecAsVariableFlag
;
43 SWFDEC_AS_DELETE_NOT_FOUND
= 0,
44 SWFDEC_AS_DELETE_DELETED
,
45 SWFDEC_AS_DELETE_NOT_DELETED
46 } SwfdecAsDeleteReturn
;
48 typedef struct _SwfdecAsObjectClass SwfdecAsObjectClass
;
49 typedef gboolean (* SwfdecAsVariableForeach
) (SwfdecAsObject
*object
,
50 const char *variable
, SwfdecAsValue
*value
, guint flags
, gpointer data
);
52 #define SWFDEC_TYPE_AS_OBJECT (swfdec_as_object_get_type())
53 #define SWFDEC_IS_AS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_AS_OBJECT))
54 #define SWFDEC_IS_AS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFDEC_TYPE_AS_OBJECT))
55 #define SWFDEC_AS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_AS_OBJECT, SwfdecAsObject))
56 #define SWFDEC_AS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_AS_OBJECT, SwfdecAsObjectClass))
57 #define SWFDEC_AS_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFDEC_TYPE_AS_OBJECT, SwfdecAsObjectClass))
59 struct _SwfdecAsObject
{
61 SwfdecGcObject object
;
63 SwfdecAsObject
* prototype
; /* prototype object (referred to as __proto__) */
64 guint prototype_flags
; /* propflags for the prototype object */
65 GHashTable
* properties
; /* string->SwfdecAsVariable mapping or NULL when not in GC */
66 GHashTable
* watches
; /* string->WatchData mapping or NULL when not watching anything */
67 GSList
* interfaces
; /* list of interfaces this object implements */
70 struct _SwfdecAsObjectClass
{
71 SwfdecGcObjectClass object_class
;
73 /* get the value and flags for a variables */
74 gboolean (* get
) (SwfdecAsObject
* object
,
75 SwfdecAsObject
* orig
,
76 const char * variable
,
79 /* set the variable - and return it (or NULL on error) */
80 void (* set
) (SwfdecAsObject
* object
,
81 const char * variable
,
82 const SwfdecAsValue
* val
,
84 /* set flags of a variable */
85 void (* set_flags
) (SwfdecAsObject
* object
,
86 const char * variable
,
89 /* delete the variable - return TRUE if it exists */
90 SwfdecAsDeleteReturn (* del
) (SwfdecAsObject
* object
,
91 const char * variable
);
92 /* call with every variable until func returns FALSE */
93 gboolean (* foreach
) (SwfdecAsObject
* object
,
94 SwfdecAsVariableForeach func
,
96 /* get the real object referenced by this object (useful for internal objects) */
97 SwfdecAsObject
* (* resolve
) (SwfdecAsObject
* object
);
98 /* get a debug string representation for this object */
99 char * (* debug
) (SwfdecAsObject
* object
);
102 GType
swfdec_as_object_get_type (void);
104 SwfdecAsObject
*swfdec_as_object_new (SwfdecAsContext
* context
);
105 SwfdecAsObject
*swfdec_as_object_new_empty (SwfdecAsContext
* context
);
106 void swfdec_as_object_create (SwfdecAsFunction
* fun
,
108 const SwfdecAsValue
* args
,
109 SwfdecAsValue
* return_value
);
110 void swfdec_as_object_set_constructor(SwfdecAsObject
* object
,
111 SwfdecAsObject
* construct
);
112 SwfdecAsObject
*swfdec_as_object_resolve (SwfdecAsObject
* object
);
113 char * swfdec_as_object_get_debug (SwfdecAsObject
* object
);
115 /* I'd like to name these [gs]et_property, but binding authors will complain
116 * about overlap with g_object_[gs]et_property then */
117 #define swfdec_as_object_set_variable(object, variable, value) \
118 swfdec_as_object_set_variable_and_flags (object, variable, value, 0)
119 void swfdec_as_object_set_variable_and_flags
120 (SwfdecAsObject
* object
,
121 const char * variable
,
122 const SwfdecAsValue
* value
,
123 guint default_flags
);
124 void swfdec_as_object_add_variable (SwfdecAsObject
* object
,
125 const char * variable
,
126 SwfdecAsFunction
* get
,
127 SwfdecAsFunction
* set
,
128 SwfdecAsVariableFlag default_flags
);
129 #define swfdec_as_object_get_variable(object, variable, value) \
130 swfdec_as_object_get_variable_and_flags (object, variable, value, NULL, NULL)
131 gboolean swfdec_as_object_get_variable_and_flags
132 (SwfdecAsObject
* object
,
133 const char * variable
,
134 SwfdecAsValue
* value
,
136 SwfdecAsObject
** pobject
);
137 SwfdecAsObject
*swfdec_as_object_has_variable (SwfdecAsObject
* object
,
138 const char * variable
);
140 swfdec_as_object_delete_variable(SwfdecAsObject
* object
,
141 const char * variable
);
142 void swfdec_as_object_delete_all_variables
143 (SwfdecAsObject
* object
);
144 void swfdec_as_object_set_variable_flags
145 (SwfdecAsObject
* object
,
146 const char * variable
,
147 SwfdecAsVariableFlag flags
);
148 void swfdec_as_object_unset_variable_flags
149 (SwfdecAsObject
* object
,
150 const char * variable
,
151 SwfdecAsVariableFlag flags
);
152 gboolean
swfdec_as_object_foreach (SwfdecAsObject
* object
,
153 SwfdecAsVariableForeach func
,
156 SwfdecAsFunction
*swfdec_as_object_add_function (SwfdecAsObject
* object
,
158 SwfdecAsNative native
);
159 SwfdecAsFunction
*swfdec_as_object_add_constructor
160 (SwfdecAsObject
* object
,
162 GType construct_type
,
163 SwfdecAsNative native
,
164 SwfdecAsObject
* prototype
);
166 gboolean
swfdec_as_object_call (SwfdecAsObject
* object
,
169 SwfdecAsValue
* argv
,
170 SwfdecAsValue
* return_value
);
171 void swfdec_as_object_run (SwfdecAsObject
* object
,
172 SwfdecScript
* script
);