added support for \0 in strings
[swftools.git] / lib / as3 / registry.c
1 /* registry.c
2
3    Routines for compiling Flash2 AVM2 ABC Actionscript
4
5    Extension module for the rfxswf library.
6    Part of the swftools package.
7
8    Copyright (c) 2008 Matthias Kramm <kramm@quiss.org>
9  
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
23
24 #include "pool.h"
25 #include "registry.h"
26
27 static namespace_t static_empty_ns = {
28     ACCESS_PACKAGE, ""
29 };
30 static namespace_t static_flash_display_ns = {
31     ACCESS_PACKAGE, "flash.display"
32 };
33 static multiname_t static_object_class = {
34     QNAME, &static_empty_ns, 0, "Object"
35 };
36 static multiname_t static_anytype_class = {
37     QNAME, &static_empty_ns, 0, 0
38 };
39 static multiname_t static_string_class = {
40     QNAME, &static_empty_ns, 0, "String"
41 };
42 static multiname_t static_boolean_class = {
43     QNAME, &static_empty_ns, 0, "Boolean"
44 };
45 static multiname_t static_number_class = {
46     QNAME, &static_empty_ns, 0, "Number"
47 };
48 static multiname_t static_int_class = {
49     QNAME, &static_empty_ns, 0, "int"
50 };
51 static multiname_t static_uint_class = {
52     QNAME, &static_empty_ns, 0, "uint"
53 };
54 static multiname_t static_null_class = {
55     QNAME, &static_empty_ns, 0, "null"
56 };
57 static multiname_t static_movieclip_class = {
58     QNAME, &static_flash_display_ns, 0, "MovieClip"
59 };
60
61 multiname_t* registry_getobjectclass() {return &static_object_class;}
62 multiname_t* registry_getanytype() {return &static_anytype_class;}
63 multiname_t* registry_getstringclass() {return &static_string_class;}
64 multiname_t* registry_getintclass() {return &static_int_class;}
65 multiname_t* registry_getuintclass() {return &static_uint_class;}
66 multiname_t* registry_getnullclass() {return &static_null_class;}
67 multiname_t* registry_getbooleanclass() {return &static_boolean_class;}
68 multiname_t* registry_getnumberclass() {return &static_number_class;}
69 multiname_t* registry_getMovieClip() {return &static_movieclip_class;}
70
71
72 multiname_t* registry_findclass(const char*package, const char*name)
73 {
74     multiname_t*m=0;
75     if(!package) {
76         m = multiname_new(0, name);
77     } else {
78         namespace_t*ns = 0;
79
80         /* things in the "flash" package are usually public */
81         if(!strncmp(package, "flash", 5))
82             ns =namespace_new_package(package);
83         else
84             ns = namespace_new_packageinternal(package);
85
86         m = multiname_new(ns,name);
87         namespace_destroy(ns);
88     }
89     return m;
90 }
91 multiname_t* registry_getsuperclass(multiname_t*m)
92 {
93     if(!m->name)
94         return 0;
95     if(!strcmp(m->name, "Object"))
96         return 0;
97
98     else if(!strcmp(m->name, "MovieClip"))
99         return multiname_fromstring("[package]flash.display::Sprite");
100     else if(!strcmp(m->name, "Sprite"))
101         return multiname_fromstring("[package]flash.display::DisplayObjectContainer");
102     else if(!strcmp(m->name, "DisplayObjectContainer"))
103         return multiname_fromstring("[package]flash.display::InteractiveObject");
104     else if(!strcmp(m->name, "InteractiveObject"))
105         return multiname_fromstring("[package]flash.display::DisplayObject");
106     else if(!strcmp(m->name, "DisplayObject"))
107         return multiname_fromstring("[package]flash.events::EventDispatcher");
108     else
109         return &static_object_class;
110 }
111