1 module as.func;
2 import as.def;
3 import as.engine;
4 import as.mod;
5 import std..string;
6 
7 enum FuncType : asEFuncType {
8     /**
9         A dummy no-op function
10     */
11     Dummy = asEFuncType.asFUNC_DUMMY,
12 
13     /**
14         A system function
15     */
16     System = asEFuncType.asFUNC_SYSTEM,
17 
18     /**
19         A script function
20     */
21     Script = asEFuncType.asFUNC_SCRIPT,
22 
23     /**
24         A interface function declaration
25     */
26     Interface = asEFuncType.asFUNC_INTERFACE,
27 
28     /**
29         A virtual function
30     */
31     Virtual = asEFuncType.asFUNC_VIRTUAL,
32 
33     /**
34         A function definition
35     */
36     FuncDef = asEFuncType.asFUNC_FUNCDEF,
37 
38     /**
39         An imported function
40     */
41     Imported = asEFuncType.asFUNC_IMPORTED,
42 
43     /**
44         A function delegate
45     */
46     Delegate = asEFuncType.asFUNC_DELEGATE
47 }
48 
49 class Function {
50 private:
51     ScriptEngine engine;
52     Module mod;
53 
54     ~this() {
55         // Avoid garbage collecting the engine
56         this.engine = null;
57         this.mod = null;
58     }
59 
60 package(as):
61     asIScriptFunction* func;
62 
63     this(ScriptEngine engine, asIScriptFunction* func) {
64         this.engine = engine;
65         this.mod = new Module(engine, asFunction_GetModule(func));
66         this.func = func;
67     }
68 
69     this(ScriptEngine engine, Module mod, asIScriptFunction* func) {
70         this.engine = engine;
71         this.mod = mod;
72         this.func = func;
73     }
74 
75 public:
76 
77     /**
78         Gets the scripting engine this module belongs to
79     */
80     ScriptEngine getEngine() {
81         return engine;
82     }
83 
84     /**
85         Gets the module this function belongs to
86     */
87     Module getModule() {
88         return mod;
89     }
90 
91     /**
92         Adds a reference to this function
93     */
94     int addRef() {
95         return asFunction_AddRef(func);
96     }
97 
98     /**
99         Releases a reference from this function
100     */
101     int release() {
102         return asFunction_Release(func);
103     }
104 
105     /**
106         Gets the ID of this function
107     */
108     int getId() {
109         return asFunction_GetId(func);
110     }
111 
112     /**
113         Gets this function's function type
114     */
115     FuncType getFuncType() {
116         return cast(FuncType)asFunction_GetFuncType(func);
117     }
118 
119     /**
120         Gets the module this function belongs to
121     */
122     string getModuleName() {
123         return cast(string)asFunction_GetModuleName(func).fromStringz;
124     }
125 
126     /**
127         Gets the name of the script section this function belongs to
128     */
129     string getScriptSectionName() {
130         return cast(string)asFunction_GetScriptSectionName(func).fromStringz;
131     }
132 
133     /**
134         Gets the config group this function belongs to
135     */
136     string getConfigGroup() {
137         return cast(string)asFunction_GetConfigGroup(func).fromStringz;
138     }
139 
140     /**
141         Gets this function's access mask
142     */
143     asDWORD getAccessMask() {
144         return asFunction_GetAccessMask(func);
145     }
146 
147     /**
148         Gets this function's auxiliary
149     */
150     void* getAuxiliary() {
151         return asFunction_GetAuxiliary(func);
152     }
153 }