Questions related to Native method implementations

Steven Johnson stejohns at
Tue Jun 10 10:22:09 PDT 2008

This usecase isn't contradictory; in fact, Flash does this very thing very
frequently in the Tamarin-Central codebase.

However, we're trying to move away from this model as much as possible in
the Tamarin-Tracing codebase (and thus in future versions of Flash) -
concentrating all object creation and storage into AS code (rather than C++)
opens up possibilities for improvements in the GC code (I'll let Tommy
Reilly comment on specifices), as well as being generally more compact
code-size wise... our belief is that the tracing-jit approach will mitigate
any possible loss of efficiency in the vast majority of cases.

On 6/10/08 7:34 AM, "Kelkar, Anand" <akelkar at> wrote:

> Thanks for the suggestion. I will start looking into those mscom classes.
> I agree that I should plan to have as much functionality in AS side instead of
> native c++. But my usecase is kind of different in way that C++ side has
> knowledge about bunch of .abc files which define new AS classes (containing
> some methods natively implemented), so c++ side calls those scripts to
> define/initialize to those classes (scriptinit part) and then on certain
> events it will start instantiating those initialized classes and call methods
> on objects. I have to implement some logic in native methods as it has more
> knowledge about application side (in my case game code) data.
> So I wanted to know better way to instantiate already defined AS classes and
> call methods on them from c++.
> Is this usecase kind of contradictory to what users of tamarin should do? But
> I guess even Flash player code must also be doing something similar to
> instantiate movieclips(like Timeline movieclips) very first time?
> Thanks
> Anand
> -----Original Message-----
> From: Steven Johnson [mailto:stejohns at]
> Sent: Monday, June 09, 2008 8:17 PM
> To: Mark Hammond; Kelkar, Anand; tamarin-devel at
> Subject: Re: Questions related to Native method implementations
> Definitely. The patch there hasn't been pushed yet but hopefully will be
> within a day or two. In TT there is substantive benefit to doing as much
> work as practical in AS itself, rather than native code -- so much so that
> we are hoping to avoid to providing a hosting API for constructing objects
> directly from C/C++.
> On 6/9/08 5:13 PM, "Mark Hammond" <mhammond at> wrote:
>> The best I can do is point you at the 'axscript' directory in the
>> tamarin-central branch.  Similarly to what Par said, the approach axscript
>> takes is to implement the native objects, but have them instantiated from
>> script code, not from C++ code.  In axscript's case, it assumes that some
>> bootstrap script code has created an object called 'engine', and the C++
>> code gets that object from the global object, and using other C++ APIs,
>> arranges to call (script implemented) methods on that object.  That script
>> code in turn interacts with the natively implemented objects.  Using
>> top-level script functions would probably work just as well as my "object
>> oriented" approach, which was chosen to mirror the underlying API I was
>> implementing using Tamarin.
>> I believe some of this will need to change for TT though - see bug
>> for details.
>> Cheers,
>> Mark
>> --------------------------------------------------------------
>> From: tamarin-devel-bounces at
>> [mailto:tamarin-devel-bounces at] On Behalf Of Kelkar, Anand
>> Sent: Tuesday, 10 June 2008 8:30 AM
>> To: tamarin-devel at
>> Subject: Questions related to Native method implementations
>> Hello,
>> I created my AS class and defined some native methods and implemented them
>> in C++. If I use that class in AS and instantiate it and call methods my
>> code in C++ is executed properly.
>> Now I want to how to create an instance of that AS class from C++ side. So I
>> think I know the steps but not sure how to do it.
>> - I will first have to find classclosure for my AS class in my domain
>> environment
>> - Use that classclosure to create a new object of type subclass of
>> ScriptObject
>> - Find method I want to call inside ScriptObject
>> - Execute that method
>> I tried looking in tamarin-devel archives and found one thread related to
>> this
>> ?how to add my own objects? ? Mark Hammond
>> But it does not have the full answer to my questions about how to
>> instantiate as AS class (which has native methods implemented in C++) from
>> C++.
>> Can somebody help me with this.
>> Thanks
>> Anand
>> P.S. I also have some other questions related to this which I sent sometime
>> back to a wrong address, I guess.
>> From: Kelkar, Anand
>> Sent: Friday, May 30, 2008 3:19 PM
>> To: 'tamarin-devel at'
>> Subject: Questions related to Native method implementations
>> Hello,
>> I am trying to implement few methods of a sample AS3.0 class as native
>> methods. In that process I am able to use macros like BEGIN_NATIVE_MAP and
>> define C++ impmentations for the native methods. Also able to build the
>> AS3.0 class and generate header file defining all constatnts related to
>> class, methods name etc and map AS3.0 class with my C++ class.? I am also
>> hitting the code inside my native C++ methods when functions are called on
>> object of that AS3.0 class. But I have comple of questions related to
>> implementations of native methods.
>> - How to interpret arguments passed to native member functions of classes
>> that we have added? ?Especially if those are not native like boolean,
>> string, ints etc. How to interpret ?object? type parameters?
>> - How to return a valid data type from a native function which is not a
>> simple data type like int, bool etc?
>> - How to map/interpret AS3.0 class member properties defined inside AS class
>> definition to member variables inside C++ class that is used to implement
>> native methods?
>> - Is it possible to access other AS3.0 class static members like constants
>> from C++.
>> Are there any good examples of such implementations. I tried looking mostly
>> at StringBuilder, ByteArray implementations in avmshell but most of them
>> have native parameters such as int, bool, string etc.
>> Thanks in advance.
>> Anand
>> _______________________________________________
>> Tamarin-devel mailing list
>> Tamarin-devel at

More information about the Tamarin-devel mailing list