1 module as.func;
2 import as.def;
3 import as.engine;
4 import as.mod;
5 import std..string;
6 
7 /**
8     Supported calling conventions
9 */
10 enum CallConv : asECallConvTypes {
11     
12     /**
13         The CDECL standard calling convention
14     */
15 	CDecl = asECallConvTypes.asCALL_CDECL,
16 
17     /**
18         The STDCall calling convention
19     */
20 	STDCall = asECallConvTypes.asCALL_STDCALL,
21 
22     /**
23         The ThisCall calling convention that emulates a global object
24     */
25 	ThisCallASGlobal = asECallConvTypes.asCALL_THISCALL_ASGLOBAL,
26 
27     /**
28         The ThisCall calling convention
29     */
30 	ThisCall = asECallConvTypes.asCALL_THISCALL,
31 
32     /**
33         CDECL calling convention where object pointer is the first int argument
34     */
35 	CDeclObjFirst = asECallConvTypes.asCALL_CDECL_OBJFIRST,
36 
37     /**
38         CDECL calling convention where the object pointer is the last int argument
39     */
40 	CDeclObjLast = asECallConvTypes.asCALL_CDECL_OBJLAST,
41 
42     /**
43         The Generic calling convention, requires writing specialized code to handle it
44     */
45 	Generic = asECallConvTypes.asCALL_GENERIC,
46 
47     /**
48         ThisCall calling convention where the object pointer is the last int argument
49     */
50 	ThisCallObjLast = asECallConvTypes.asCALL_THISCALL_OBJLAST,
51 
52     /**
53         ThisCall calling convention where the object pointer is the last int argument
54     */
55 	ThisCallObjFirst = asECallConvTypes.asCALL_THISCALL_OBJFIRST,
56 
57     /**
58         The DDECL standard calling convention
59 
60         DDECL is CDECL but with int registers in reverse order
61     */
62 	DDecl = asECallConvTypes.asCALL_DDECL,
63 
64     /**
65         DDECL calling convention where the object pointer is the last int argument
66     */
67 	DDeclObjLast = asECallConvTypes.asCALL_DDECL_OBJLAST,
68 
69     /**
70         DDECL calling convention where the object pointer is the last int argument
71     */
72 	DDeclObjFirst = asECallConvTypes.asCALL_DDECL_OBJFIRST,
73 }
74 
75 /**
76     Function types
77 */
78 enum FuncType : asEFuncType {
79     /**
80         A dummy no-op function
81     */
82     Dummy = asEFuncType.asFUNC_DUMMY,
83 
84     /**
85         A system function
86     */
87     System = asEFuncType.asFUNC_SYSTEM,
88 
89     /**
90         A script function
91     */
92     Script = asEFuncType.asFUNC_SCRIPT,
93 
94     /**
95         A interface function declaration
96     */
97     Interface = asEFuncType.asFUNC_INTERFACE,
98 
99     /**
100         A virtual function
101     */
102     Virtual = asEFuncType.asFUNC_VIRTUAL,
103 
104     /**
105         A function definition
106     */
107     FuncDef = asEFuncType.asFUNC_FUNCDEF,
108 
109     /**
110         An imported function
111     */
112     Imported = asEFuncType.asFUNC_IMPORTED,
113 
114     /**
115         A function delegate
116     */
117     Delegate = asEFuncType.asFUNC_DELEGATE
118 }
119 
120 class Function {
121 private:
122     ScriptEngine engine;
123     Module mod;
124 
125     ~this() {
126         // Avoid garbage collecting the engine
127         this.engine = null;
128         this.mod = null;
129     }
130 
131 package(as):
132     asIScriptFunction* func;
133 
134     this(ScriptEngine engine, asIScriptFunction* func) {
135         this.engine = engine;
136         this.mod = new Module(engine, asFunction_GetModule(func));
137         this.func = func;
138     }
139 
140     this(ScriptEngine engine, Module mod, asIScriptFunction* func) {
141         this.engine = engine;
142         this.mod = mod;
143         this.func = func;
144     }
145 
146 public:
147 
148     /**
149         Gets the scripting engine this module belongs to
150     */
151     ScriptEngine getEngine() {
152         return engine;
153     }
154 
155     /**
156         Gets the module this function belongs to
157     */
158     Module getModule() {
159         return mod;
160     }
161 
162     /**
163         Adds a reference to this function
164     */
165     int addRef() {
166         return asFunction_AddRef(func);
167     }
168 
169     /**
170         Releases a reference from this function
171     */
172     int release() {
173         return asFunction_Release(func);
174     }
175 
176     /**
177         Gets the ID of this function
178     */
179     int getId() {
180         return asFunction_GetId(func);
181     }
182 
183     /**
184         Gets this function's function type
185     */
186     FuncType getFuncType() {
187         return cast(FuncType)asFunction_GetFuncType(func);
188     }
189 
190     /**
191         Gets the module this function belongs to
192     */
193     string getModuleName() {
194         return cast(string)asFunction_GetModuleName(func).fromStringz;
195     }
196 
197     /**
198         Gets the name of the script section this function belongs to
199     */
200     string getScriptSectionName() {
201         return cast(string)asFunction_GetScriptSectionName(func).fromStringz;
202     }
203 
204     /**
205         Gets the config group this function belongs to
206     */
207     string getConfigGroup() {
208         return cast(string)asFunction_GetConfigGroup(func).fromStringz;
209     }
210 
211     /**
212         Gets declaration
213     */
214     string getDeclaration(bool includeObjectName=true, bool includeNamespace=false) {
215         return cast(string)asFunction_GetDeclaration(func, includeObjectName, includeNamespace).fromStringz;
216     }
217 
218     /**
219         Gets this function's access mask
220     */
221     asDWORD getAccessMask() {
222         return asFunction_GetAccessMask(func);
223     }
224 
225     /**
226         Gets this function's auxiliary
227     */
228     void* getAuxiliary() {
229         return asFunction_GetAuxiliary(func);
230     }
231 }