Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8390 in orxonox.OLD


Ignore:
Timestamp:
Jun 14, 2006, 3:33:04 PM (18 years ago)
Author:
bensch
Message:

script: added scriptMethod, for better handling of Script-Functions/Methods…

Location:
branches/script_engine/src/lib/script_engine
Files:
4 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/script_engine/src/lib/script_engine/Makefile.am

    r8271 r8390  
    1313
    1414libORXscript_a_SOURCES = \
    15                 script.cc\
    16                 script_manager.cc\
    17                 script_class.cc\
     15                script.cc \
     16                script_manager.cc \
     17                script_class.cc \
     18                script_method.cc \
     19                \
    1820                account.cc \
    1921                object.cc
     
    2527                lunar.h\
    2628                script.h\
    27                 script_manager.h\
    28                 script_class.h
     29                script_manager.h \
     30                script_class.h \
     31                script_method.h
    2932
    3033
     
    3235
    3336check_PROGRAMS = example
    34 
    35 
    36 
    37 
    38 
    39 
    40 
    4137example_DEPENDENCIES = \
    4238                $(MAINSRCDIR)/world_entities/libORXwe.a \
    4339                $(libORXlibs_a_LIBRARIES_) \
    4440                $(MAINSRCDIR)/util/libORXutils.a
    45 
    4641example_LDADD = \
    4742                $(MAINSRCDIR)/util/libORXutils.a \
  • branches/script_engine/src/lib/script_engine/script.cc

    r8380 r8390  
    9595 {
    9696   printf("Script %p: I am about to add %s of class %s\n",this,objectName.c_str(),className.c_str());
    97    
     97
    9898   BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
    9999   printf("The script class for %s is at %p \n",className.c_str(),scriptClass);
     
    171171     reportError(error);
    172172     //clean up
    173      currentFunction.assign(""); 
     173     currentFunction.assign("");
    174174     argumentCount = returnCount = 0;
    175175     return false;
     
    184184   else
    185185     printf("Error: no function selected.\n");
    186    
     186
    187187   return false;
    188188 }
     
    241241 int Script::getReturnedInt()
    242242 {
    243    int returnValue;
     243   int returnValue = 0;
    244244   if(returnCount > 0)
    245245   {
     
    257257 bool Script::getReturnedBool()
    258258 {
    259    bool returnValue;
     259   bool returnValue = false;
    260260   if(returnCount > 0)
    261261   {
     
    272272float Script::getReturnedFloat()
    273273 {
    274    float returnValue;
     274   float returnValue = 0.0f;
    275275   if(returnCount > 0)
    276276   {
     
    287287 void Script::getReturnedString(std::string& string)
    288288 {
    289    const char* returnValue;
     289   const char* returnValue = "";
    290290   if(returnCount > 0)
    291291   {
  • branches/script_engine/src/lib/script_engine/script_class.cc

    r8271 r8390  
    1717
    1818#include "script_class.h"
    19 
    20 using namespace std;
    21 
    2219
    2320/**
  • branches/script_engine/src/lib/script_engine/script_class.h

    r8289 r8390  
    1111#include "script.h"
    1212#include "lunar.h"
    13 
    14 // FORWARD DECLARATION
    15 
    1613
    1714/**
     
    2825{
    2926
    30   public:
    31     virtual ~ScriptClass();
     27public:
     28  virtual ~ScriptClass();
    3229
    33     bool operator==(const std::string& name) { return (this->getName() == name); }
    34     bool operator==(ClassID classID) { return (this->classID == classID); }
     30  bool operator==(const std::string& name) { return (this->getName() == name); }
     31  bool operator==(ClassID classID) { return (this->classID == classID); }
    3532
    36     virtual void registerClass(Script* script) = 0;
    37     virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) = 0;
     33  virtual void registerClass(Script* script) = 0;
     34  virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) = 0;
    3835
    39   protected:
    40     ScriptClass(const std::string& name, ClassID classID);
     36protected:
     37  ScriptClass(const std::string& name, ClassID classID);
    4138
    42   private:
    43     ClassID             classID;
     39private:
     40  ClassID             classID;
    4441};
    4542
     
    5047class tScriptable : public ScriptClass
    5148{
    52   public:
    53     tScriptable(const std::string& name, ClassID classID)
    54         : ScriptClass(name, classID)
    55     { }
     49public:
     50  tScriptable(const std::string& name, ClassID classID)
     51      : ScriptClass(name, classID)
     52  { }
    5653
    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 }
    69 ;
     54  virtual void registerClass(Script* script)
     55  {
     56    Lunar<T>::Register(script);
     57  }
     58  virtual int insertObject(Script* L, BaseObject* obj, bool gc=false)
     59  {
     60    return Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), obj->getName(), gc);
     61  }
     62};
    7063
    7164
  • branches/script_engine/src/lib/script_engine/script_method.cc

    r8387 r8390  
    1616//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
    1717
    18 #include "script_class.h"
    19 
    20 using namespace std;
    21 
     18#include "script_method.h"
    2219
    2320/**
    24  * standard constructor
     21 * @param standard constructor
    2522 * @todo this constructor is not jet implemented - do it
    2623*/
    27 ScriptClass::ScriptClass(const std::string& name, ClassID classID)
    28  : BaseObject(name)
     24ScriptMethod::ScriptMethod(const std::string& methodName, const Executor& executor)
    2925{
    30    this->setClassID(CL_SCRIPT_CLASS, "ScriptClass");
    31    this->classID = classID;
     26  this->addMethod(methodName, executor);
    3227}
    3328
     29ScriptMethod& ScriptMethod::addMethod(const std::string& methodName, const Executor& executor)
     30{
     31  this->methods.push_back(ScriptMethod::Method(methodName, executor));
     32
     33  return *this;
     34}
     35
     36ScriptMethod::Method::Method(const std::string& name, const Executor& executor)
     37{
     38  this->name = name;
     39  this->executor = executor.clone();
     40}
    3441
    3542/**
    3643 * standard deconstructor
    3744*/
    38 ScriptClass::~ScriptClass ()
     45ScriptMethod::~ScriptMethod()
    3946{
    40   // delete what has to be deleted here
     47  for (unsigned int i = 0; i < methods.size(); i ++)
     48  {
     49    delete methods[i].executor;
     50  };
    4151}
     52
     53
     54
  • branches/script_engine/src/lib/script_engine/script_method.h

    r8387 r8390  
    44*/
    55
    6 #ifndef _SCRIPT_CLASS_H
    7 #define _SCRIPT_CLASS_H
     6#ifndef _SCRIPT_METHOD_H
     7#define _SCRIPT_METHOD_H
    88
    9 #include "base_object.h"
     9#include <vector>
    1010
    11 #include "script.h"
    1211#include "lunar.h"
    13 
    14 // FORWARD DECLARATION
     12#include "executor/executor_lua.h"
    1513
    1614
    17 /**
    18  * Creates a factory to a Loadable Class.
    19  * this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
    20  */
    21 #define CREATE_SCRIPTABLE_CLASS(CLASS_NAME, CLASS_ID) \
    22     tScriptable<CLASS_NAME> global_##CLASS_NAME##_ScriptableClass(#CLASS_NAME, CLASS_ID)
     15class ScriptMethod
     16{
     17public:
     18  ScriptMethod(const std::string& methodName, const Executor& executor);
     19  ~ScriptMethod();
     20
     21  ScriptMethod& addMethod(const std::string& methodName, const Executor& executor);
    2322
    2423
     24private:
     25  struct Method
     26  {
     27    Method(const std::string& name, const Executor& executor);
     28    std::string    name;
     29    Executor*      executor;
     30  };
    2531
    26 //! A class for ...
    27 class ScriptClass : protected BaseObject
    28 {
    29 
    30   public:
    31     virtual ~ScriptClass();
    32 
    33     bool operator==(const std::string& name) { return (this->getName() == name); }
    34     bool operator==(ClassID classID) { return (this->classID == classID); }
    35 
    36     virtual void registerClass(Script* script) = 0;
    37     virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) = 0;
    38 
    39   protected:
    40     ScriptClass(const std::string& name, ClassID classID);
    41 
    42   private:
    43     ClassID             classID;
     32  std::vector<Method> methods;
    4433};
    4534
    46 
    47 
    48 
    49 template <class T>
    50 class tScriptable : public ScriptClass
    51 {
    52   public:
    53     tScriptable(const std::string& name, ClassID classID)
    54         : ScriptClass(name, classID)
    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 }
    69 ;
    70 
    71 
    72 #endif /* _SCRIPT_CLASS_H */
     35#endif /* _SCRIPT_METHOD_H */
Note: See TracChangeset for help on using the changeset viewer.