- Timestamp:
- Jun 14, 2006, 5:31:13 PM (18 years ago)
- Location:
- branches/script_engine/src/lib/script_engine
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/script_engine/src/lib/script_engine/account.cc
r8401 r8404 11 11 12 12 13 class Account : public BaseObject { 14 lua_Number m_balance; 15 public: 16 // static const char className[]; 17 static Lunar<Account>::RegType methods[]; 13 class Account : public BaseObject 14 { 15 lua_Number m_balance; 16 public: 17 // static const char className[]; 18 static Lunar<Account>::RegType methods[]; 18 19 19 20 20 Account(lua_State *L) { m_balance = luaL_checknumber(L, 1); } 21 Account(double balance=0) : m_balance(balance) { this->setClassID(CL_ACCOUNT, "Account"); } 21 22 22 23 24 23 void deposit (float value) { m_balance += value; }; 24 void withdraw(float value) { m_balance -= value; }; 25 float balance() { return m_balance; }; 25 26 26 27 28 29 30 27 int deposit (lua_State *L) { m_balance += luaL_checknumber(L, 1); return 0; } 28 int withdraw(lua_State *L) { m_balance -= luaL_checknumber(L, 1); return 0; } 29 int balance (lua_State *L) { lua_pushnumber(L, m_balance); return 1; } 30 ~Account() { printf("deleted Account (%p)\n", this); } 31 }; 31 32 32 33 //const char Account::className[] = "Account"; 33 34 34 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 };35 Lunar<Account>::RegType Account::methods[] = { 36 {"deposit", new ExecutorLua1<Account, float>(&Account::deposit)}, 37 {"withdraw", new ExecutorLua1<Account, float>(&Account::withdraw)}, 38 {"balance", new ExecutorLua0ret<Account, float>(&Account::balance)}, 39 {0,NULL} 40 }; 40 41 41 42 tScriptClass<Account> global_ACCOUNT_ScriptableClass("Account", CL_ACCOUNT, (new ScriptMethod())->addMethod("deposit", ExecutorLua1<Account, float>(&Account::deposit))); 42 43 43 44 //CREATE_SCRIPTABLE_CLASS(Account, CL_ACCOUNT, NULL); 44 CREATE_SCRIPTABLE_CLASS(Account, CL_ACCOUNT, 45 addMethod("deposit", ExecutorLua1<Account, float>(&Account::deposit)) 46 ->addMethod("withdraw", ExecutorLua1<Account, float>(&Account::withdraw)) 47 ->addMethod("balance", ExecutorLua0ret<Account, float>(&Account::balance))); -
branches/script_engine/src/lib/script_engine/object.cc
r8401 r8404 43 43 }; 44 44 45 const char Object::className[] = "Object";46 47 Lunar<Object>::RegType Object::methods[] = {48 {"printName", new ExecutorLua0<Object>(&Object::printName)},49 {"getCallCount", new ExecutorLua0ret<Object, int>(&Object::getCallCount)},50 {"takeParam", new ExecutorLua1<Object, int>(&Object::takeParam)},51 {0,0}52 };53 45 54 46 CREATE_SCRIPTABLE_CLASS(Object, CL_TEST_OBJECT,
Note: See TracChangeset
for help on using the changeset viewer.