Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8403 in orxonox.OLD for branches


Ignore:
Timestamp:
Jun 14, 2006, 5:22:13 PM (18 years ago)
Author:
bensch
Message:

methods should work

Location:
branches/script_engine/src/lib/script_engine
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/script_engine/src/lib/script_engine/lunar.h

    r8399 r8403  
    2121
    2222
    23   static void Register(Script* script, const std::string& className, const ScriptMethod* scriptMethod)
     23  static void Register(Script* script, const std::string& className, const ScriptMethod* scriptMethods)
    2424  {
    2525    if(script != NULL)
    26       Register(script->getLuaState(), className, scriptMethod);
    27   }
    28 
    29   static void Register(lua_State *L, const std::string& className, const ScriptMethod* scriptMethod)
     26      Register(script->getLuaState(), className, scriptMethods);
     27  }
     28
     29  static void Register(lua_State *L, const std::string& className, const ScriptMethod* scriptMethods)
    3030  {
    3131    Lunar<T>::className = className;
     32    Lunar<T>::scriptMethods = scriptMethods;
    3233    lua_newtable(L);
    3334    int methods = lua_gettop(L);
     
    6263
    6364    // fill method table with methods from class T
     65    /* as it was originally
    6466    for (RegType *l = T::methods; l->name; l++)
    6567    {
     
    6870      lua_pushcclosure(L, thunk, 1);
    6971      lua_settable(L, methods);
    70     }
    71 
     72  }*/
     73    for (unsigned int i = 0; i < Lunar<T>::scriptMethods->size(); i++)
     74    {
     75      lua_pushstring(L, Lunar<T>::scriptMethods->name(i).c_str());
     76      lua_pushlightuserdata(L, (void*)Lunar<T>::scriptMethods->executor(i));
     77      lua_pushcclosure(L, thunk, 1);
     78      lua_settable(L, methods);
     79    }
    7280    lua_pop(L, 2);  // drop metatable and method table
    7381  }
     
    176184    lua_remove(L, 1);  // remove self so member function args start at index 1
    177185    // get member function from upvalue
    178     RegType *l = static_cast<RegType*>(lua_touserdata(L, lua_upvalueindex(1)));
     186    Executor *l = static_cast<Executor*>(lua_touserdata(L, lua_upvalueindex(1)));
    179187    int value;
    180     (*l->mfunc)(obj, value, L);  // call member function
     188    (*l)(obj, value, L);  // call member function
    181189    return value;
    182190  }
     
    268276  private:
    269277    static std::string className;
     278    static const ScriptMethod* scriptMethods;
    270279};
    271280
    272281template <typename T>
    273282    std::string Lunar<T>::className = "";
     283template <typename T>
     284    const ScriptMethod* Lunar<T>::scriptMethods = NULL;
    274285
    275286#endif /* _LUNAR_H */
  • branches/script_engine/src/lib/script_engine/script_method.h

    r8401 r8403  
    2020  ScriptMethod* addMethod(const std::string& methodName, const Executor& executor);
    2121
     22  unsigned int size() const { return methods.size(); };
     23
    2224  const std::string& name(unsigned int methodNumber) const { return methods[methodNumber].name; };
    2325  const Executor* executor(unsigned int methodNumber) const { return methods[methodNumber].executor; };
Note: See TracChangeset for help on using the changeset viewer.