[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog doc/C/internals.xml
From: |
Ann Barcomb |
Subject: |
[Gnash-commit] gnash ChangeLog doc/C/internals.xml |
Date: |
Mon, 05 Mar 2007 21:35:27 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Ann Barcomb <ann> 07/03/05 21:35:27
Modified files:
. : ChangeLog
doc/C : internals.xml
Log message:
'ActionScript Support' was updated in an attempt
to describe the current interface.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2538&r2=1.2539
http://cvs.savannah.gnu.org/viewcvs/gnash/doc/C/internals.xml?cvsroot=gnash&r1=1.58&r2=1.59
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2538
retrieving revision 1.2539
diff -u -b -r1.2538 -r1.2539
--- ChangeLog 5 Mar 2007 15:03:05 -0000 1.2538
+++ ChangeLog 5 Mar 2007 21:35:26 -0000 1.2539
@@ -1,3 +1,8 @@
+2007-03-05 Ann Barcomb <address@hidden>
+
+ * doc/C/internals.xml: section 'ActionScript Support' was updated
+ in an attempt to describe the current interface.
+
2007-03-05 Sandro Santilli <address@hidden>
* testsuite/misc-ming.all/action_execution_order_extend_test.c:
Index: doc/C/internals.xml
===================================================================
RCS file: /sources/gnash/gnash/doc/C/internals.xml,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- doc/C/internals.xml 28 Feb 2007 11:07:09 -0000 1.58
+++ doc/C/internals.xml 5 Mar 2007 21:35:27 -0000 1.59
@@ -348,10 +348,10 @@
the ActionScript class itself, something like
<emphasis>XML</emphasis>. All implementations are written in
<emphasis>C++</emphasis>. In the CVS source tree for Gnash, there is a
- utility file called <emphasis>gen-files.sh</emphasis> that can be used
- to generate a template for a new ActionScript class. At this
- time templates have been generated for all documented
- ActionScript classes.
+ utility file called <emphasis>gen-asclass.sh</emphasis> which
+ can be used to generate a header file and a C++ source file template
+ for an ActionScript class. Templates have already been generated
+ for all documented ActionScript classes.
</para>
<sect4 id="defclass">
@@ -406,7 +406,7 @@
<para>
A more complex example might be to add hooks to the
- constructor an destructor for the class to keep track of
+ constructor and destructor for the class to keep track of
memory allocations and cleanup. In this case only a debug
statement is printed.
@@ -429,7 +429,7 @@
<emphasis>m_members</emphasis>, is a list of each symbol name and its
associated code. Normally this is kept internally within the
interpreter engine, but in this example for certain methods we
- want to return a point to itself, instead of getting the data
+ want to return a pointer to itself, instead of getting the data
from the list.
<programlisting>
@@ -443,7 +443,7 @@
};
virtual bool get_member(const tu_stringi& name, as_value*
val) {
if ((name == "firstChild") || (name == "childNodes")) {
- val->set_as_object_interface(this);
+ val->set_as_object(this);
return true;
}
if (m_members.get(name, val) == false) {
@@ -463,14 +463,30 @@
<title>Instantiating a new Class</title>
<para>
- To add a new object to the list maintained by Gnash, it needs
- to be added to the function <emphasis>gnash::action_init()</emphasis>,
- in <emphasis>action.cpp</emphasis>. The symbol name is specified along
- with a function pointer that will be called when the symbol
- name is seen by the interpreter.
+ To add a new object, create an init method similar to the
+ one below, then call it in the constructor in
+ <emphasis>Global.cpp</emphasis> using the syntax
+ <emphasis>xml_class_init(*this);</emphasis>
+ <programlisting>
+ // Example init method
+
+ void xml_class_init(as_object& global)
+ {
+ // GNASH_REPORT_FUNCTION;
+ // This is going to be the global XML "class"/"function"
+ static boost::intrusive_ptr<builtin_function> cl;
+
+ if ( cl == NULL ) {
+ cl=new builtin_function(&xml_new, getXMLInterface());
+ // replicate all interface to class, to be able to access
+ // all methods as static functions
+ attachXMLInterface(*cl);
+ }
- <programlisting>
- obj->set_member("XML", as_value(xml_new));
+ // Register _global.String
+ global.init_member("XML", cl.get());
+
+ }
</programlisting>
</para>
<para>
@@ -491,50 +507,55 @@
<para>
The object popped off the stack also has its own methods. The
- main one of interest is <emphasis>get_type</emphasis>. This returns
- the type of the object being referred to.
-
+ main one of interest is <emphasis>is_function</emphasis>,
+ <emphasis>is_as_function</emphasis>, <emphasis>is_string</emphasis>,
+ and so on. A list of these methods, which indicate if a argument
+ is of a specified type, can be found in
+ <emphasis>as_value.h</emphasis>.
<programlisting>
- if (fn.env->top(0).get_type() == as_value::STRING) {
+ if (fn.env->top(0).is_string()) {
...
}
</programlisting>
+ Another option is to use <emphasis>typeOf</emphasis>, which will
+ return a string describing the argument type.
</para>
<para>
The supported data types for an object are
+ <emphasis>NULLTYPE</emphasis>
<emphasis>BOOLEAN</emphasis>, <emphasis>STRING</emphasis>,
<emphasis>NUMBER</emphasis>, <emphasis>OBJECT</emphasis>,
- <emphasis>C_FUNCTION</emphasis>, <emphasis>AS_FUNCTION</emphasis>.
Because
+ <emphasis>C_FUNCTION</emphasis>, <emphasis>AS_FUNCTION</emphasis>,
+ and <emphasis>MOVIECLIP</emphasis>. Because
they are defined as part of the as_value class, they need to
always have the class name prefixed to use these as a
constant. You can retrieve the value of an
<emphasis>as_value</emphasis> using the conversion methods. For
- example, <emphasis>to_tu_string</emphasis> returns the value as string
- using the Gnash small STL library. Similarly,
+ example, <emphasis>to_std_string</emphasis> returns the value
+ as a std::string. Similarly,
<emphasis>to_number</emphasis> would return this same value as a
<emphasis>double.</emphasis>
</para>
<para>
To add methods to the class, a new class needs to be
- instantiated as an object. Each ActionScript object can have
- child methods attached in a similar way as the object was. In
- this case, the built-in <emphasis>set_member</emphasis> function is
- used.
-
+ instantiated as an object. Each ActionScript object can
+ have child methods, which are attached to the object in a
+ manner similar to how the object itself is initialized using
+ <emphasis>init_member</emphasis>.
<programlisting>
xml_obj = new xml_as_object;
- xml_obj->set_member("load", &xml_load);
+ xml_obj->init_member("load", new builtin_function(xml_load));
</programlisting>
</para>
<para>
- To make the object active within the interpreter, the new
- object gets returned by the function using the
- <emphasis>fn_call</emphasis> typed parameter.
-
+ To activate the object within the interpreter and increment
+ the reference count of the object, the new object should
+ be returned (in ActionScript) by the function. This should
+ be done using the <emphasis>fn_call</emphasis> typed parameter.
<programlisting>
- fn.result->set_as_object_interface(xml_obj);
+ fn.result->set_as_object(xml_obj);
</programlisting>
</para>
@@ -546,28 +567,32 @@
<programlisting>
void
- xml_new(const fn_call& fn) {
+ xml_new(const fn_call& fn)
+ {
as_value inum;
- xml_as_object *xml_obj;
+ XML *xml_obj;
if (fn.nargs > 0) {
- if (fn.env->top(0).get_type() == as_value::STRING) {
- xml_obj = new xml_as_object;
+ as_object* obj = fn.env->top(0).to_object();
+
+ if (! obj ) {
+ xml_obj = new XML;
tu_string datain = fn.env->top(0).to_tu_string();
- xml_obj->obj.parseXML(datain);
- xml_obj->obj.setupFrame(xml_obj,
xml_obj->obj.firstChild(), true);
+ xml_obj->parseXML(datain);
+ xml_obj->setupFrame(xml_obj, xml_obj->firstChild(),
true);
} else {
- xml_as_object *xml_obj =
(xml_as_object*)fn.env->top(0).to_object();
- fn.result->set_as_object_interface(xml_obj);
+ assert(dynamic_cast<XML*>(obj));
+ XML* xml_obj = (XML*)obj;
+ fn.result->set_as_object(xml_obj);
return;
}
} else {
- xml_obj = new xml_as_object;
- xml_obj->set_member("load", &xml_load);
- xml_obj->set_member("loaded", &xml_loaded);
+ xml_obj = new XML;
}
- fn.result->set_as_object_interface(xml_obj);
+
+ fn.result->set_as_object(xml_obj);
}
+
</programlisting>
</para>
@@ -580,7 +605,7 @@
function, a string or number is used.
<programlisting>
- as_obj->set_member("nodeName", as_value("HelloWorld"));
+ as_obj->init_member("nodeName", as_value("HelloWorld"));
</programlisting>
When a Flash movie looks this up as a property, the value
@@ -612,7 +637,7 @@
Parameters are passed to the callback functions for a class's
methods and properties using the <emphasis>fn_call</emphasis> data
structure. This data structure contains all the incoming
- parameters for a callback, as well as it contains the final
+ parameters for a callback, and contains the final
result from the callback to be passed back into the
player.
</para>
@@ -626,9 +651,9 @@
this example:
<programlisting>
- xml_as_object *xml_obj = (xml_as_object*)fn.this_ptr;
+ xml_as_object *xml_obj = static_cast < xml_as_object* >
(fn.this_ptr);
if (fn.nargs) {
- filespec = fn.env->bottom(fn.first_arg_bottom_index).to_string;
+ filespec =
fn.env->bottom(fn.first_arg_bottom_index).to_string();
}
</programlisting>
</para>
@@ -674,19 +699,21 @@
</programlisting>
<para>
- If the type of the object is needed, that can be accessed by
- using the <emphasis>as_value::get_type()</emphasis> method. There
- are more details on the types of values in the
+ If the type of the object is needed, the methods
+ <emphasis>is_function</emphasis>,
<emphasis>is_as_function</emphasis>,
+ and so on can be used. A list of these methods can be found in
+ <emphasis>as_value.h</emphasis>.
+ More information about types of values can be found in the
<link linkend="handval">Handling Values</link> section of
this manual.
</para>
<programlisting>
if (fn.nargs > 0) {
- if (fn.env->top(0).get_type() == as_value::STRING) {
+ if (fn.env->top(0).is_string()) {
name = fn.env->top(0).to_string);
}
- if (fn.env->top(0).get_type() == as_value::NUMBER) {
+ if (fn.env->top(0).is_number()) {
value = fn.env->top(0).to_number);
}
}
@@ -698,7 +725,7 @@
resident in the player.
<programlisting>
- foo_as_object *foo_obj = (foo_as_object*)fn.this_ptr;
+ foo_as_object *foo_obj = static_cast < foo_as_object* >
(fn.this_ptr);
bool bar = foo_obj->obj.GetBar();
</programlisting>
@@ -765,7 +792,7 @@
</listitem>
</varlistentry>
<varlistentry>
- <term>as_value::set_as_object_interface()</term>
+ <term>as_value::set_as_object()</term>
<listitem>
<para>
Set the result to an object value.
- [Gnash-commit] gnash ChangeLog doc/C/internals.xml,
Ann Barcomb <=
Message not available