Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/lib/script_engine/account.cc @ 8349

Last change on this file since 8349 was 8271, checked in by bensch, 19 years ago

merge

File size: 1.3 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
13 class Account : public BaseObject {
14      lua_Number m_balance;
15   public:
16     static const char className[];
17     static Lunar<Account>::RegType methods[];
18
19     Account(lua_State *L)      { m_balance = luaL_checknumber(L, 1); }
20     Account(double balance=0)    : m_balance(balance) { this->setClassID(CL_ACCOUNT, "Account"); }
21
22     void deposit (float value) { m_balance += value; };
23     void withdraw(float value) { m_balance -= value; };
24     float balance() { return m_balance; };
25
26     int deposit (lua_State *L) { m_balance += luaL_checknumber(L, 1); return 0; }
27     int withdraw(lua_State *L) { m_balance -= luaL_checknumber(L, 1); return 0; }
28     int balance (lua_State *L) { lua_pushnumber(L, m_balance); return 1; }
29     ~Account() { printf("deleted Account (%p)\n", this); }
30 };
31
32 const char Account::className[] = "Account";
33
34 Lunar<Account>::RegType Account::methods[] = {
35   {"deposit", new ExecutorLua1<Account, float>(&Account::deposit)},
36   {"withdraw", new ExecutorLua1<Account, float>(&Account::withdraw)},
37   {"balance", new ExecutorLua0ret<Account, float>(&Account::balance)},
38   {0,NULL}
39 };
40
41 CREATE_SCRIPTABLE_CLASS(Account, CL_ACCOUNT);
42
Note: See TracBrowser for help on using the repository browser.