Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

EXECUTOR USED

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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()));
Note: See TracChangeset for help on using the changeset viewer.