Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8051 in orxonox.OLD for trunk/src/lib/util


Ignore:
Timestamp:
Jun 1, 2006, 12:57:57 AM (19 years ago)
Author:
bensch
Message:

lua: new Executor for lua-interpretation

Location:
trunk/src/lib/util/executor
Files:
1 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/executor/executor_lua.cc

    r8042 r8051  
    1616//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
    1717
    18 #include "proto_class.h"
     18#include "executor_lua.h"
    1919
    20 using namespace std;
     20template<> bool fromLua<bool>(lua_state* state) { return lua_tonumber(state); };
     21template<> int fromLua<int>(lua_state* state);
     22template<> unsigned int fromLua<unsigned int>(lua_state* state);
     23template<> float fromLua<float>(lua_state* state);
     24template<> char fromLua<char>(lua_state* state);
     25template<> const std::string& fromLua<const std::string&>(lua_state* state);
    2126
    22 
    23 /**
    24  * standard constructor
    25  * @todo this constructor is not jet implemented - do it
    26 */
    27 ProtoClass::ProtoClass ()
    28 {
    29    this->setClassID(CL_PROTO_ID, "ProtoClass");
    30 
    31    /* If you make a new class, what is most probably the case when you write this file
    32       don't forget to:
    33        1. Add the new file new_class.cc to the ./src/Makefile.am
    34        2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS
    35 
    36       Advanced Topics:
    37       - if you want to let your object be managed via the ObjectManager make sure to read
    38         the object_manager.h header comments. You will use this most certanly only if you
    39         make many objects of your class, like a weapon bullet.
    40    */
    41 }
    42 
    43 
    44 /**
    45  * standard deconstructor
    46 */
    47 ProtoClass::~ProtoClass ()
    48 {
    49   // delete what has to be deleted here
    50 }
  • trunk/src/lib/util/executor/executor_lua.h

    r8048 r8051  
    1010#include "compiler.h"
    1111
    12 #include "compiler.h"
    13 #include "parser/tinyxml/tinyxml.h"
     12#include "luaincl.h"
     13
     14
     15
     16template<typename type> type fromLua(lua_state* state) { PRINTF(1)("NOT IMPLEMENTED\n"); };
     17template<> bool fromLua<bool>(lua_state* state);
     18template<> int fromLua<int>(lua_state* state);
     19template<> unsigned int fromLua<unsigned int>(lua_state* state);
     20template<> float fromLua<float>(lua_state* state);
     21template<> char fromLua<char>(lua_state* state);
     22template<> const std::string& fromLua<const std::string&>(lua_state* state);
     23
    1424// FORWARD DECLARATION
    1525
    16 //! Executes a Function with a const TiXmlElement* parameter.
    17 /**
    18  * This is a Special Executor, that finds ParamName in root as XML-sub-element
    19  * This is especially usefull, if you have to Load a SubElement from root in a new Function
    20  * What must be defined is a XML-root to search the ParameterName under an  a Function to call.
    21  */
    22 template<class T> class ExecutorXML : public Executor
     26
     27///////////
     28//// 0 ////
     29///////////
     30//! Executes a Function with a lua_state* parameter.
     31template<class T> class ExecutorLua0 : public Executor
     32{
     33public:
     34  /**
     35   * @brief Constructor of a ExecutorXML
     36   * @param function a Function to call
     37   */
     38  ExecutorLua0(void(T::*function)())
     39      : Executor()
     40  {
     41    this->functionPointer = function;
     42    this->functorType = Executor_Objective | Executor_NoLoadString;
     43  }
     44
     45  /**
     46   * @brief executes the Command on BaseObject
     47   * @param object the BaseObject to execute this Executor on
     48   * @param loadString ignored in this case
     49   */
     50  virtual void operator()(BaseObject* object, const SubString& = SubString()) const
     51  {
     52    PRINTF(1)("no usefull executor\n");
     53  }
     54
     55  virtual void operator()(BaseObject* object, unsigned int count, void* values) const
     56  {
     57    (dynamic_cast<T*>(object)->*(functionPointer))();
     58  }
     59
     60  /**
     61   * @returns a _new_ Copy of this Executor
     62   */
     63  virtual Executor* clone () const
     64  {
     65    return = new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer));
     66  }
     67};
     68
     69
     70
     71///////////
     72//// 1 ////
     73///////////
     74//! Executes a Function with a lua_state* parameter.
     75template<class T, typename type0> class ExecutorLua1 : public Executor
    2376{
    2477  public:
    25     /**
     78  /**
    2679   * @brief Constructor of a ExecutorXML
    27      * @param function a Function to call
    28      * @param root The XML root to search paramName under
    29      * @param paramName the ParameterName the search in root, and lookup the TiXmlElement from
    30      */
    31     ExecutorXML(void(T::*function)(const TiXmlElement*), const TiXmlElement* root, const char* paramName)
    32       : Executor(MT_EXT1)
     80   * @param function a Function to call
     81   */
     82    ExecutorLua0(void(T::*function)(type0))
     83  : Executor(ExecutorParamType<type0>())
    3384    {
    34       PRINTF(4)("Loading %s from XML-element %p\n", paramName, root);
    35 
    36       if (likely(root != NULL && paramName != NULL))
    37         this->element = root->FirstChildElement(paramName);
    38       else
    39         this->element = NULL;
    40 
    4185      this->functionPointer = function;
    4286      this->functorType = Executor_Objective | Executor_NoLoadString;
    4387    }
    4488
    45     /**
    46      * @brief clones an ExecutorXML, used to copy this Element.
    47      * @returns a _new_ Copy of this Executor
    48      */
    49     virtual Executor* clone () const
    50     {
    51       ExecutorXML<T>* executor = new ExecutorXML<T>();
    52       this->cloning(executor);
    53       executor->functionPointer = this->functionPointer;
    54       executor->element = this->element;
    55       return executor;
    56     }
    57 
    58     /**
     89  /**
    5990     * @brief executes the Command on BaseObject
    6091     * @param object the BaseObject to execute this Executor on
    6192     * @param loadString ignored in this case
    62      */
     93   */
    6394    virtual void operator()(BaseObject* object, const SubString& = SubString()) const
    6495    {
    65       if (object != NULL && this->element != NULL)
    66         (dynamic_cast<T*>(object)->*(functionPointer))(this->element);
     96      PRINTF(1)("no usefull executor\n");
    6797    }
    6898
    6999    virtual void operator()(BaseObject* object, unsigned int count, void* values) const
    70100    {
    71       PRINTF(1)("missuse of XML-operator, OR IMPLEMENT.\n");
     101      lua_state* state = (lua_state*)values;
     102      type0 value0 = lua_pop values
     103
     104      (dynamic_cast<T*>(object)->*(functionPointer))();
    72105    }
    73106
    74   private:
    75     /**
    76    * @brief used for the copy-(Clone)-constructor
    77      */
    78     ExecutorXML() : Executor() { };
     107  /**
     108     * @returns a _new_ Copy of this Executor
     109   */
     110    virtual Executor* clone () const
     111    {
     112      return = new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer));
     113    }
     114};
    79115
    80116
    81   private:
    82     void    (T::*functionPointer)(const TiXmlElement*);  //!< The functionPointer to the function to be called
    83     const   TiXmlElement* element;                       //!< The XML-element to call.
    84 };
    85 
    86117#endif /* _EXECUTOR_SPECIALS_H */
  • trunk/src/lib/util/executor/executor_xml.h

    r8048 r8051  
    1010#include "compiler.h"
    1111
    12 #include "compiler.h"
    1312#include "parser/tinyxml/tinyxml.h"
    14 // FORWARD DECLARATION
    1513
    1614//! Executes a Function with a const TiXmlElement* parameter.
Note: See TracChangeset for help on using the changeset viewer.