#include #include "luaincl.h" #include "base_object.h" #include "lunar.h" #include "script_class.h" class Account : public BaseObject { lua_Number m_balance; public: Account(lua_State *L) { m_balance = luaL_checknumber(L, 1); } Account(double balance=0) : m_balance(balance) { this->setClassID(CL_ACCOUNT, "Account"); } void deposit (float value) { m_balance += value; }; void withdraw(float value) { m_balance -= value; }; float balance() { return m_balance; }; int deposit (lua_State *L) { m_balance += luaL_checknumber(L, 1); return 0; } int withdraw(lua_State *L) { m_balance -= luaL_checknumber(L, 1); return 0; } int balance (lua_State *L) { lua_pushnumber(L, m_balance); return 1; } ~Account() { printf("deleted Account (%p)\n", this); } }; CREATE_SCRIPTABLE_CLASS(Account, CL_ACCOUNT, addMethod("deposit", ExecutorLua1(&Account::deposit)) ->addMethod("withdraw", ExecutorLua1(&Account::withdraw)) ->addMethod("balance", ExecutorLua0ret(&Account::balance)));