Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8098 in orxonox.OLD for branches


Ignore:
Timestamp:
Jun 1, 2006, 6:40:50 PM (19 years ago)
Author:
bensch
Message:

orxonox/script_engine: more executors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/script_engine/src/lib/util/executor/executor_lua.h

    r8092 r8098  
    183183////////////////////
    184184
     185
     186///////////
     187//// 0 ////
     188///////////
     189//! Executes a Function with a lua_State* parameter.
     190template<class T, typename ret> class ExecutorLua0ret : public Executor
     191{
     192  public:
     193    /**
     194     * @brief Constructor of a ExecutorXML
     195     * @param function a Function to call
     196     */
     197    ExecutorLua0ret(ret (T::*function)())
     198        : Executor()
     199    {
     200      this->functionPointer = function;
     201      this->functorType = Executor_Objective | Executor_NoLoadString;
     202    }
     203
     204    /**
     205     * @brief executes the Command on BaseObject
     206     * @param object the BaseObject to execute this Executor on
     207     * @param loadString ignored in this case
     208     */
     209    virtual void operator()(BaseObject* object, const SubString& = SubString()) const
     210    {
     211      PRINTF(1)("no usefull executor\n");
     212    }
     213
     214    virtual void operator()(BaseObject* object, int& count, void* values) const
     215    {
     216      lua_State* state = (lua_State*)values;
     217      count = 1;
     218
     219      toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))());
     220    }
     221
     222    /**
     223                       * @returns a _new_ Copy of this Executor
     224     */
     225    virtual Executor* clone () const
     226    {
     227      return new ExecutorLua0ret<T, ret>(this->functionPointer);
     228    }
     229};
     230
     231
     232
     233///////////
     234//// 1 ////
     235///////////
     236//! Executes a Function with a lua_State* parameter.
     237template<class T, typename ret, typename type0> class ExecutorLua1ret : public Executor
     238{
     239  public:
     240    /**
     241     * @brief Constructor of a ExecutorXML
     242     * @param function a Function to call
     243     */
     244    ExecutorLua1ret(ret (T::*function)(type0))
     245        : Executor(ExecutorParamType<type0>())
     246    {
     247      this->functionPointer = function;
     248      this->functorType = Executor_Objective | Executor_NoLoadString;
     249    }
     250
     251    /**
     252     * @brief executes the Command on BaseObject
     253     * @param object the BaseObject to execute this Executor on
     254     * @param loadString ignored in this case
     255     */
     256    virtual void operator()(BaseObject* object, const SubString& = SubString()) const
     257    {
     258      PRINTF(1)("no usefull executor\n");
     259    }
     260
     261    virtual void operator()(BaseObject* object, int& count, void* values) const
     262    {
     263      lua_State* state = (lua_State*)values;
     264      count = 1;
     265
     266      toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
     267                   fromLua<type0>(state, 1)));
     268    }
     269
     270    /**
     271     * @returns a _new_ Copy of this Executor
     272     */
     273    virtual Executor* clone () const
     274    {
     275      return new ExecutorLua1ret<T, ret, type0>(this->functionPointer);
     276    }
     277};
     278
    185279///////////
    186280//// 2 ////
     
    217311
    218312      toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
    219         fromLua<type0>(state, 1),
    220         fromLua<type1>(state, 2) ));
     313                   fromLua<type0>(state, 1),
     314                   fromLua<type1>(state, 2) ));
    221315    }
    222316
Note: See TracChangeset for help on using the changeset viewer.