| 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, CLASS_ID, SCRIPT_METHODS) \ |
|---|
| 21 | tScriptClass<CLASS_NAME> global_##CLASS_NAME##_ScriptableClass(#CLASS_NAME, CLASS_ID, (new ScriptMethod)->SCRIPT_METHODS) |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | //! A class for ... |
|---|
| 25 | class ScriptClass : protected BaseObject |
|---|
| 26 | { |
|---|
| 27 | |
|---|
| 28 | public: |
|---|
| 29 | virtual ~ScriptClass(); |
|---|
| 30 | |
|---|
| 31 | bool operator==(const std::string& name) { return (this->getName() == name); } |
|---|
| 32 | bool operator==(ClassID classID) { return (this->_classID == classID); } |
|---|
| 33 | |
|---|
| 34 | virtual void registerClass(Script* script) = 0; |
|---|
| 35 | virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) = 0; |
|---|
| 36 | |
|---|
| 37 | const ScriptMethod* scriptMethods() const { return this->_scriptMethods; } |
|---|
| 38 | |
|---|
| 39 | protected: |
|---|
| 40 | ScriptClass(const std::string& name, ClassID classID, ScriptMethod* scriptMethods); |
|---|
| 41 | |
|---|
| 42 | private: |
|---|
| 43 | ClassID _classID; |
|---|
| 44 | ScriptMethod* _scriptMethods; |
|---|
| 45 | }; |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | template <class T> |
|---|
| 51 | class tScriptClass : public ScriptClass |
|---|
| 52 | { |
|---|
| 53 | public: |
|---|
| 54 | tScriptClass(const std::string& name, ClassID classID, ScriptMethod* scriptMethods) |
|---|
| 55 | : ScriptClass(name, classID, scriptMethods) |
|---|
| 56 | { } |
|---|
| 57 | |
|---|
| 58 | virtual void registerClass(Script* script) |
|---|
| 59 | { |
|---|
| 60 | Lunar<T>::Register(script, this->getName(), this->scriptMethods()); |
|---|
| 61 | } |
|---|
| 62 | virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) |
|---|
| 63 | { |
|---|
| 64 | return Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), obj->getName(), gc); |
|---|
| 65 | } |
|---|
| 66 | }; |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | #endif /* _SCRIPT_CLASS_H */ |
|---|