1 module as.obj;
2 import as.def;
3 import as.engine;
4 import std..string;
5 
6 class ScriptObject {
7 private:
8     ScriptEngine engine;
9 
10     ~this() {
11         this.engine = null;
12     }
13 
14 package(as):
15     asIScriptObject* obj;
16 
17     this(ScriptEngine engine, asIScriptObject* obj) {
18         this.engine = engine;
19         this.obj = obj;
20     }
21 
22 public:
23 
24     /**
25         Gets the engine this object belongs to
26     */
27     ScriptEngine getEngine() {
28         return engine;
29     }
30 
31     /**
32         Adds a reference to this object
33     */
34     int addRef() {
35         return asObject_AddRef(obj);
36     }
37 
38     /**
39         Releases a reference to this object
40     */
41     int release() {
42         return asObject_Release(obj);
43     }
44 
45     /**
46         Get the count of properties in this object
47     */
48     asUINT getPropertyCount() {
49         return asObject_GetPropertyCount(obj);
50     }
51 
52     /**
53         Get the type ID of a property
54     */
55     int getPropertyTypeId(asUINT prop) {
56         int err = asObject_GetPropertyTypeId(obj, prop);
57         assert(err != asERetCodes.asINVALID_ARG, "prop is too large");
58         return err;
59     }
60 
61     /**
62         Get the name of a property
63     */
64     string getPropertyName(asUINT prop) {
65         return cast(string)asObject_GetPropertyName(obj, prop).fromStringz;
66     }
67 
68     /**
69         Get the address of a property
70     */
71     void* getPropertyAddress(asUINT prop) {
72         return asObject_GetAddressOfProperty(obj, prop);
73     }
74     
75     /**
76         Copy content from an other object of the same type
77     */
78     void copyFrom(ScriptObject other) {
79         int err = asObject_CopyFrom(obj, other.obj);
80         assert(err != asERetCodes.asINVALID_ARG, "Argument is null");
81         assert(err != asERetCodes.asINVALID_TYPE, "Types of objects didn't match");
82     }
83 
84     /**
85         Sets the user data associated with this object
86     */
87     void* setUserData(void* data, asPWORD type) {
88         return asObject_SetUserData(obj, data, type);
89     }
90 
91     /**
92         Gets the user data associated with this object
93     */
94     void* getUserData(asPWORD type) {
95         return asObject_GetUserData(obj, type);
96     }
97 
98 }