Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InterfaceScripted.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_INTERFACE_SCRIPTED
19 #define INCLUDED_INTERFACE_SCRIPTED
20 
22 #include "js/jsapi.h"
23 
24 #define BEGIN_INTERFACE_WRAPPER(iname) \
25  JSClass class_ICmp##iname = { \
26  "ICmp" #iname, JSCLASS_HAS_PRIVATE, \
27  JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, \
28  JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, \
29  JSCLASS_NO_OPTIONAL_MEMBERS \
30  }; \
31  static JSFunctionSpec methods_ICmp##iname[] = {
32 
33 #define END_INTERFACE_WRAPPER(iname) \
34  { NULL } \
35  }; \
36  void ICmp##iname::InterfaceInit(ScriptInterface& scriptInterface) { \
37  JSContext* cx = scriptInterface.GetContext(); \
38  JSObject* global = JS_GetGlobalObject(cx); \
39  JS_InitClass(cx, global, NULL, &class_ICmp##iname, NULL, 0, NULL, methods_ICmp##iname, NULL, NULL); \
40  } \
41  JSClass* ICmp##iname::GetJSClass() const { return &class_ICmp##iname; } \
42  void RegisterComponentInterface_##iname(ScriptInterface& scriptInterface) { \
43  ICmp##iname::InterfaceInit(scriptInterface); \
44  }
45 
46 #define DEFINE_INTERFACE_METHOD_0(scriptname, rettype, classname, methodname) \
47  { scriptname, \
48  ScriptInterface::callMethod<rettype, &class_##classname, classname, &classname::methodname>, \
49  0, \
50  JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
51 
52 #define DEFINE_INTERFACE_METHOD_1(scriptname, rettype, classname, methodname, arg1) \
53  { scriptname, \
54  ScriptInterface::callMethod<rettype, arg1, &class_##classname, classname, &classname::methodname>, \
55  1, \
56  JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
57 
58 #define DEFINE_INTERFACE_METHOD_2(scriptname, rettype, classname, methodname, arg1, arg2) \
59  { scriptname, \
60  ScriptInterface::callMethod<rettype, arg1, arg2, &class_##classname, classname, &classname::methodname>, \
61  2, \
62  JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
63 
64 #define DEFINE_INTERFACE_METHOD_3(scriptname, rettype, classname, methodname, arg1, arg2, arg3) \
65  { scriptname, \
66  ScriptInterface::callMethod<rettype, arg1, arg2, arg3, &class_##classname, classname, &classname::methodname>, \
67  3, \
68  JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
69 
70 #define DEFINE_INTERFACE_METHOD_4(scriptname, rettype, classname, methodname, arg1, arg2, arg3, arg4) \
71  { scriptname, \
72  ScriptInterface::callMethod<rettype, arg1, arg2, arg3, arg4, &class_##classname, classname, &classname::methodname>, \
73  4, \
74  JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
75 
76 #define DEFINE_INTERFACE_METHOD_5(scriptname, rettype, classname, methodname, arg1, arg2, arg3, arg4, arg5) \
77  { scriptname, \
78  ScriptInterface::callMethod<rettype, arg1, arg2, arg3, arg4, arg5, &class_##classname, classname, &classname::methodname>, \
79  5, \
80  JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
81 
82 #define DEFINE_INTERFACE_METHOD_6(scriptname, rettype, classname, methodname, arg1, arg2, arg3, arg4, arg5, arg6) \
83  { scriptname, \
84  ScriptInterface::callMethod<rettype, arg1, arg2, arg3, arg4, arg5, arg6, &class_##classname, classname, &classname::methodname>, \
85  6, \
86  JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
87 
88 #define DEFINE_INTERFACE_METHOD_7(scriptname, rettype, classname, methodname, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
89  { scriptname, \
90  ScriptInterface::callMethod<rettype, arg1, arg2, arg3, arg4, arg5, arg6, arg7, &class_##classname, classname, &classname::methodname>, \
91  7, \
92  JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT },
93 
94 #endif // INCLUDED_INTERFACE_SCRIPTED