Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain.older/src/lib/script_engine/script_class.h @ 10661

Last change on this file since 10661 was 9003, checked in by bensch, 19 years ago

orxonox/trunk: merged the single_player_map branche back
merged with command:
svn merge -r8896:HEAD https://svn.orxonox.net/orxonox/branches/single_player_map .
no conflicts

File size: 2.0 KB
Line 
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 ...
25class ScriptClass : protected BaseObject
26{
27
28public:
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  virtual int insertObject(Script* L, BaseObject* obj, const std::string& name, bool gc=false) = 0; 
37
38  const ScriptMethod* scriptMethods() const { return this->_scriptMethods; }
39
40protected:
41  ScriptClass(const std::string& name, ClassID classID, ScriptMethod* scriptMethods);
42
43private:
44  ClassID             _classID;
45  ScriptMethod*       _scriptMethods;
46};
47
48
49
50
51template <class T>
52class tScriptClass : public ScriptClass
53{
54public:
55  tScriptClass(const std::string& name, ClassID classID, ScriptMethod* scriptMethods)
56      : ScriptClass(name, classID, scriptMethods)
57  { }
58
59  virtual void registerClass(Script* script)
60  {
61    Lunar<T>::Register(script, this->getName(), this->scriptMethods());
62  }
63  virtual int insertObject(Script* L, BaseObject* obj, bool gc=false)
64  {
65    return Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), obj->getName(), gc);
66  }
67
68  virtual int insertObject(Script* L, BaseObject* obj,const std::string& name, bool gc=false)
69  {
70    return Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), name, gc);
71  }
72};
73
74
75#endif /* _SCRIPT_CLASS_H */
Note: See TracBrowser for help on using the repository browser.