Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8101 in orxonox.OLD


Ignore:
Timestamp:
Jun 1, 2006, 7:24:22 PM (18 years ago)
Author:
bensch
Message:

EXECUTOR USED

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

Legend:

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

    r8100 r8101  
    11MAINSRCDIR=../..
    22include $(MAINSRCDIR)/defs/include_paths.am
     3
     4
     5LIB_PREFIX=$(MAINSRCDIR)/lib
     6include $(MAINSRCDIR)/lib/BuildLibs.am
     7
     8
    39
    410INCLUDES= -I../../../extern_libs
     
    1319
    1420bin_PROGRAMS = example
    15 example_SOURCES = \
    16                 example.cc \
    17                 \
    18                 ../util/executor/executor_lua.cc
    1921
    2022
    21 
    22 
    23 example_LDADD = libORXscript.a -L../../../extern_libs @LUA_LIBS@
    24 
    25 #main_LDFLAGS =
    2623
    2724
     
    3128                script.h\
    3229                script_manager.h
     30
     31
     32
     33example_DEPENDENCIES = \
     34                $(MAINSRCDIR)/world_entities/libORXwe.a \
     35                $(libORXlibs_a_LIBRARIES_) \
     36                $(MAINSRCDIR)/util/libORXutils.a
     37
     38example_LDADD = \
     39                $(MAINSRCDIR)/util/libORXutils.a \
     40                $(libORXlibs_a_LIBRARIES_) \
     41                libORXscript.a -L../../../extern_libs @LUA_LIBS@ \
     42                $(MAINSRCDIR)/world_entities/libORXwe.a \
     43                $(libORXlibs_a_LIBRARIES_) \
     44                $(MAINSRCDIR)/util/libORXutils.a
     45
     46example_SOURCES= \
     47                example.cc \
     48                \
     49                ../util/executor/executor_lua.cc
  • branches/script_engine/src/lib/script_engine/example.cc

    r8093 r8101  
    66#include "script.h"
    77
    8     class Account {
     8
     9    class Account : public BaseObject {
    910      lua_Number m_balance;
    1011    public:
     
    1415      Account(lua_State *L)      { m_balance = luaL_checknumber(L, 1); }
    1516      Account(double balance=0)    : m_balance(balance) { }
     17
     18      void deposit (float value) { m_balance += value; };
     19      void withdraw(float value) { m_balance -= value; };
     20      float balance() { return m_balance; };;;;;;;;;;;;;;
     21
    1622      int deposit (lua_State *L) { m_balance += luaL_checknumber(L, 1); return 0; }
    1723      int withdraw(lua_State *L) { m_balance -= luaL_checknumber(L, 1); return 0; }
     
    2632
    2733    Lunar<Account>::RegType Account::methods[] = {
    28       method(Account, deposit),
    29       method(Account, withdraw),
    30       method(Account, balance),
    31       {0,0}
     34      {"deposit", new ExecutorLua1<Account, float>(&Account::deposit)},
     35      {"withdraw", new ExecutorLua1<Account, float>(&Account::withdraw)},
     36      {"balance", new ExecutorLua0ret<Account, float>(&Account::balance)},
     37      {0,NULL}
    3238    };
    3339
    3440
    35     class Object {
     41    class Object : public BaseObject {
    3642      public:
    3743        static const char className[];
     
    4753        {
    4854         int calls = getCallCount();
    49          lua_pushnumber(L,(lua_Number)calls); 
     55         lua_pushnumber(L,(lua_Number)calls);
    5056         return 1; // return number of values that the function wants to return to lua
    5157        }
     
    5359         //function that takes an argument from lua
    5460         int takeParam(lua_State* L)
    55          { 
     61         {
    5662          int param = (int)lua_tonumber(L,-1);
    5763          takeParam(param);
    58           return 0; 
     64          return 0;
    5965         }
    6066
     
    6773        int printName(lua_State* L)
    6874        {
    69           callCount ++;
    70           printf("Hi i'm object %p ! This is the %i. call.\n",this,callCount);
     75          this->printName();
    7176          return 0;
    7277        }
    7378
    74         int getCallCount(){return callCount;}
     79        void printName()
     80        {
     81          callCount ++;
     82          printf("Hi i'm object %p ! This is the %i. call.\n",this,callCount);
     83        }
     84
     85        int getCallCount(){ return callCount; }
    7586
    7687      private:
     
    8293
    8394    Lunar<Object>::RegType Object::methods[] = {
    84       method(Object, printName),
    85       method(Object, getCallCount),
    86       method(Object, takeParam),
     95      {"printName", new ExecutorLua0<Object>(&Object::printName)},
     96      {"getCallCount", new ExecutorLua0ret<Object, int>(&Object::getCallCount)},
     97      {"takeParam", new ExecutorLua1<Object, int>(&Object::takeParam)},
    8798      {0,0}
    8899    };
     
    123134      float retf = script.getReturnedFloat();
    124135      printf("main returned %f\n",retf);
    125      
     136
    126137
    127138      if(script.getReturnedBool())
     
    142153      script.executeFunction();
    143154
    144      
     155
    145156      //if(argc>1) lua_dofile(script.getLuaState(), argv[1]);
    146157      printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
  • branches/script_engine/src/lib/script_engine/lunar.h

    r8092 r8101  
    1313      typedef struct { T *pT; } userdataType;
    1414    public:
    15       typedef int (T::*mfp)(lua_State *L);
     15      typedef Executor* mfp;
    1616      typedef struct { const char *name; mfp mfunc; } RegType;
    1717
     
    164164        // get member function from upvalue
    165165        RegType *l = static_cast<RegType*>(lua_touserdata(L, lua_upvalueindex(1)));
    166         return (obj->*(l->mfunc))(L);  // call member function
     166        int value;
     167        (*l->mfunc)(obj, value, L);  // call member function
     168        return value;
    167169      }
    168170
  • branches/script_engine/src/lib/util/executor/executor_lua.h

    r8098 r8101  
    7575      return new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer));
    7676    }
     77  private:
     78    void          (T::*functionPointer)();
    7779};
    7880
     
    122124      return new ExecutorLua1<T, type0>((this->functionPointer));
    123125    }
     126  private:
     127    void          (T::*functionPointer)(type0);
    124128};
    125129
     
    171175      return new ExecutorLua2<T, type0, type1>(this->functionPointer);
    172176    }
     177  private:
     178    void          (T::*functionPointer)(type0, type1);
    173179};
    174180
     
    227233      return new ExecutorLua0ret<T, ret>(this->functionPointer);
    228234    }
     235  private:
     236    ret           (T::*functionPointer)();
    229237};
    230238
     
    275283      return new ExecutorLua1ret<T, ret, type0>(this->functionPointer);
    276284    }
     285  private:
     286    ret           (T::*functionPointer)(type0);
    277287};
    278288
     
    322332      return new ExecutorLua2ret<T, ret, type0, type1>(this->functionPointer);
    323333    }
     334  private:
     335    ret           (T::*functionPointer)(type0, type1);
    324336};
    325337
Note: See TracChangeset for help on using the changeset viewer.