gnash-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnash-dev] Static Members


From: strk
Subject: Re: [Gnash-dev] Static Members
Date: Sat, 11 Mar 2006 20:15:11 +0100

Hello Mike, nice to hear you're working on this.
I'm not sure I understand your questions, anyway they look
like something I worked on already for Function.cpp.

Basically we need to model ActionScript inheritance as
a whole.

I started with assumption from AS1, which are as follows:

 1. Every function has a 'prototype' member which
    contains 'exported' (virtual, I'd say) members.

 2. Every object has a __proto__ member pointing
    to it's constructor's 'prototype' member.

 3. The 'prototype' member of a function has a 'constructor'
    element pointing to the function itself.

Following this, I made as_object::get_member always look,
recuring, into the __proto__ element when a member is not
found locally.

To make a simple example, consider the Object class.
In Gnash this is currently NOT a class, but somtething hard-coded.
It it has to be a class it would ba an as_function_object
member of the s_global (Actionscript's _global) object and 
named 'Object'.

When following actionscript code is found:

        var a = new Object();

The variable 'a' would be constructed by the s_global['Object']
as_function_object, which would be Object class' constructor.

a['__proto__'] would then point to s_global['Object']['prototype']

When calling a.toString() ( current handling being hard-coded)
Gnash should look at a['toString'], when not finding it (this
is already implented in as_object::get_member) it will look
into a['__proto__']['toString'] and will find it.
The found member would really be Object.toString().

The code I used for Function is not surely the best one, but
works fine as far as I tested it.

The point is to be able to do, in actionscript, something like
this:

        var d = new Date();
        Date.prototype.sayHello = function() { trace("Hello"); }
        d.sayHello();

This is *known* to be expected to work, and it is commonly used
with the MovieClip class, adding functions to the drawing API.

I'm interested in discussing this further, and please let
me know if I completely missed your point :)

--strk;

On Sun, Mar 12, 2006 at 02:50:33AM +0800, Michael Carlson wrote:
> Hey Everyone,
> 
> I'm going through and implementing some of the basic actionscript
> classes, and ran into a problem - I don't know how to create static
> members with the current code.
> The first idea to come to my head was
> to add static members to the constructor object itself (to cover case
> 1 below), as well as adding the member to each instance of the class
> when created (in the normal non-static way) using the constructor (to
> cover case 2 below).
> 
> For reference, examples of the two basic cases (that I can think of)
> using Date's UTC function (which is static):
> 
> case 1) Date.UTC(params);
> case 2) var x = new Date(); x.UTC(params);
> 
> However, if the static member is a variable which is non-constant
> (which fortunately none I've encountered so far are - maybe none are -
> but can the user define a variable like this that is?), this would
> cause problems as each instance of the class would have its own
> separate version of the variable. Furthermore, at the moment the
> constructors are all created as an as_value (of type function), which
> seems to be unable to have arbitrarily named "members" like objects do
> anyways.
> 
> Should we add a new as_value type of "constructor", which has the
> ability to hold named members like normal objects? Or should we make
> the constructor and the uninstantiated object definition separate
> entities in code, in which the static variables would exist in the
> uninstantiated object definition (this seems to solve all the problems
> I thought of, but it might be overkill and overcomplicate the code)?
> 
> What is the proper solution here?
> 
> - Mike
> 
> 
> _______________________________________________
> Gnash-dev mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/gnash-dev

-- 
----------------------------------------------------------------------
State-collected Geographic Data is public property !
Reject the INSPIRE directive.
Sign the petition: http://petition.publicgeodata.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]