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