Changeset 7808 in orxonox.OLD for branches/script_engine/src/lib
- Timestamp:
- May 24, 2006, 3:25:09 PM (18 years ago)
- Location:
- branches/script_engine/src/lib/script_engine
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/script_engine/src/lib/script_engine/account.cc
r7702 r7808 37 37 return 1; 38 38 } 39 39 40 protected: 40 41 double m_balance; … … 93 94 lua_State* L = lua_open(); 94 95 lua_baselibopen(L); 95 96 96 Luna<Account>::Register(L); 97 Luna<Euclid>::Register(L);97 // Luna<Euclid>::Register(L); 98 98 99 99 lua_dofile(L, argv[1]); 100 100 101 101 102 lua_close(L); -
branches/script_engine/src/lib/script_engine/account.lua
r7702 r7808 2 2 -- Luna Account example 3 3 -- 4 5 print("testoutput from lua") 4 6 local a = Account{balance=100} 5 7 a:deposit(50.00) -
branches/script_engine/src/lib/script_engine/luna.h
r7703 r7808 28 28 lua_setglobal(L, T::className); 29 29 30 30 31 /* if (otag == 0) { 31 32 otag = lua_newtag(L); … … 41 42 static int thunk(lua_State* L) { 42 43 /* stack = closure(-1), [args...], 'self' table(1) */ 43 int i = static_cast<int>(lua_tonumber(L,-1)); 44 lua_pushnumber(L, 0); /* userdata object at index 0 */ 45 lua_gettable(L, 1); 46 T* obj = static_cast<T*>(lua_touserdata(L,-1)); 44 //int i = static_cast<int>(lua_tonumber(L,-1)); 45 int i = lua_upvalueindex (1); 46 //lua_pushnumber(L, 0); /* userdata object at index 0 */ 47 //lua_gettable(L, 1); 48 lua_rawgeti (L, 1, 0); 49 T* obj = (T*)(lua_touserdata(L,-1)); 47 50 lua_pop(L, 2); /* pop closure value and obj */ 51 52 printf("FUNCTION:: %d\n", i ); 53 printf("OBJECT %p\n", obj); 54 55 48 56 return (obj->*(T::Register[i].mfunc))(L); 49 57 } … … 64 72 static int constructor(lua_State* L) { 65 73 T* obj= new T(L); /* new T */ 74 printf("OBJECT CREATED %p\n", obj); 75 66 76 return registerObject(obj, L); 67 77 } … … 82 92 lua_newtable(L); /* new table object */ 83 93 int objRef = luaL_ref (L, LUA_REGISTRYINDEX); 84 std::cout<<"test"<<std::endl; 94 95 //lua_pushnumber(L, 0); /* userdata obj at index 0 */ 96 lua_rawgeti(L, LUA_REGISTRYINDEX, objRef); 97 lua_pushlightuserdata(L, obj); 98 lua_rawseti(L,-2,0); 99 //lua_pushusertag(L, obj, otag); /* have gc call tm */ 100 //lua_settable(L, -3); 101 //std::cout<<"test"<<std::endl; 102 103 /* Set up garbage collection */ 85 104 if(lua_getmetatable(L, objRef) != 0) 86 105 { 87 std::cout<<"test"<<std::endl;106 //std::cout<<"test"<<std::endl; 88 107 lua_pushstring (L, "__gc"); 89 108 lua_pushcfunction(L, &Luna<T>::gc_obj); 90 lua_rawset(L,-3); 91 // lua_setfield(L, objRef, "__gc"); 109 lua_settable(L,-3); 92 110 } 93 94 lua_pushnumber(L, 0); /* userdata obj at index 0 */ 95 96 // lua_pushusertag(L, obj, otag); /* have gc call tm */ 97 98 lua_settable(L, -3); 99 111 112 lua_rawgeti (L, LUA_REGISTRYINDEX, objRef); 100 113 /* register the member functions */ 101 114 for (int i=0; T::Register[i].name; i++) { 115 102 116 lua_pushstring(L, T::Register[i].name); 103 117 lua_pushnumber(L, i); 104 118 lua_pushcclosure(L, &Luna<T>::thunk, 1); 105 lua_settable(L, 119 lua_settable(L,-3); 106 120 } 107 121 return 1; /* return the table object */
Note: See TracChangeset
for help on using the changeset viewer.