Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/script_engine/script_class.h @ 8937

Last change on this file since 8937 was 8408, checked in by bensch, 18 years ago

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

File size: 1.7 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
37  const ScriptMethod* scriptMethods() const { return this->_scriptMethods; }
38
39protected:
40  ScriptClass(const std::string& name, ClassID classID, ScriptMethod* scriptMethods);
41
42private:
43  ClassID             _classID;
44  ScriptMethod*       _scriptMethods;
45};
46
47
48
49
50template <class T>
51class tScriptClass : public ScriptClass
52{
53public:
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 */
Note: See TracBrowser for help on using the repository browser.