1 | /*! |
---|
2 | * @file script_class.h |
---|
3 | * @brief Definition of ... |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _SCRIPT_CLASS_H |
---|
7 | #define _SCRIPT_CLASS_H |
---|
8 | |
---|
9 | #include "base_object.h" |
---|
10 | |
---|
11 | #include "script.h" |
---|
12 | #include "lunar.h" |
---|
13 | #include "script_method.h" |
---|
14 | |
---|
15 | |
---|
16 | /** |
---|
17 | * Creates a factory to a Loadable Class. |
---|
18 | * this should be used at the beginning of all the Classes that should be loadable (in the cc-file) |
---|
19 | */ |
---|
20 | #define CREATE_SCRIPTABLE_CLASS(CLASS_NAME, SCRIPT_METHODS) \ |
---|
21 | tScriptClass<CLASS_NAME> global_##CLASS_NAME##_ScriptableClass(#CLASS_NAME, CLASS_NAME::staticClassID(), (new ScriptMethod)->SCRIPT_METHODS) |
---|
22 | |
---|
23 | |
---|
24 | //! A class for ... |
---|
25 | class ScriptClass : public BaseObject |
---|
26 | { |
---|
27 | ObjectListDeclaration(ScriptClass); |
---|
28 | |
---|
29 | public: |
---|
30 | virtual ~ScriptClass(); |
---|
31 | |
---|
32 | virtual void registerClass(Script* script) = 0; |
---|
33 | virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) = 0; |
---|
34 | virtual int insertObject(Script* L, BaseObject* obj, const std::string& name, bool gc=false) = 0; |
---|
35 | |
---|
36 | const ScriptMethod* scriptMethods() const { return this->_scriptMethods; } |
---|
37 | |
---|
38 | protected: |
---|
39 | ScriptClass(const std::string& name, const ClassID& classID, ScriptMethod* scriptMethods); |
---|
40 | |
---|
41 | private: |
---|
42 | ClassID _classID; |
---|
43 | ScriptMethod* _scriptMethods; |
---|
44 | }; |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | template <class T> |
---|
50 | class tScriptClass : public ScriptClass |
---|
51 | { |
---|
52 | public: |
---|
53 | tScriptClass(const std::string& name, ClassID classID, ScriptMethod* scriptMethods) |
---|
54 | : ScriptClass(name, classID, scriptMethods) |
---|
55 | { } |
---|
56 | |
---|
57 | virtual void registerClass(Script* script) |
---|
58 | { |
---|
59 | Lunar<T>::Register(script, this->getName(), this->scriptMethods()); |
---|
60 | } |
---|
61 | virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) |
---|
62 | { |
---|
63 | return Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), obj->getName(), gc); |
---|
64 | } |
---|
65 | |
---|
66 | virtual int insertObject(Script* L, BaseObject* obj,const std::string& name, bool gc=false) |
---|
67 | { |
---|
68 | return Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), name, gc); |
---|
69 | } |
---|
70 | }; |
---|
71 | |
---|
72 | |
---|
73 | #endif /* _SCRIPT_CLASS_H */ |
---|