Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/heathaze/src/lib/script_engine/account.cc @ 10610

Last change on this file since 10610 was 8408, checked in by bensch, 19 years ago

trunk: merged the script_engine branche back here
merged with command
svn merge https://svn.orxonox.net/orxonox/branches/script_engine . -r8284:HEAD
no conflicts

File size: 1.1 KB
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
13class Account : public BaseObject
14{
15  lua_Number m_balance;
16public:
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
32CREATE_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.