Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/script_engine/src/lib/script_engine/script_class.h @ 8393

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

orxonox/trunk: scriptMethod much better implemented

File size: 1.6 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    tScriptable<CLASS_NAME> global_##CLASS_NAME##_ScriptableClass(#CLASS_NAME, CLASS_ID, new SCRIPT_METHODS)
22
23
24
25//! A class for ...
26class ScriptClass : protected BaseObject
27{
28
29public:
30  virtual ~ScriptClass();
31
32  bool operator==(const std::string& name) { return (this->getName() == name); }
33  bool operator==(ClassID classID) { return (this->classID == classID); }
34
35  virtual void registerClass(Script* script) = 0;
36  virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) = 0;
37
38protected:
39  ScriptClass(const std::string& name, ClassID classID, ScriptMethod* scriptMethods);
40
41private:
42  ClassID             classID;
43  ScriptMethod*       scriptMethods;
44};
45
46
47
48
49template <class T>
50class tScriptable : public ScriptClass
51{
52public:
53  tScriptable(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);
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
67
68#endif /* _SCRIPT_CLASS_H */
Note: See TracBrowser for help on using the repository browser.