Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8057 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Jun 1, 2006, 1:30:11 PM (18 years ago)
Author:
bensch
Message:

trunk: some lua-stuff

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

Legend:

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

    r8051 r8057  
    1818#include "executor_lua.h"
    1919
    20 template<> bool fromLua<bool>(lua_state* state) { return lua_tonumber(state); };
    21 template<> int fromLua<int>(lua_state* state);
    22 template<> unsigned int fromLua<unsigned int>(lua_state* state);
    23 template<> float fromLua<float>(lua_state* state);
    24 template<> char fromLua<char>(lua_state* state);
    25 template<> const std::string& fromLua<const std::string&>(lua_state* state);
     20template<> bool fromLua<bool>(lua_state* state, int index) { return lua_toboolean(state, index); };
     21template<> int fromLua<int>(lua_state* state, int index) { return (int)lua_toumber(state, index); };
     22template<> unsigned int fromLua<unsigned int>(lua_state* state, int index) { return (unsigned int)lua_tonumber(state, index); };
     23template<> float fromLua<float>(lua_state* state, int index) { return (float)lua_tonumber(state, index); };
     24template<> char fromLua<char>(lua_state* state, int index) { reutnr (char)lua_tonumber(state, index); };
     25template<> const std::string& fromLua<const std::string&>(lua_state* state, int index) { return lua_tostring(state, index); };
    2626
     27
     28
     29template<> void toLua<bool>(lua_state* state, bool value) { lua_pushboolean(state, (int) value); };
     30template<> void toLua<int>(lua_state* state, int value)  { lua_pushnumber(state, (lua_Number) value); };
     31template<> void toLua<unsigned int>(lua_state* state, unsigned int value){ lua_pushnumber(state, (lua_Number) value); };
     32template<> void toLua<float>(lua_state* state, float value) { lua_pushnumber(state, (lua_Number) value); };
     33template<> void toLua<char>(lua_state* state, char value) { lua_pushnumber(state, (lua_Number) value); };
     34template<> void toLua<const std::string&>(lua_state* state, const std::string& value) {lua_pushstring (state, value.c_str()); }
  • trunk/src/lib/util/executor/executor_lua.h

    r8051 r8057  
    1414
    1515
    16 template<typename type> type fromLua(lua_state* state) { PRINTF(1)("NOT IMPLEMENTED\n"); };
    17 template<> bool fromLua<bool>(lua_state* state);
    18 template<> int fromLua<int>(lua_state* state);
    19 template<> unsigned int fromLua<unsigned int>(lua_state* state);
    20 template<> float fromLua<float>(lua_state* state);
    21 template<> char fromLua<char>(lua_state* state);
    22 template<> const std::string& fromLua<const std::string&>(lua_state* state);
     16template<typename type> type fromLua(lua_state* state, int index) { PRINTF(1)("NOT IMPLEMENTED\n"); };
     17template<> bool fromLua<bool>(lua_state* state, int index);
     18template<> int fromLua<int>(lua_state* state, int index);
     19template<> unsigned int fromLua<unsigned int>(lua_state* state, int index);
     20template<> float fromLua<float>(lua_state* state, int index);
     21template<> char fromLua<char>(lua_state* state, int index);
     22template<> const std::string& fromLua<const std::string&>(lua_state* state, int index);
     23
     24
     25template<typename type> void toLua(lua_state* state, type value) { PRINTF(1)("NOT IMPLEMENTED\n"); };
     26template<> void toLua<bool>(lua_state* state, bool value);
     27template<> void toLua<int>(lua_state* state, int value);
     28template<> void toLua<unsigned int>(lua_state* state, unsigned int value);
     29template<> void toLua<float>(lua_state* state, float value);
     30template<> void toLua<char>(lua_state* state, char value);
     31template<> void toLua<const std::string&>(lua_state* state, const std::string& value);
    2332
    2433// FORWARD DECLARATION
     
    3140template<class T> class ExecutorLua0 : public Executor
    3241{
    33 public:
    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   }
     42  public:
     43    /**
     44     * @brief Constructor of a ExecutorXML
     45     * @param function a Function to call
     46     */
     47    ExecutorLua0(void(T::*function)())
     48        : Executor()
     49    {
     50      this->functionPointer = function;
     51      this->functorType = Executor_Objective | Executor_NoLoadString;
     52    }
    4453
    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     * @brief executes the Command on BaseObject
     56     * @param object the BaseObject to execute this Executor on
     57     * @param loadString ignored in this case
     58     */
     59    virtual void operator()(BaseObject* object, const SubString& = SubString()) const
     60    {
     61      PRINTF(1)("no usefull executor\n");
     62    }
    5463
    55   virtual void operator()(BaseObject* object, unsigned int count, void* values) const
    56   {
    57     (dynamic_cast<T*>(object)->*(functionPointer))();
    58   }
     64    virtual void operator()(BaseObject* object, unsigned int count, void* values) const
     65    {
     66      (dynamic_cast<T*>(object)->*(functionPointer))();
     67    }
    5968
    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   }
     69    /**
     70     * @returns a _new_ Copy of this Executor
     71     */
     72    virtual Executor* clone () const
     73    {
     74      return = new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer));
     75    }
    6776};
    6877
     
    7685{
    7786  public:
    78   /**
    79    * @brief Constructor of a ExecutorXML
    80    * @param function a Function to call
    81    */
     87    /**
     88     * @brief Constructor of a ExecutorXML
     89     * @param function a Function to call
     90     */
    8291    ExecutorLua0(void(T::*function)(type0))
    83   : Executor(ExecutorParamType<type0>())
     92        : Executor(ExecutorParamType<type0>())
    8493    {
    8594      this->functionPointer = function;
     
    8796    }
    8897
    89   /**
    90      * @brief executes the Command on BaseObject
    91      * @param object the BaseObject to execute this Executor on
    92      * @param loadString ignored in this case
    93    */
     98    /**
     99       * @brief executes the Command on BaseObject
     100       * @param object the BaseObject to execute this Executor on
     101       * @param loadString ignored in this case
     102     */
    94103    virtual void operator()(BaseObject* object, const SubString& = SubString()) const
    95104    {
     
    100109    {
    101110      lua_state* state = (lua_state*)values;
    102       type0 value0 = lua_pop values
    103111
    104       (dynamic_cast<T*>(object)->*(functionPointer))();
     112      (dynamic_cast<T*>(object)->*(functionPointer))(fromLua<type0>(state, 1));
    105113    }
    106114
    107   /**
    108      * @returns a _new_ Copy of this Executor
    109    */
     115    /**
     116       * @returns a _new_ Copy of this Executor
     117     */
    110118    virtual Executor* clone () const
    111119    {
     
    115123
    116124
     125
     126///////////
     127//// 2 ////
     128///////////
     129//! Executes a Function with a lua_state* parameter.
     130template<class T, typename type0, typename type1> class ExecutorLua1 : public Executor
     131{
     132  public:
     133    /**
     134     * @brief Constructor of a ExecutorXML
     135     * @param function a Function to call
     136     */
     137    ExecutorLua0(void(T::*function)(type0, type1))
     138        : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>())
     139    {
     140      this->functionPointer = function;
     141      this->functorType = Executor_Objective | Executor_NoLoadString;
     142    }
     143
     144    /**
     145     * @brief executes the Command on BaseObject
     146     * @param object the BaseObject to execute this Executor on
     147     * @param loadString ignored in this case
     148     */
     149    virtual void operator()(BaseObject* object, const SubString& = SubString()) const
     150    {
     151      PRINTF(1)("no usefull executor\n");
     152    }
     153
     154    virtual void operator()(BaseObject* object, unsigned int count, void* values) const
     155    {
     156      lua_state* state = (lua_state*)values;
     157
     158      (dynamic_cast<T*>(object)->*(functionPointer))(
     159        fromLua<type0>(state, 1),
     160        fromLua<type1>(state, 2) );
     161    }
     162
     163    /**
     164     * @returns a _new_ Copy of this Executor
     165     */
     166    virtual Executor* clone () const
     167    {
     168      return = new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer));
     169    }
     170};
     171
     172
     173
    117174#endif /* _EXECUTOR_SPECIALS_H */
Note: See TracChangeset for help on using the changeset viewer.