| Line |   | 
|---|
| 1 |  | 
|---|
| 2 |  | 
|---|
| 3 |  | 
|---|
| 4 | #include <iostream> | 
|---|
| 5 |  | 
|---|
| 6 | #include "luaincl.h" | 
|---|
| 7 | #include "base_object.h" | 
|---|
| 8 | #include "lunar.h" | 
|---|
| 9 |  | 
|---|
| 10 | #include "script_class.h" | 
|---|
| 11 |  | 
|---|
| 12 |  | 
|---|
| 13 | class Account : public BaseObject | 
|---|
| 14 | { | 
|---|
| 15 |   lua_Number m_balance; | 
|---|
| 16 | public: | 
|---|
| 17 |   Account(lua_State *L)      { m_balance = luaL_checknumber(L, 1); } | 
|---|
| 18 |   Account(double balance=0)    : m_balance(balance) { this->setClassID(CL_ACCOUNT, "Account"); } | 
|---|
| 19 |  | 
|---|
| 20 |   void deposit (float value) { m_balance += value; }; | 
|---|
| 21 |   void withdraw(float value) { m_balance -= value; }; | 
|---|
| 22 |   float balance() { return m_balance; }; | 
|---|
| 23 |  | 
|---|
| 24 |   int deposit (lua_State *L) { m_balance += luaL_checknumber(L, 1); return 0; } | 
|---|
| 25 |   int withdraw(lua_State *L) { m_balance -= luaL_checknumber(L, 1); return 0; } | 
|---|
| 26 |   int balance (lua_State *L) { lua_pushnumber(L, m_balance); return 1; } | 
|---|
| 27 |   ~Account() { printf("deleted Account (%p)\n", this); } | 
|---|
| 28 | }; | 
|---|
| 29 |  | 
|---|
| 30 |  | 
|---|
| 31 |  | 
|---|
| 32 | CREATE_SCRIPTABLE_CLASS(Account, CL_ACCOUNT, | 
|---|
| 33 |                         addMethod("deposit", ExecutorLua1<Account, float>(&Account::deposit)) | 
|---|
| 34 |                         ->addMethod("withdraw", ExecutorLua1<Account, float>(&Account::withdraw)) | 
|---|
| 35 |                         ->addMethod("balance", ExecutorLua0ret<Account, float>(&Account::balance))); | 
|---|
       
      
      Note: See 
TracBrowser
        for help on using the repository browser.