Changeset 8044 in orxonox.OLD for branches/script_engine/src/lib/script_engine/account.cc
- Timestamp:
- May 31, 2006, 9:24:11 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/script_engine/src/lib/script_engine/account.cc
r7975 r8044 1 #include "luaincl.h"2 #include <iostream>3 1 4 #include "lunar.h" 2 #include <iostream> 3 4 #include "luaincl.h" 5 #include "lunar.h" 6 #include "Script.h" 5 7 6 8 class Account { … … 11 13 12 14 Account(lua_State *L) { m_balance = luaL_checknumber(L, 1); } 15 Account(double balance=0) : m_balance(balance) { } 13 16 int deposit (lua_State *L) { m_balance += luaL_checknumber(L, 1); return 0; } 14 17 int withdraw(lua_State *L) { m_balance -= luaL_checknumber(L, 1); return 0; } … … 36 39 37 40 Object(lua_State* L) {callCount = 0; } 41 Object(){callCount = 0;}; 38 42 ~Object() { printf("deleted Object (%p)\n", this); } 43 39 44 40 45 int printName(lua_State* L) 41 46 { 47 callCount ++; 42 48 printf("Hi i'm object %p ! This is the %i. call.\n",this,callCount); 43 callCount ++;44 49 return 0; 45 50 } … … 60 65 int main(int argc, char *argv[]) 61 66 { 62 lua_State *L = lua_open(); 67 Script script; 68 Lunar<Account>::Register(&script); 69 Lunar<Object>::Register(&script); 63 70 64 luaopen_base(L); 65 luaopen_table(L); 66 luaopen_io(L); 67 luaopen_string(L); 68 luaopen_math(L); 69 luaopen_debug(L); 71 Object* obj= new Object(); 72 Account a; 73 Account *b = new Account(30); 70 74 71 Lunar<Account>::Register(L); 72 Lunar<Object>::Register(L); 75 Lunar<Object>::insertObject(&script,obj,"Obj",true); 76 Lunar<Account>::insertObject(&script,&a,"a",false); 77 Lunar<Account>::insertObject(&script,b,"b",true); 73 78 74 Object* obj= new Object(L);75 Lunar<Object>::insertObject(L,obj,"Obj",false);76 //delete obj;77 79 78 if(argc>1) lua_dofile(L,argv[1]);80 std::string file(argv[1]); 79 81 80 lua_setgcthreshold(L, 0); // collected garbage 81 lua_close(L); 82 if(script.loadFile(file)) 83 printf("file %s succefully loaded\n", file.c_str()); 84 85 //script.executeFile(); 86 87 std::string main("main"); 88 script.selectFunction(main,1); 89 script.pushParam(3,main); 90 script.executeFunction(); 91 92 //if(argc>1) lua_dofile(script.getLuaState(), argv[1]); 93 82 94 return 0; 83 95 }
Note: See TracChangeset
for help on using the changeset viewer.