Index: trunk/src/lib/script_engine/Makefile.am
===================================================================
--- trunk/src/lib/script_engine/Makefile.am	(revision 8376)
+++ trunk/src/lib/script_engine/Makefile.am	(revision 8408)
@@ -13,7 +13,9 @@
 
 libORXscript_a_SOURCES = \
-                script.cc\
-                script_manager.cc\
-		script_class.cc\
+                script.cc \
+                script_manager.cc \
+		script_class.cc \
+		script_method.cc \
+		\
 		account.cc \
 		object.cc
@@ -25,6 +27,7 @@
                 lunar.h\
                 script.h\
-                script_manager.h\
-		script_class.h
+                script_manager.h \
+		script_class.h \
+		script_method.h
 
 
@@ -32,16 +35,8 @@
 
 check_PROGRAMS = example
-
-
-
-
-
-
-
 example_DEPENDENCIES = \
                 $(MAINSRCDIR)/world_entities/libORXwe.a \
                 $(libORXlibs_a_LIBRARIES_) \
                 $(MAINSRCDIR)/util/libORXutils.a
-
 example_LDADD = \
                 $(MAINSRCDIR)/util/libORXutils.a \
Index: trunk/src/lib/script_engine/account.cc
===================================================================
--- trunk/src/lib/script_engine/account.cc	(revision 8376)
+++ trunk/src/lib/script_engine/account.cc	(revision 8408)
@@ -11,32 +11,25 @@
 
 
- class Account : public BaseObject {
-      lua_Number m_balance;
-   public:
-     static const char className[];
-     static Lunar<Account>::RegType methods[];
+class Account : public BaseObject
+{
+  lua_Number m_balance;
+public:
+  Account(lua_State *L)      { m_balance = luaL_checknumber(L, 1); }
+  Account(double balance=0)    : m_balance(balance) { this->setClassID(CL_ACCOUNT, "Account"); }
 
-     Account(lua_State *L)      { m_balance = luaL_checknumber(L, 1); }
-     Account(double balance=0)    : m_balance(balance) { this->setClassID(CL_ACCOUNT, "Account"); }
+  void deposit (float value) { m_balance += value; };
+  void withdraw(float value) { m_balance -= value; };
+  float balance() { return m_balance; };
 
-     void deposit (float value) { m_balance += value; };
-     void withdraw(float value) { m_balance -= value; };
-     float balance() { return m_balance; };
+  int deposit (lua_State *L) { m_balance += luaL_checknumber(L, 1); return 0; }
+  int withdraw(lua_State *L) { m_balance -= luaL_checknumber(L, 1); return 0; }
+  int balance (lua_State *L) { lua_pushnumber(L, m_balance); return 1; }
+  ~Account() { printf("deleted Account (%p)\n", this); }
+};
 
-     int deposit (lua_State *L) { m_balance += luaL_checknumber(L, 1); return 0; }
-     int withdraw(lua_State *L) { m_balance -= luaL_checknumber(L, 1); return 0; }
-     int balance (lua_State *L) { lua_pushnumber(L, m_balance); return 1; }
-     ~Account() { printf("deleted Account (%p)\n", this); }
- };
 
- const char Account::className[] = "Account";
 
- Lunar<Account>::RegType Account::methods[] = {
-   {"deposit", new ExecutorLua1<Account, float>(&Account::deposit)},
-   {"withdraw", new ExecutorLua1<Account, float>(&Account::withdraw)},
-   {"balance", new ExecutorLua0ret<Account, float>(&Account::balance)},
-   {0,NULL}
- };
-
- CREATE_SCRIPTABLE_CLASS(Account, CL_ACCOUNT);
-
+CREATE_SCRIPTABLE_CLASS(Account, CL_ACCOUNT,
+                        addMethod("deposit", ExecutorLua1<Account, float>(&Account::deposit))
+                        ->addMethod("withdraw", ExecutorLua1<Account, float>(&Account::withdraw))
+                        ->addMethod("balance", ExecutorLua0ret<Account, float>(&Account::balance)));
Index: trunk/src/lib/script_engine/lunar.h
===================================================================
--- trunk/src/lib/script_engine/lunar.h	(revision 8376)
+++ trunk/src/lib/script_engine/lunar.h	(revision 8408)
@@ -7,239 +7,280 @@
 
 #include "luaincl.h"
-#include "executor/executor_lua.h"
-
-
-
-    template <typename T> class Lunar {
-      typedef struct { T *pT; } userdataType;
-    public:
-      typedef Executor* mfp;
-      typedef struct { const char *name; mfp mfunc; } RegType;
-
-
-      static void Register(Script* script)
+#include "script_method.h"
+
+
+
+template <typename T> class Lunar
+{
+  typedef struct { T *pT; }
+  userdataType;
+public:
+  typedef Executor* mfp;
+  typedef struct { const char *name; mfp mfunc; }
+  RegType;
+
+
+  static void Register(Script* script, const std::string& className, const ScriptMethod* scriptMethods)
+  {
+    if(script != NULL)
+      Register(script->getLuaState(), className, scriptMethods);
+  }
+
+  static void Register(lua_State *L, const std::string& className, const ScriptMethod* scriptMethods)
+  {
+    Lunar<T>::className = className;
+    Lunar<T>::scriptMethods = scriptMethods;
+    lua_newtable(L);
+    int methods = lua_gettop(L);
+
+    luaL_newmetatable(L, Lunar<T>::className.c_str());
+    int metatable = lua_gettop(L);
+
+    // store method table in globals so that
+    // scripts can add functions written in Lua.
+    lua_pushvalue(L, methods);
+    set(L, LUA_GLOBALSINDEX, Lunar<T>::className.c_str());
+
+    // hide metatable from Lua getmetatable()
+    lua_pushvalue(L, methods);
+    set(L, metatable, "__metatable");
+
+    lua_pushvalue(L, methods);
+    set(L, metatable, "__index");
+
+    lua_pushcfunction(L, tostring_T);
+    set(L, metatable, "__tostring");
+
+    lua_pushcfunction(L, gc_T);
+    set(L, metatable, "__gc");
+
+    lua_newtable(L);                // mt for method table
+    lua_pushcfunction(L, new_T);
+    lua_pushvalue(L, -1);           // dup new_T function
+    set(L, methods, "new");         // add new_T to method table
+    set(L, -3, "__call");           // mt.__call = new_T
+    lua_setmetatable(L, methods);
+
+    // fill method table with methods from class T
+    /* as it was originally
+    for (RegType *l = T::methods; l->name; l++)
+    {
+      lua_pushstring(L, l->name);
+      lua_pushlightuserdata(L, (void*)l);
+      lua_pushcclosure(L, thunk, 1);
+      lua_settable(L, methods);
+  }*/
+    for (unsigned int i = 0; i < Lunar<T>::scriptMethods->size(); i++)
+    {
+      lua_pushstring(L, Lunar<T>::scriptMethods->name(i).c_str());
+      lua_pushlightuserdata(L, (void*)Lunar<T>::scriptMethods->executor(i));
+      lua_pushcclosure(L, thunk, 1);
+      lua_settable(L, methods);
+    }
+    lua_pop(L, 2);  // drop metatable and method table
+  }
+
+  // call named lua method from userdata method table
+  static int call(lua_State *L, const char *method,
+                  int nargs=0, int nresults=LUA_MULTRET, int errfunc=0)
+  {
+    int base = lua_gettop(L) - nargs;  // userdata index
+    if (!luaL_checkudata(L, base, Lunar<T>::className.c_str()))
+    {
+      lua_settop(L, base-1);           // drop userdata and args
+      lua_pushfstring(L, "not a valid %s userdata", Lunar<T>::className.c_str());
+      return -1;
+    }
+
+    lua_pushstring(L, method);         // method name
+    lua_gettable(L, base);             // get method from userdata
+    if (lua_isnil(L, -1))
+    {            // no method?
+      lua_settop(L, base-1);           // drop userdata and args
+      lua_pushfstring(L, "%s missing method '%s'", Lunar<T>::className.c_str(), method);
+      return -1;
+    }
+    lua_insert(L, base);               // put method under userdata, args
+
+    int status = lua_pcall(L, 1+nargs, nresults, errfunc);  // call method
+    if (status)
+    {
+      const char *msg = lua_tostring(L, -1);
+      if (msg == NULL) msg = "(error with no message)";
+      lua_pushfstring(L, "%s:%s status = %d\n%s",
+                      Lunar<T>::className.c_str(), method, status, msg);
+      lua_remove(L, base);             // remove old message
+      return -1;
+    }
+    return lua_gettop(L) - base + 1;   // number of results
+  }
+
+  // push onto the Lua stack a userdata containing a pointer to T object
+  static int push(lua_State *L, T *obj, bool gc=false)
+  {
+    if (!obj) { lua_pushnil(L); return 0; }
+    luaL_getmetatable(L, Lunar<T>::className.c_str());  // lookup metatable in Lua registry
+    if (lua_isnil(L, -1)) luaL_error(L, "%s missing metatable", Lunar<T>::className.c_str());
+    int mt = lua_gettop(L);
+    subtable(L, mt, "userdata", "v");
+    userdataType *ud =
+      static_cast<userdataType*>(pushuserdata(L, obj, sizeof(userdataType)));
+    if (ud)
+    {
+      ud->pT = obj;  // store pointer to object in userdata
+      lua_pushvalue(L, mt);
+      lua_setmetatable(L, -2);
+      if (gc == false)
       {
-        if(script != NULL)
-          Register(script->getLuaState());
+        lua_checkstack(L, 3);
+        subtable(L, mt, "do not trash", "k");
+        lua_pushvalue(L, -2);
+        lua_pushboolean(L, 1);
+        lua_settable(L, -3);
+        lua_pop(L, 1);
       }
-
-      static void Register(lua_State *L) {
-        lua_newtable(L);
-        int methods = lua_gettop(L);
-
-        luaL_newmetatable(L, T::className);
-        int metatable = lua_gettop(L);
-
-        // store method table in globals so that
-        // scripts can add functions written in Lua.
-        lua_pushvalue(L, methods);
-        set(L, LUA_GLOBALSINDEX, T::className);
-
-        // hide metatable from Lua getmetatable()
-        lua_pushvalue(L, methods);
-        set(L, metatable, "__metatable");
-
-        lua_pushvalue(L, methods);
-        set(L, metatable, "__index");
-
-        lua_pushcfunction(L, tostring_T);
-        set(L, metatable, "__tostring");
-
-        lua_pushcfunction(L, gc_T);
-        set(L, metatable, "__gc");
-
-        lua_newtable(L);                // mt for method table
-        lua_pushcfunction(L, new_T);
-        lua_pushvalue(L, -1);           // dup new_T function
-        set(L, methods, "new");         // add new_T to method table
-        set(L, -3, "__call");           // mt.__call = new_T
-        lua_setmetatable(L, methods);
-
-        // fill method table with methods from class T
-        for (RegType *l = T::methods; l->name; l++) {
-          lua_pushstring(L, l->name);
-          lua_pushlightuserdata(L, (void*)l);
-          lua_pushcclosure(L, thunk, 1);
-          lua_settable(L, methods);
-        }
-
-        lua_pop(L, 2);  // drop metatable and method table
-      }
-
-      // call named lua method from userdata method table
-      static int call(lua_State *L, const char *method,
-                      int nargs=0, int nresults=LUA_MULTRET, int errfunc=0)
-      {
-        int base = lua_gettop(L) - nargs;  // userdata index
-        if (!luaL_checkudata(L, base, T::className)) {
-          lua_settop(L, base-1);           // drop userdata and args
-          lua_pushfstring(L, "not a valid %s userdata", T::className);
-          return -1;
-        }
-
-        lua_pushstring(L, method);         // method name
-        lua_gettable(L, base);             // get method from userdata
-        if (lua_isnil(L, -1)) {            // no method?
-          lua_settop(L, base-1);           // drop userdata and args
-          lua_pushfstring(L, "%s missing method '%s'", T::className, method);
-          return -1;
-        }
-        lua_insert(L, base);               // put method under userdata, args
-
-        int status = lua_pcall(L, 1+nargs, nresults, errfunc);  // call method
-        if (status) {
-          const char *msg = lua_tostring(L, -1);
-          if (msg == NULL) msg = "(error with no message)";
-          lua_pushfstring(L, "%s:%s status = %d\n%s",
-                          T::className, method, status, msg);
-          lua_remove(L, base);             // remove old message
-          return -1;
-        }
-        return lua_gettop(L) - base + 1;   // number of results
-      }
-
-      // push onto the Lua stack a userdata containing a pointer to T object
-      static int push(lua_State *L, T *obj, bool gc=false) {
-        if (!obj) { lua_pushnil(L); return 0; }
-        luaL_getmetatable(L, T::className);  // lookup metatable in Lua registry
-        if (lua_isnil(L, -1)) luaL_error(L, "%s missing metatable", T::className);
-        int mt = lua_gettop(L);
-        subtable(L, mt, "userdata", "v");
-        userdataType *ud =
-          static_cast<userdataType*>(pushuserdata(L, obj, sizeof(userdataType)));
-        if (ud) {
-          ud->pT = obj;  // store pointer to object in userdata
-          lua_pushvalue(L, mt);
-          lua_setmetatable(L, -2);
-          if (gc == false) {
-            lua_checkstack(L, 3);
-            subtable(L, mt, "do not trash", "k");
-            lua_pushvalue(L, -2);
-            lua_pushboolean(L, 1);
-            lua_settable(L, -3);
-            lua_pop(L, 1);
-          }
-        }
-        lua_replace(L, mt);
-        lua_settop(L, mt);
-        return mt;  // index of userdata containing pointer to T object
-      }
-
-
-      static int insertObject(lua_State* L, T* obj, const std::string& name, bool gc=false)
-      {
-        int objectRef = push(L, obj, gc);
-
-        lua_pushlstring(L, name.c_str(), name.size());
-        lua_pushvalue(L, objectRef );
-        lua_settable(L, LUA_GLOBALSINDEX );
-
-        return objectRef;
-      }
-
-
-      static int insertObject(Script* script, T* obj, const std::string& name, bool gc=false)
-      {
-        assert (script != NULL);
-        return insertObject(script->getLuaState(), obj, name, gc);
-      }
-
-      // get userdata from Lua stack and return pointer to T object
-      static T *check(lua_State *L, int narg) {
-        userdataType *ud =
-          static_cast<userdataType*>(luaL_checkudata(L, narg, T::className));
-        if(!ud) luaL_typerror(L, narg, T::className);
-        return ud->pT;  // pointer to T object
-      }
-
-    private:
-      Lunar();  // hide default constructor
-
-      // member function dispatcher
-      static int thunk(lua_State *L) {
-        // stack has userdata, followed by method args
-        T *obj = check(L, 1);  // get 'self', or if you prefer, 'this'
-        lua_remove(L, 1);  // remove self so member function args start at index 1
-        // get member function from upvalue
-        RegType *l = static_cast<RegType*>(lua_touserdata(L, lua_upvalueindex(1)));
-        int value;
-        (*l->mfunc)(obj, value, L);  // call member function
-        return value;
-      }
-
-      // create a new T object and
-      // push onto the Lua stack a userdata containing a pointer to T object
-      static int new_T(lua_State *L) {
-        lua_remove(L, 1);   // use classname:new(), instead of classname.new()
-        T *obj = new T(L);  // call constructor for T objects
-        push(L, obj, true); // gc_T will delete this object
-        return 1;           // userdata containing pointer to T object
-      }
-
-      // garbage collection metamethod
-      static int gc_T(lua_State *L) {
-        if (luaL_getmetafield(L, 1, "do not trash")) {
-          lua_pushvalue(L, 1);  // dup userdata
-          lua_gettable(L, -2);
-          if (!lua_isnil(L, -1)) return 0;  // do not delete object
-        }
-        userdataType *ud = static_cast<userdataType*>(lua_touserdata(L, 1));
-        T *obj = ud->pT;
-        if (obj) delete obj;  // call destructor for T objects
-        return 0;
-      }
-
-      static int tostring_T (lua_State *L) {
-        char buff[32];
-        userdataType *ud = static_cast<userdataType*>(lua_touserdata(L, 1));
-        T *obj = ud->pT;
-        sprintf(buff, "%p", obj);
-        lua_pushfstring(L, "%s (%s)", T::className, buff);
-        return 1;
-      }
-
-      static void set(lua_State *L, int table_index, const char *key) {
-        lua_pushstring(L, key);
-        lua_insert(L, -2);  // swap value and key
-        lua_settable(L, table_index);
-      }
-
-      static void weaktable(lua_State *L, const char *mode) {
-        lua_newtable(L);
-        lua_pushvalue(L, -1);  // table is its own metatable
-        lua_setmetatable(L, -2);
-        lua_pushliteral(L, "__mode");
-        lua_pushstring(L, mode);
-        lua_settable(L, -3);   // metatable.__mode = mode
-      }
-
-      static void subtable(lua_State *L, int tindex, const char *name, const char *mode) {
-        lua_pushstring(L, name);
-        lua_gettable(L, tindex);
-        if (lua_isnil(L, -1)) {
-          lua_pop(L, 1);
-          lua_checkstack(L, 3);
-          weaktable(L, mode);
-          lua_pushstring(L, name);
-          lua_pushvalue(L, -2);
-          lua_settable(L, tindex);
-        }
-      }
-
-      static void *pushuserdata(lua_State *L, void *key, size_t sz) {
-        void *ud = 0;
-        lua_pushlightuserdata(L, key);
-        lua_gettable(L, -2);     // lookup[key]
-        if (lua_isnil(L, -1)) {
-          lua_pop(L, 1);         // drop nil
-          lua_checkstack(L, 3);
-          ud = lua_newuserdata(L, sz);  // create new userdata
-          lua_pushlightuserdata(L, key);
-          lua_pushvalue(L, -2);  // dup userdata
-          lua_settable(L, -4);   // lookup[key] = userdata
-        }
-        return ud;
-      }
-    };
+    }
+    lua_replace(L, mt);
+    lua_settop(L, mt);
+    return mt;  // index of userdata containing pointer to T object
+  }
+
+
+  static int insertObject(lua_State* L, T* obj, const std::string& name, bool gc=false)
+  {
+    int objectRef = push(L, obj, gc);
+
+    lua_pushlstring(L, name.c_str(), name.size());
+    lua_pushvalue(L, objectRef );
+    lua_settable(L, LUA_GLOBALSINDEX );
+
+    return objectRef;
+  }
+
+
+  static int insertObject(Script* script, T* obj, const std::string& name, bool gc=false)
+  {
+    assert (script != NULL);
+    return insertObject(script->getLuaState(), obj, name, gc);
+  }
+
+  // get userdata from Lua stack and return pointer to T object
+  static T *check(lua_State *L, int narg)
+  {
+    userdataType *ud =
+      static_cast<userdataType*>(luaL_checkudata(L, narg, Lunar<T>::className.c_str()));
+    if(!ud) luaL_typerror(L, narg, Lunar<T>::className.c_str());
+    return ud->pT;  // pointer to T object
+  }
+
+private:
+  Lunar();  // hide default constructor
+
+  // member function dispatcher
+  static int thunk(lua_State *L)
+  {
+    // stack has userdata, followed by method args
+    T *obj = check(L, 1);  // get 'self', or if you prefer, 'this'
+    lua_remove(L, 1);  // remove self so member function args start at index 1
+    // get member function from upvalue
+    Executor *l = static_cast<Executor*>(lua_touserdata(L, lua_upvalueindex(1)));
+    int value;
+    (*l)(obj, value, L);  // call member function
+    return value;
+  }
+
+  // create a new T object and
+  // push onto the Lua stack a userdata containing a pointer to T object
+  static int new_T(lua_State *L)
+  {
+    lua_remove(L, 1);   // use classname:new(), instead of classname.new()
+    T *obj = new T();  // call constructor for T objects
+    push(L, obj, true); // gc_T will delete this object
+    return 1;           // userdata containing pointer to T object
+  }
+
+  // garbage collection metamethod
+  static int gc_T(lua_State *L)
+  {
+    if (luaL_getmetafield(L, 1, "do not trash"))
+    {
+      lua_pushvalue(L, 1);  // dup userdata
+      lua_gettable(L, -2);
+      if (!lua_isnil(L, -1)) return 0;  // do not delete object
+    }
+    userdataType *ud = static_cast<userdataType*>(lua_touserdata(L, 1));
+    T *obj = ud->pT;
+    if (obj) delete obj;  // call destructor for T objects
+    return 0;
+  }
+
+  static int tostring_T (lua_State *L)
+  {
+    char buff[32];
+    userdataType *ud = static_cast<userdataType*>(lua_touserdata(L, 1));
+    T *obj = ud->pT;
+    sprintf(buff, "%p", obj);
+    lua_pushfstring(L, "%s (%s)", Lunar<T>::className.c_str(), buff);
+    return 1;
+  }
+
+  static void set(lua_State *L, int table_index, const char *key)
+  {
+    lua_pushstring(L, key);
+    lua_insert(L, -2);  // swap value and key
+    lua_settable(L, table_index);
+  }
+
+  static void weaktable(lua_State *L, const char *mode)
+  {
+    lua_newtable(L);
+    lua_pushvalue(L, -1);  // table is its own metatable
+    lua_setmetatable(L, -2);
+    lua_pushliteral(L, "__mode");
+    lua_pushstring(L, mode);
+    lua_settable(L, -3);   // metatable.__mode = mode
+  }
+
+  static void subtable(lua_State *L, int tindex, const char *name, const char *mode)
+  {
+    lua_pushstring(L, name);
+    lua_gettable(L, tindex);
+    if (lua_isnil(L, -1))
+    {
+      lua_pop(L, 1);
+      lua_checkstack(L, 3);
+      weaktable(L, mode);
+      lua_pushstring(L, name);
+      lua_pushvalue(L, -2);
+      lua_settable(L, tindex);
+    }
+  }
+
+  static void *pushuserdata(lua_State *L, void *key, size_t sz)
+  {
+    void *ud = 0;
+    lua_pushlightuserdata(L, key);
+    lua_gettable(L, -2);     // lookup[key]
+    if (lua_isnil(L, -1))
+    {
+      lua_pop(L, 1);         // drop nil
+      lua_checkstack(L, 3);
+      ud = lua_newuserdata(L, sz);  // create new userdata
+      lua_pushlightuserdata(L, key);
+      lua_pushvalue(L, -2);  // dup userdata
+      lua_settable(L, -4);   // lookup[key] = userdata
+    }
+    return ud;
+  }
+
+  private:
+    static std::string className;
+    static const ScriptMethod* scriptMethods;
+};
+
+template <typename T>
+    std::string Lunar<T>::className = "";
+template <typename T>
+    const ScriptMethod* Lunar<T>::scriptMethods = NULL;
 
 #endif /* _LUNAR_H */
Index: trunk/src/lib/script_engine/lunartest2.lua
===================================================================
--- trunk/src/lib/script_engine/lunartest2.lua	(revision 8376)
+++ trunk/src/lib/script_engine/lunartest2.lua	(revision 8408)
@@ -22,14 +22,17 @@
 
 function main(arg)
+  io.write("hello i am main!")
   -- use parameter
   io.write("main received ", arg)
   io.write(" as parameter\n")
 
+ o = Object()
+  o:printName()
   --call member of an inserted object
   Obj:printName()
 
   --create object of a registered type
-  o = Object()
-  o:printName()
+  --o = Object()
+  --o:printName()
 
   --take returnvalue from c
Index: trunk/src/lib/script_engine/object.cc
===================================================================
--- trunk/src/lib/script_engine/object.cc	(revision 8376)
+++ trunk/src/lib/script_engine/object.cc	(revision 8408)
@@ -8,46 +8,39 @@
 
 
-class Object : public BaseObject {
-   public:
-     static const char className[];
-     static Lunar<Object>::RegType methods[];
+class Object : public BaseObject
+{
+public:
+  Object(lua_State* L) {callCount = 0; }
+  Object(){callCount = 0;this->setClassID(CL_TEST_OBJECT, "Object");};
+  ~Object() { printf("deleted Object (%p)\n", this); }
 
-     Object(lua_State* L) {callCount = 0; }
-     Object(){callCount = 0;};
-     ~Object() { printf("deleted Object (%p)\n", this); }
+  //meber functions
+  void takeParam(int i)
+  {
+    printf("Lua passed %i to c++\n",i);
+  }
 
-        //meber functions
-     void takeParam(int i)
-     {
-       printf("Lua passed %i to c++\n",i);
-     }
+  int printName(lua_State* L)
+  {
+    this->printName();
+    return 0;
+  }
 
-     int printName(lua_State* L)
-     {
-       this->printName();
-       return 0;
-     }
+  void printName()
+  {
+    callCount ++;
+    printf("Hi i'm object %p ! This is the %i. call.\n",this,callCount);
+  }
 
-     void printName()
-     {
-       callCount ++;
-       printf("Hi i'm object %p ! This is the %i. call.\n",this,callCount);
-     }
+  int getCallCount(){ return callCount; }
 
-     int getCallCount(){ return callCount; }
+private:
+  int callCount;
 
-   private:
-     int callCount;
+};
 
- };
 
- const char Object::className[] = "Object";
-
- Lunar<Object>::RegType Object::methods[] = {
-   {"printName", new ExecutorLua0<Object>(&Object::printName)},
-   {"getCallCount", new ExecutorLua0ret<Object, int>(&Object::getCallCount)},
-   {"takeParam", new ExecutorLua1<Object, int>(&Object::takeParam)},
-   {0,0}
- };
-
- CREATE_SCRIPTABLE_CLASS(Object, CL_TEST_OBJECT);
+CREATE_SCRIPTABLE_CLASS(Object, CL_TEST_OBJECT,
+                        addMethod("printName", ExecutorLua0<Object>(&Object::printName))
+                        ->addMethod("getCallCount", ExecutorLua0ret<Object, int>(&Object::getCallCount))
+                        ->addMethod("takeParam", ExecutorLua1<Object, int>(&Object::takeParam)));
Index: trunk/src/lib/script_engine/script.cc
===================================================================
--- trunk/src/lib/script_engine/script.cc	(revision 8376)
+++ trunk/src/lib/script_engine/script.cc	(revision 8408)
@@ -23,5 +23,4 @@
   luaopen_math(luaState);
   luaopen_debug(luaState);
-
   if (root != NULL)
     this->loadParams(root);
@@ -38,4 +37,5 @@
 void Script::loadParams(const TiXmlElement* root)
 {
+  //printf("Loading params for %p \n",this);
   BaseObject::loadParams(root);
 
@@ -77,10 +77,12 @@
      else
      {
-      reportError(error);
-     }
-
-   }
-   else
-   {
+       printf("ERROR while loading file %s: \n",filename.c_str());
+       reportError(error);
+     }
+
+   }
+   else
+   {
+     printf("ERROR while loading file %s: \n",filename.c_str());
      reportError(error);
    }
@@ -92,5 +94,8 @@
  void Script::addObject(const std::string& className, const std::string& objectName)
  {
+   //printf("Script %p: I am about to add %s of class %s\n",this,objectName.c_str(),className.c_str());
+
    BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
+   //printf("The script class for %s is at %p \n",className.c_str(),scriptClass);
    WorldObject tmpObj;
    if (scriptClass != NULL)
@@ -103,4 +108,5 @@
 
      BaseObject* object = ClassList::getObject(objectName, className);
+     //printf("%s is at %p \n",objectName.c_str(),object);
      if (object != NULL && !objectIsAdded(objectName))
      {
@@ -162,5 +168,9 @@
     if(error != 0)
     {
+     printf("ERROR while executing function %s: \n",currentFunction.c_str());
      reportError(error);
+     //clean up
+     currentFunction.assign("");
+     argumentCount = returnCount = 0;
      return false;
     }
@@ -174,4 +184,6 @@
    else
      printf("Error: no function selected.\n");
+
+   return false;
  }
 
@@ -229,12 +241,13 @@
  int Script::getReturnedInt()
  {
-   int returnValue;
+   int returnValue = 0;
    if(returnCount > 0)
    {
-     if(lua_isnumber(luaState, -1))
-     {
-       returnValue = (int)lua_tonumber(luaState, -1);
+     if(lua_isnumber(luaState, -1*returnCount))
+     {
+       returnValue = (int)lua_tonumber(luaState, -1*returnCount);
+       lua_remove(luaState,-1*returnCount);
        returnCount--;
-       lua_pop(luaState,1);
+       
      }
    }
@@ -245,12 +258,12 @@
  bool Script::getReturnedBool()
  {
-   bool returnValue;
+   bool returnValue = false;
    if(returnCount > 0)
    {
-     if(lua_isboolean(luaState, -1))
-     {
-       returnValue = (bool)lua_toboolean(luaState, -1);
+     if(lua_isboolean(luaState, -1*returnCount))
+     {
+       returnValue = (bool)lua_toboolean(luaState, -1*returnCount);
+       lua_remove(luaState,-1*returnCount);
        returnCount--;
-       lua_pop(luaState,1);
      }
    }
@@ -260,12 +273,12 @@
 float Script::getReturnedFloat()
  {
-   float returnValue;
+   float returnValue = 0.0f;
    if(returnCount > 0)
    {
-     if(lua_isnumber(luaState, -1))
-     {
-       returnValue = (float)lua_tonumber(luaState, -1);
+     if(lua_isnumber(luaState, -1*returnCount))
+     {
+       returnValue = (float)lua_tonumber(luaState, -1*returnCount);
+       lua_remove(luaState,-1*returnCount);
        returnCount--;
-       lua_pop(luaState,1);
      }
    }
@@ -275,12 +288,12 @@
  void Script::getReturnedString(std::string& string)
  {
-   const char* returnValue;
+   const char* returnValue = "";
    if(returnCount > 0)
    {
-     if(lua_isstring(luaState, -1))
-     {
-       returnValue = lua_tostring(luaState, -1);
+     if(lua_isstring(luaState, -1*returnCount))
+     {
+       returnValue = lua_tostring(luaState, -1*returnCount);
+       lua_remove(luaState,-1*returnCount);
        returnCount--;
-       lua_pop(luaState,1);
      }
    }
@@ -296,7 +309,7 @@
   fprintf(stderr, "ERROR: %s\n", msg);
   lua_pop(luaState, 1);
+ }
   return error;
  }
- }
 
 
Index: trunk/src/lib/script_engine/script.h
===================================================================
--- trunk/src/lib/script_engine/script.h	(revision 8376)
+++ trunk/src/lib/script_engine/script.h	(revision 8408)
@@ -47,5 +47,5 @@
     bool executeFunction();
 
-     // get returned values the last return value in lua is the first in c. TODO: change order of return
+     // get returned values in the order the lua function returns it
     int   getReturnedInt();
     bool  getReturnedBool();
Index: trunk/src/lib/script_engine/script_class.cc
===================================================================
--- trunk/src/lib/script_engine/script_class.cc	(revision 8376)
+++ trunk/src/lib/script_engine/script_class.cc	(revision 8408)
@@ -17,17 +17,19 @@
 
 #include "script_class.h"
-
-using namespace std;
-
+#include <cassert>
 
 /**
- * standard constructor
+ * @brief standard constructor
  * @todo this constructor is not jet implemented - do it
 */
-ScriptClass::ScriptClass(const std::string& name, ClassID classID)
- : BaseObject(name)
+ScriptClass::ScriptClass(const std::string& name, ClassID classID, ScriptMethod* scriptMethods)
+    : BaseObject(name)
 {
-   this->setClassID(CL_SCRIPT_CLASS, "ScriptClass");
-   this->classID = classID;
+  assert(scriptMethods != NULL);
+  this->setClassID(CL_SCRIPT_CLASS, "ScriptClass");
+
+  this->_classID = classID;
+
+  this->_scriptMethods = scriptMethods;
 }
 
@@ -38,4 +40,4 @@
 ScriptClass::~ScriptClass ()
 {
-  // delete what has to be deleted here
+  delete this->_scriptMethods;
 }
Index: trunk/src/lib/script_engine/script_class.h
===================================================================
--- trunk/src/lib/script_engine/script_class.h	(revision 8376)
+++ trunk/src/lib/script_engine/script_class.h	(revision 8408)
@@ -11,6 +11,5 @@
 #include "script.h"
 #include "lunar.h"
-
-// FORWARD DECLARATION
+#include "script_method.h"
 
 
@@ -19,7 +18,6 @@
  * this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
  */
-#define CREATE_SCRIPTABLE_CLASS(CLASS_NAME, CLASS_ID) \
-    tScriptable<CLASS_NAME> global_##CLASS_NAME##_ScriptableClass(#CLASS_NAME, CLASS_ID)
-
+#define CREATE_SCRIPTABLE_CLASS(CLASS_NAME, CLASS_ID, SCRIPT_METHODS) \
+    tScriptClass<CLASS_NAME> global_##CLASS_NAME##_ScriptableClass(#CLASS_NAME, CLASS_ID, (new ScriptMethod)->SCRIPT_METHODS)
 
 
@@ -28,18 +26,21 @@
 {
 
-  public:
-    virtual ~ScriptClass();
+public:
+  virtual ~ScriptClass();
 
-    bool operator==(const std::string& name) { return (this->getName() == name); }
-    bool operator==(ClassID classID) { return (this->classID == classID); }
+  bool operator==(const std::string& name) { return (this->getName() == name); }
+  bool operator==(ClassID classID) { return (this->_classID == classID); }
 
-    virtual void registerClass(Script* script) = 0;
-    virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) = 0;
+  virtual void registerClass(Script* script) = 0;
+  virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) = 0;
 
-  protected:
-    ScriptClass(const std::string& name, ClassID classID);
+  const ScriptMethod* scriptMethods() const { return this->_scriptMethods; }
 
-  private:
-    ClassID             classID;
+protected:
+  ScriptClass(const std::string& name, ClassID classID, ScriptMethod* scriptMethods);
+
+private:
+  ClassID             _classID;
+  ScriptMethod*       _scriptMethods;
 };
 
@@ -48,24 +49,20 @@
 
 template <class T>
-class tScriptable : public ScriptClass
+class tScriptClass : public ScriptClass
 {
-  public:
-    tScriptable(const std::string& name, ClassID classID)
-        : ScriptClass(name, classID)
-    { }
+public:
+  tScriptClass(const std::string& name, ClassID classID, ScriptMethod* scriptMethods)
+      : ScriptClass(name, classID, scriptMethods)
+  { }
 
-    virtual void registerClass(Script* script)
-    {
-      Lunar<T>::Register(script);
-    }
-    virtual int insertObject(Script* L, BaseObject* obj, bool gc=false)
-    {
-      Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), obj->getName(), gc);
-    }
-
-
-
-}
-;
+  virtual void registerClass(Script* script)
+  {
+    Lunar<T>::Register(script, this->getName(), this->scriptMethods());
+  }
+  virtual int insertObject(Script* L, BaseObject* obj, bool gc=false)
+  {
+    return Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), obj->getName(), gc);
+  }
+};
 
 
Index: trunk/src/lib/script_engine/script_manager.cc
===================================================================
--- trunk/src/lib/script_engine/script_manager.cc	(revision 8376)
+++ trunk/src/lib/script_engine/script_manager.cc	(revision 8408)
@@ -1,4 +1,6 @@
 #include <string>
 #include <list>
+
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD
 
 
@@ -19,5 +21,4 @@
 {
   this->setName("ScriptManager");
-  printf("ScriptManager created\n");
   this->scripts = NULL;
   this->triggers = NULL;
@@ -37,5 +38,5 @@
 void ScriptManager::loadParams(const TiXmlElement* root)
 {
-  //BaseObject::loadParams(root);
+  BaseObject::loadParams(root);
   {
     LoadParamXML(root, "Scripts", this, ScriptManager, createScripts);
Index: trunk/src/lib/util/executor/executor.h
===================================================================
--- trunk/src/lib/util/executor/executor.h	(revision 8376)
+++ trunk/src/lib/util/executor/executor.h	(revision 8408)
@@ -33,5 +33,5 @@
  *  Objects of any Class (Templated)
  *  Default Values
- *  Functions with up to 5 parameters (more seems useless)
+ *  Functions with up to 5 parameters (more seems overhead, split up the function)
  *  Functions with many types (@see functor_list.h)
  */
Index: trunk/src/lib/util/executor/executor_functional.cc
===================================================================
--- trunk/src/lib/util/executor/executor_functional.cc	(revision 8376)
+++ trunk/src/lib/util/executor/executor_functional.cc	(revision 8408)
@@ -15,7 +15,5 @@
 
 #include "executor.h"
-
-std::string ExecutorFunctional_returningString_from;
-std::string ExecutorFunctional_returningString_default;
+std::string ExecutorFunctional_returningString_from[5];
 
 
@@ -32,5 +30,5 @@
 template<> float fromString<float>(const std::string& input, float defaultValue) { return isFloat(input, defaultValue); };
 template<> char fromString<char>(const std::string& input, char defaultValue) { return isInt(input, defaultValue); };
-template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue) { return ExecutorFunctional_returningString_from = isString(input, defaultValue); };
+template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue) { return (input.size() > 0) ? input : defaultValue; };
 
 
@@ -48,5 +46,5 @@
 template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getFloat(); };
 template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getChar(); };
-template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i) { return ExecutorFunctional_returningString_default = defaultValues[i].getString(); };
+template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i) { return ExecutorFunctional_returningString_from[i] = defaultValues[i].getString(); };
 
 
Index: trunk/src/lib/util/executor/executor_lua.cc
===================================================================
--- trunk/src/lib/util/executor/executor_lua.cc	(revision 8376)
+++ trunk/src/lib/util/executor/executor_lua.cc	(revision 8408)
@@ -18,6 +18,9 @@
 #include "executor_lua.h"
 
-std::string temp;
+#include "lunar.h"
 
+std::string temp[5];
+
+template<typename type> type* fromLua(lua_State* state, int index) { type *obj = Lunar<type>::check(state, 1); lua_remove(state, 1); return obj;};
 template<> bool fromLua<bool>(lua_State* state, int index) { return lua_toboolean(state, index); };
 template<> int fromLua<int>(lua_State* state, int index) { return (int)lua_tonumber(state, index); };
@@ -25,8 +28,8 @@
 template<> float fromLua<float>(lua_State* state, int index) { return (float)lua_tonumber(state, index); };
 template<> char fromLua<char>(lua_State* state, int index) { return (char)lua_tonumber(state, index); };
-template<> const std::string& fromLua<const std::string&>(lua_State* state, int index) { temp = lua_tostring(state, index); return temp; };
+template<> const std::string& fromLua<const std::string&>(lua_State* state, int index) { temp[index] = lua_tostring(state, index); return temp[index]; };
 
 
-
+template<typename type> void toLua(lua_State* state, type value) { Lunar<type>::push(state, value, false); };
 template<> void toLua<bool>(lua_State* state, bool value) { lua_pushboolean(state, (int) value); };
 template<> void toLua<int>(lua_State* state, int value)  { lua_pushnumber(state, (lua_Number) value); };
Index: trunk/src/lib/util/executor/executor_lua.h
===================================================================
--- trunk/src/lib/util/executor/executor_lua.h	(revision 8376)
+++ trunk/src/lib/util/executor/executor_lua.h	(revision 8408)
@@ -14,5 +14,5 @@
 
 
-template<typename type> type fromLua(lua_State* state, int index) { PRINTF(1)("NOT IMPLEMENTED\n"); };
+template<typename type> type fromLua(lua_State* state, int index);
 template<> bool fromLua<bool>(lua_State* state, int index);
 template<> int fromLua<int>(lua_State* state, int index);
@@ -23,5 +23,5 @@
 
 
-template<typename type> void toLua(lua_State* state, type value) { PRINTF(1)("NOT IMPLEMENTED\n"); };
+template<typename type> void toLua(lua_State* state, type value);
 template<> void toLua<bool>(lua_State* state, bool value);
 template<> void toLua<int>(lua_State* state, int value);
@@ -339,9 +339,3 @@
 };
 
-
-
-
-
-
-
 #endif /* _EXECUTOR_LUA_H */
Index: trunk/src/lib/util/loading/load_param.cc
===================================================================
--- trunk/src/lib/util/loading/load_param.cc	(revision 8376)
+++ trunk/src/lib/util/loading/load_param.cc	(revision 8408)
@@ -31,5 +31,4 @@
   :  object(object), paramName(paramName)
 {
-  this->object = object;
   this->inLoadCycle = inLoadCycle;
 
Index: trunk/src/lib/util/substring.h
===================================================================
--- trunk/src/lib/util/substring.h	(revision 8376)
+++ trunk/src/lib/util/substring.h	(revision 8408)
@@ -70,7 +70,7 @@
   inline unsigned int size() const { return this->strings.size(); };
   /** @param i the i'th String @returns the i'th string from the subset of Strings */
-const std::string& operator[](unsigned int i) const { return (i < this->strings.size()) ? this->strings[i] : emptyString;return this->getString(i); };
+  inline const std::string& operator[](unsigned int i) const { return (i < this->strings.size()) ? this->strings[i] : emptyString; };
   /** @param i the i'th String @returns the i'th string from the subset of Strings */
-  const std::string& getString(unsigned int i) const { return (*this)[i]; };
+  inline const std::string& getString(unsigned int i) const { return (*this)[i]; };
 
   // the almighty algorithm.
