Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7808 in orxonox.OLD for branches


Ignore:
Timestamp:
May 24, 2006, 3:25:09 PM (18 years ago)
Author:
snellen
Message:

object pointer is now found

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  
    3737    return 1;
    3838  }
     39
    3940protected:
    4041  double m_balance;
     
    9394  lua_State* L = lua_open();
    9495  lua_baselibopen(L);
    95 
    9696  Luna<Account>::Register(L);
    97   Luna<Euclid>::Register(L);
     97 // Luna<Euclid>::Register(L);
    9898
    9999  lua_dofile(L, argv[1]);
     100
    100101
    101102  lua_close(L);
  • branches/script_engine/src/lib/script_engine/account.lua

    r7702 r7808  
    22-- Luna Account example
    33--
     4
     5print("testoutput from lua")
    46local a = Account{balance=100}
    57a:deposit(50.00)
  • branches/script_engine/src/lib/script_engine/luna.h

    r7703 r7808  
    2828      lua_setglobal(L, T::className);
    2929
     30
    3031     /* if (otag == 0) {
    3132        otag = lua_newtag(L);
     
    4142   static int thunk(lua_State* L) {
    4243      /* 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));
    4750      lua_pop(L, 2); /* pop closure value and obj */
     51
     52        printf("FUNCTION:: %d\n", i );
     53        printf("OBJECT %p\n", obj);
     54
     55
    4856      return (obj->*(T::Register[i].mfunc))(L);
    4957   }
     
    6472   static int constructor(lua_State* L) {
    6573      T* obj= new T(L); /* new T */
     74       printf("OBJECT CREATED %p\n", obj);
     75
    6676      return registerObject(obj, L);
    6777   }
     
    8292      lua_newtable(L); /* new table object */
    8393      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 */
    85104      if(lua_getmetatable(L, objRef) != 0)
    86105       {
    87         std::cout<<"test"<<std::endl;
     106        //std::cout<<"test"<<std::endl;
    88107        lua_pushstring (L, "__gc");
    89108        lua_pushcfunction(L, &Luna<T>::gc_obj);
    90         lua_rawset(L,-3);
    91 //        lua_setfield(L, objRef, "__gc");
     109        lua_settable(L,-3);
    92110       }
    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);
    100113      /* register the member functions */
    101114      for (int i=0; T::Register[i].name; i++) {
     115         
    102116         lua_pushstring(L, T::Register[i].name);
    103117         lua_pushnumber(L, i);
    104118         lua_pushcclosure(L, &Luna<T>::thunk, 1);
    105          lua_settable(L, -3);
     119         lua_settable(L,-3);
    106120      }
    107121      return 1; /* return the table object */
Note: See TracChangeset for help on using the changeset viewer.