Rev | Line | |
---|
[8250] | 1 | |
---|
| 2 | |
---|
| 3 | |
---|
[8248] | 4 | #include <iostream> |
---|
| 5 | |
---|
| 6 | #include "luaincl.h" |
---|
[8250] | 7 | #include "base_object.h" |
---|
| 8 | #include "lunar.h" |
---|
[8248] | 9 | |
---|
[8250] | 10 | #include "script_class.h" |
---|
[8248] | 11 | |
---|
[8250] | 12 | |
---|
[8408] | 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"); } |
---|
[8248] | 19 | |
---|
[8408] | 20 | void deposit (float value) { m_balance += value; }; |
---|
| 21 | void withdraw(float value) { m_balance -= value; }; |
---|
| 22 | float balance() { return m_balance; }; |
---|
[8248] | 23 | |
---|
[8408] | 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 | }; |
---|
[8248] | 29 | |
---|
| 30 | |
---|
| 31 | |
---|
[8408] | 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.