Index: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am	(revision 8270)
+++ trunk/src/Makefile.am	(revision 8271)
@@ -28,5 +28,6 @@
 		$(libORXlibs_a_LIBRARIES_) \
 		$(CURL_LIBS) \
-		@QT_LIBS@
+		@QT_LIBS@ \
+		-L../extern_libs @LUA_LIBS@
 
 orxonox_SOURCES = \
Index: trunk/src/defs/class_id.h
===================================================================
--- trunk/src/defs/class_id.h	(revision 8270)
+++ trunk/src/defs/class_id.h	(revision 8271)
@@ -84,6 +84,4 @@
 
   CL_WORLD_ENTITY               =    0x40000000,
-
-  CL_RESOURCE                   =    0x80000000,
 
   /// subsuper-classes
@@ -223,4 +221,6 @@
   // Testing Entities
   CL_TEST_ENTITY                =    0x00000409,
+  CL_ACCOUNT                    =    0x00000410,
+  CL_TEST_OBJECT                =    0x00000411,
 
   // misc
@@ -242,4 +242,10 @@
   CL_AMMO_CONTAINER             =    0x00000604,
   CL_HUD                        =    0x00000620,
+
+
+  CL_SCRIPT_MANAGER             =    0x00000650,
+  CL_SCRIPT                     =    0x00000651,
+  CL_SCRIPT_CLASS               =    0x00000652,
+  CL_SCRIPT_TRIGGER             =    0x00000652,
 
 
Index: trunk/src/defs/include_paths.am
===================================================================
--- trunk/src/defs/include_paths.am	(revision 8270)
+++ trunk/src/defs/include_paths.am	(revision 8271)
@@ -26,4 +26,5 @@
 AM_CXXFLAGS+=-I$(MAINSRCDIR)/lib/newmat
 AM_CXXFLAGS+=-I$(MAINSRCDIR)/lib/sound
+AM_CXXFLAGS+=-I$(MAINSRCDIR)/lib/script_engine
 AM_CXXFLAGS+=-I$(MAINSRCDIR)/defs
 AM_CXXFLAGS+=-I$(MAINSRCDIR)/font
@@ -35,2 +36,3 @@
 AM_CXXFLAGS+=-I$(MAINSRCDIR)/util/track
 AM_CXXFLAGS+=-I$(MAINSRCDIR)/subprojects
+AM_CXXFLAGS+=-I$(MAINSRCDIR)/../extern_libs
Index: trunk/src/lib/BuildLibs.am
===================================================================
--- trunk/src/lib/BuildLibs.am	(revision 8270)
+++ trunk/src/lib/BuildLibs.am	(revision 8271)
@@ -6,4 +6,5 @@
                 $(LIB_PREFIX)/gui/gl/libORXglgui.a \
                 $(LIB_PREFIX)/gui/libORXbasegui.a \
+                $(LIB_PREFIX)/script_engine/libORXscript.a \
                 $(LIB_PREFIX)/graphics/importer/libORXimporter.a \
                 $(LIB_PREFIX)/graphics/libORXgraphics.a \
Index: trunk/src/lib/Makefile.am
===================================================================
--- trunk/src/lib/Makefile.am	(revision 8270)
+++ trunk/src/lib/Makefile.am	(revision 8271)
@@ -16,4 +16,5 @@
 		util/executor/executor.cc \
 		util/executor/executor_functional.cc \
+		util/executor/executor_lua.cc \
 		\
 		util/loading/resource_manager.cc \
@@ -45,5 +46,7 @@
 		util/executor/executor_functional.h \
 		util/executor/executor_xml.h \
+		util/executor/executor_lua.h \
 		util/executor/functor_list.h \
+		\
 		util/preferences.h \
 		util/threading.h \
Index: trunk/src/lib/gui/gl/signal_connector.cc
===================================================================
--- trunk/src/lib/gui/gl/signal_connector.cc	(revision 8270)
+++ trunk/src/lib/gui/gl/signal_connector.cc	(revision 8271)
@@ -92,5 +92,8 @@
   {
     if (this->isValid())
-      (*this->exec)(this->object, 0, NULL);
+    {
+      static int count = 0;
+      (*this->exec)(this->object, count, NULL);
+    }
   }
 
@@ -102,5 +105,8 @@
   {
     if (exec != NULL && object != NULL)
-      (*this->exec)(this->object, 1, (void*)&value0);
+    {
+      static int count = 1;
+      (*this->exec)(this->object, count, (void*)&value0);
+    }
   }
 
@@ -114,6 +120,7 @@
     if (exec != NULL && object != NULL)
     {
+      static int count = 2;
       MultiType mt[] = { value0, value1 };
-      (*this->exec)(this->object, 2, mt);
+      (*this->exec)(this->object, count, mt);
     }
   }
@@ -129,6 +136,7 @@
     if (exec != NULL && object != NULL)
     {
+      static int count = 3;
       MultiType mt[] = { value0, value1, value2 };
-      (*this->exec)(this->object, 3, mt);
+      (*this->exec)(this->object, count, mt);
     }
   }
@@ -145,6 +153,7 @@
     if (exec != NULL && object != NULL)
     {
+      static int count = 4;
       MultiType mt[] = { value0, value1, value2, value3 };
-      (*this->exec)(this->object, 4, mt);
+      (*this->exec)(this->object, count, mt);
     }
   }
@@ -162,6 +171,7 @@
     if (exec != NULL && object != NULL)
     {
+      static int count = 5;
       MultiType mt[] = { value0, value1, value2, value3, value4 };
-      (*this->exec)(this->object, 5, mt);
+      (*this->exec)(this->object, count, mt);
     }
   }
Index: trunk/src/lib/lang/class_list.cc
===================================================================
--- trunk/src/lib/lang/class_list.cc	(revision 8270)
+++ trunk/src/lib/lang/class_list.cc	(revision 8271)
@@ -221,4 +221,25 @@
           return (*bo);
     }
+  }
+  return NULL;
+}
+
+
+/**
+ * @brief checks if the BaseObject* object exists.
+ * @param objectName the name of the BaseObject to look for
+ * @param classID if not CL_NULL it will only search through a specific type of Objects. Otherwise it will be searched everywhere.
+ * @return true, if the Object Exists in the specified ClassID, false otherwise
+ * @todo: speed this up!!
+ */
+BaseObject* ClassList::getObject(const std::string& objectName, const std::string& className)
+{
+  ClassList* cl = ClassList::getClassList(className);
+  if (cl != NULL)
+  {
+    std::list<BaseObject*>::iterator bo;
+    for (bo = cl->objectList.begin(); bo != cl->objectList.end(); bo++)
+      if ((*bo)->getName() != NULL && objectName == (*bo)->getName())
+        return (*bo);
   }
   return NULL;
Index: trunk/src/lib/lang/class_list.h
===================================================================
--- trunk/src/lib/lang/class_list.h	(revision 8270)
+++ trunk/src/lib/lang/class_list.h	(revision 8271)
@@ -42,5 +42,6 @@
     static const std::list<BaseObject*>*  getList(const std::string& className); // { return (ClassList* fl = ClassList::getClassList(className) != NULL)? &(fl->objectList) : NULL;  };
     static const std::list<std::string>*  getClassNames();
-    static BaseObject*                    getObject(const std::string& name, ClassID classID = CL_NULL);
+    static BaseObject*                    getObject(const std::string& objectName, ClassID classID = CL_NULL);
+    static BaseObject*                    getObject(const std::string& objectName, const std::string& className);
     static bool                           exists(const BaseObject* object, ClassID classID = CL_NULL);
     static bool                           exists(const std::string& className, const std::string& objectName);
Index: trunk/src/lib/script_engine/Makefile.am
===================================================================
--- trunk/src/lib/script_engine/Makefile.am	(revision 8270)
+++ trunk/src/lib/script_engine/Makefile.am	(revision 8271)
@@ -1,4 +1,10 @@
 MAINSRCDIR=../..
 include $(MAINSRCDIR)/defs/include_paths.am
+
+
+LIB_PREFIX=$(MAINSRCDIR)/lib
+include $(MAINSRCDIR)/lib/BuildLibs.am
+
+
 
 INCLUDES= -I../../../extern_libs
@@ -6,21 +12,46 @@
 noinst_LIBRARIES = libORXscript.a
 
-libORXscript_a_SOURCES =
+libORXscript_a_SOURCES = \
+                script.cc\
+                script_manager.cc\
+		script_class.cc\
+		account.cc \
+		object.cc
+
 
 AM_CPPFLAGS= @LUA_INCLUDES@
 
-bin_PROGRAMS = account
-account_SOURCES = \
-                account.cc\
-                Script.cc
+noinst_HEADERS = \
+                lunar.h\
+                script.h\
+                script_manager.h\
+		script_class.h
 
 
 
-account_LDADD = libORXscript.a -L../../../extern_libs @LUA_LIBS@
 
-#main_LDFLAGS =
+check_PROGRAMS = example
 
 
-noinst_HEADERS = \
-                lunar.h\
-                Script.h
+
+
+
+
+
+example_DEPENDENCIES = \
+                $(MAINSRCDIR)/world_entities/libORXwe.a \
+                $(libORXlibs_a_LIBRARIES_) \
+                $(MAINSRCDIR)/util/libORXutils.a
+
+example_LDADD = \
+                $(MAINSRCDIR)/util/libORXutils.a \
+                $(libORXlibs_a_LIBRARIES_) \
+                libORXscript.a -L../../../extern_libs @LUA_LIBS@ \
+                $(MAINSRCDIR)/world_entities/libORXwe.a \
+                $(libORXlibs_a_LIBRARIES_) \
+                $(MAINSRCDIR)/util/libORXutils.a
+
+example_SOURCES= \
+                example.cc \
+                \
+                ../util/executor/executor_lua.cc
Index: trunk/src/lib/script_engine/Script.cc
===================================================================
--- trunk/src/lib/script_engine/Script.cc	(revision 8270)
+++ 	(revision )
@@ -1,187 +1,0 @@
-#include "Script.h"
-
-
-Script::Script()
-{
-  returnCount = argumentCount = 0;
-
-  luaState = lua_open();
-
-  luaopen_base(luaState);
-  luaopen_table(luaState);
-  luaopen_io(luaState);
-  luaopen_string(luaState);
-  luaopen_math(luaState);
-  luaopen_debug(luaState);
-
-}
-
-
-Script::~Script()
-{
-  lua_setgcthreshold(luaState, 0);  // collected garbage
-  lua_close(luaState);
-}
-
-
-bool Script::loadFile(std::string& filename)
- {
-
-   if(currentFile.length() != 0)
-     printf("Could not load %s because an other file is already loaded: %s\n",filename.c_str(), currentFile.c_str());
-
-   int error = luaL_loadfile (luaState, filename.c_str());
-
-   if(error == 0)
-   {
-     error = lua_pcall(luaState, 0, 0, 0);
-
-     if(error == 0)
-     {
-      currentFile = filename;
-      return true;
-     }
-     else
-     {
-      reportError(error);
-     }
-
-   }
-   else
-   {
-     reportError(error);
-   }
-
-   return false;
- }
-
- bool Script::executeFile()
- {
-   if(currentFile.length() != 0)
-   {
-    int error = lua_pcall(luaState, 0, 0, 0);
-    if( error == 0)
-      return true;
-     else
-      {
-       reportError(error);
-       return false;
-      }
-   }
-   return false;
- }
-
- bool Script::selectFunction(std::string& functionName, int retCount)
- {
-   lua_pushlstring(luaState, functionName.c_str(), functionName.size() );
-   lua_gettable(luaState, LUA_GLOBALSINDEX);
-
-   if(lua_isfunction( luaState , -1))
-   {
-     returnCount = retCount;
-     argumentCount = 0;
-     currentFunction = functionName;
-     return true;
-   }
-   else
-    return false;
-
- }
-
- //return number of returned values
- bool Script::executeFunction()
- {
-   if(currentFunction.length() != 0 )
-   {
-    int error = lua_pcall(luaState, argumentCount, returnCount,0);
-    if(error != 0)
-    {
-     reportError(error);
-     return false;
-    }
-    else
-    {
-      currentFunction.assign("");//a function gets unusable after beeing called for the first time
-      returnCount = argumentCount = 0;
-      return true;
-    }
-   }
-   else
-     printf("Error: no function selected.\n");
- }
-
-
- //overload this function to add different types
- bool Script::pushParam(int param, std::string& toFunction)
- {
-   if(currentFunction.compare(toFunction) == 0)
-   {
-     lua_pushnumber(luaState, (lua_Number) param);
-     argumentCount++;
-    return true;
-   }
-   else
-   {
-    printf("Couldn't add parameter because the wrong function is selected: %s instead of %s\n", currentFunction.c_str(), toFunction.c_str());
-    return false;
-   }
-
- }
-
-
- bool Script::pushParam(float param, std::string& toFunction)
- {
-   if(currentFunction.compare(toFunction) == 0)
-   {
-     lua_pushnumber(luaState,(lua_Number) param);
-     argumentCount++;
-     return true;
-   }
-   else
-   {
-     printf("Couldn't add parameter because the wrong function is selected: %s instead of %s\n", currentFunction.c_str(), toFunction.c_str());
-     return false;
-   }
-
- }
-
- bool Script::pushParam(double param, std::string& toFunction)
- {
-   if(currentFunction.compare(toFunction) == 0)
-   {
-     lua_pushnumber(luaState,(lua_Number) param);
-     argumentCount++;
-     return true;
-   }
-   else
-   {
-     printf("Couldn't add parameter because the wrong function is selected: %s instead of %s\n", currentFunction.c_str(), toFunction.c_str());
-     return false;
-   }
-
- }
-
- int Script::getReturnedInt()
- {
-   if(returnCount > 0)
-   {
-     printf("int found");
-     if(lua_isnumber(luaState, 1))
-     {
-       printf("int found");
-       int returnValue = (int)lua_tonumber(luaState, 1);
-       returnCount--;
-     }
-   }
- }
-
-
- int Script::reportError(int error)
- {
- const char *msg = lua_tostring(luaState, -1);
- if (msg == NULL) msg = "(error with no message)";
- 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 8270)
+++ 	(revision )
@@ -1,45 +1,0 @@
-#ifndef _SCRIPT_H
-#define _SCRIPT_H
-
-
-#include <string>
-#include "base_object.h"
-
-#include "luaincl.h"
-
-
-class Script
-{
-  public:
-    Script();
-    ~Script();
-
-    bool loadFile(std::string& filename);
-    bool executeFile();
-
-    lua_State* getLuaState() const{return luaState;}
-
-    bool selectFunction(std::string& functionName, int retCount);
-    bool executeFunction();
-    bool pushParam(int param, std::string& toFunction);//overload this function to add different types
-    bool pushParam(float param, std::string& toFunction);
-    bool pushParam(double param, std::string& toFunction);
-    int  getReturnedInt();
-
-
-
-  private:
-
-    int reportError(int error);
-
-    lua_State*         luaState;         //!< The lua_State that the Script works on
-    std::string        currentFile;      //!< The file that is loaded in the script
-    std::string        currentFunction;  //!< The name of the current active function (the one that gets the pushed parameter)
-    int                argumentCount;    //!< Number of arguments for the current function
-    int                returnCount;      //!< Number of return values of the current function
-
-
-
-
-};
-#endif /* _SCRIPT_H */
Index: trunk/src/lib/script_engine/account.cc
===================================================================
--- trunk/src/lib/script_engine/account.cc	(revision 8271)
+++ trunk/src/lib/script_engine/account.cc	(revision 8271)
@@ -0,0 +1,42 @@
+
+
+
+#include <iostream>
+
+#include "luaincl.h"
+#include "base_object.h"
+#include "lunar.h"
+
+#include "script_class.h"
+
+
+ class Account : public BaseObject {
+      lua_Number m_balance;
+   public:
+     static const char className[];
+     static Lunar<Account>::RegType methods[];
+
+     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; };
+
+     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);
+
Index: trunk/src/lib/script_engine/example.cc
===================================================================
--- trunk/src/lib/script_engine/example.cc	(revision 8271)
+++ trunk/src/lib/script_engine/example.cc	(revision 8271)
@@ -0,0 +1,148 @@
+
+#include <iostream>
+
+#include "luaincl.h"
+#include "lunar.h"
+#include "script.h"
+
+// create classdummys for the scripts
+CREATE_SCRIPTABLE_CLASS(Account, CL_ACCOUNT)
+CREATE_SCRIPTABLE_CLASS(Object, CL_TEST_OBJECT)
+
+    class Account : public BaseObject {
+      lua_Number m_balance;
+    public:
+      static const char className[];
+      static Lunar<Account>::RegType methods[];
+
+      Account(lua_State *L)      { m_balance = luaL_checknumber(L, 1); }
+      Account(double balance=0)    : m_balance(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); }
+    };
+
+    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}
+    };
+
+
+    class Object : public BaseObject {
+      public:
+        static const char className[];
+        static Lunar<Object>::RegType methods[];
+
+        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);
+        }
+
+        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);
+        }
+
+        int getCallCount(){ return 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}
+    };
+
+    int main(int argc, char *argv[])
+    {
+      std::string file("lunartest2.lua");
+     // Script script;
+      Script* script = ScriptManager::getInstance()->getScriptByFile(file);
+      printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState()));
+
+      // Register classes with the script
+      // Lunar<Account>::Register(&script);
+      //Lunar<Object>::Register(&script);
+
+      //Object* obj= new Object();
+      //Account a;
+      //Account *b = new Account(30);
+
+      // Add instances to the script
+      //Lunar<Object>::insertObject(&script,obj,"Obj",true);
+      //Lunar<Account>::insertObject(&script,&a,"a",false);
+      //Lunar<Account>::insertObject(&script,b,"b",true);
+       //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
+
+      //Load a file
+      //std::string file("lunartest2.lua");
+
+      //if(script.loadFile(file))
+        //printf("File %s succefully loaded\n", file.c_str());
+      //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
+
+      //execute a function
+      printf("----------- main -----------\n");
+      std::string main("main");
+      if( script->selectFunction(main,3))
+       printf("function %s selected\n",main.c_str());
+
+      script->pushParam(3.14159,main);
+      script->executeFunction();
+
+      float retf = script->getReturnedFloat();
+      printf("main returned %f\n",retf);
+
+
+      if(script->getReturnedBool())
+       printf("main returned true\n");
+      else
+       printf("main returned false\n");
+
+      int ret = script->getReturnedInt();
+      printf("main returned %i\n",ret);
+
+      //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
+      //execute a 2nd function
+      printf("----------- test -----------\n");
+      std::string test("test");
+      if( script->selectFunction(test,0))
+       printf("function %s selected\n",test.c_str());
+
+      script->executeFunction();
+
+
+      //if(argc>1) lua_dofile(script.getLuaState(), argv[1]);
+      printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState()));
+
+      return 0;
+    }
+
Index: trunk/src/lib/script_engine/lunar.h
===================================================================
--- trunk/src/lib/script_engine/lunar.h	(revision 8270)
+++ trunk/src/lib/script_engine/lunar.h	(revision 8271)
@@ -3,7 +3,9 @@
 
 #include <string>
-#include "Script.h"
+#include <cassert>
+#include "script.h"
 
 #include "luaincl.h"
+#include "executor/executor_lua.h"
 
 
@@ -12,5 +14,5 @@
       typedef struct { T *pT; } userdataType;
     public:
-      typedef int (T::*mfp)(lua_State *L);
+      typedef Executor* mfp;
       typedef struct { const char *name; mfp mfunc; } RegType;
 
@@ -139,8 +141,6 @@
       static int insertObject(Script* script, T* obj, const std::string& name, bool gc=false)
       {
-        if(script != NULL)
-          return insertObject(script->getLuaState(), obj, name, gc);
-
-
+        assert (script != NULL);
+        return insertObject(script->getLuaState(), obj, name, gc);
       }
 
@@ -163,5 +163,7 @@
         // get member function from upvalue
         RegType *l = static_cast<RegType*>(lua_touserdata(L, lua_upvalueindex(1)));
-        return (obj->*(l->mfunc))(L);  // call member function
+        int value;
+        (*l->mfunc)(obj, value, L);  // call member function
+        return value;
       }
 
Index: trunk/src/lib/script_engine/lunartest2.lua
===================================================================
--- trunk/src/lib/script_engine/lunartest2.lua	(revision 8270)
+++ trunk/src/lib/script_engine/lunartest2.lua	(revision 8271)
@@ -15,8 +15,31 @@
 getmetatable(Account).__index = parent
 
+
+function test()
+io.write("Hi i'm test\n")
+end
+
+
 function main(arg)
+  -- use parameter
   io.write("main received ", arg)
   io.write(" as parameter\n")
+
+  --call member of an inserted object
   Obj:printName()
+
+  --create object of a registered type
+  o = Object()
+  o:printName()
+
+  --take returnvalue from c
+  callCount = Obj:getCallCount()
+  io.write("callCount is now ",callCount)
+  io.write("\n")
+
+  --pass parameters to a c++ method
+  Obj:takeParam(3)
+
+  --print object information
   print('a =', a)
   print('b =', b)
@@ -28,5 +51,6 @@
   Obj:printName()
 
-  return 2
+  return 2,false,2.72
+
   --debug.debug()
 end
Index: trunk/src/lib/script_engine/object.cc
===================================================================
--- trunk/src/lib/script_engine/object.cc	(revision 8271)
+++ trunk/src/lib/script_engine/object.cc	(revision 8271)
@@ -0,0 +1,53 @@
+
+#include <iostream>
+
+#include "base_object.h"
+#include "lunar.h"
+
+#include "script_class.h"
+
+
+class Object : public BaseObject {
+   public:
+     static const char className[];
+     static Lunar<Object>::RegType methods[];
+
+     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);
+     }
+
+     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);
+     }
+
+     int getCallCount(){ return 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);
Index: trunk/src/lib/script_engine/script.cc
===================================================================
--- trunk/src/lib/script_engine/script.cc	(revision 8271)
+++ trunk/src/lib/script_engine/script.cc	(revision 8271)
@@ -0,0 +1,329 @@
+#include "script.h"
+#include "script_class.h"
+#include "luaincl.h"
+
+
+#include "loading/load_param.h"
+#include "parser/tinyxml/tinyxml.h"
+
+#include "class_list.h"
+
+Script::Script(const TiXmlElement* root)
+{
+  this->setClassID(CL_SCRIPT, "Script");
+
+  returnCount = argumentCount = 0;
+
+  luaState = lua_open();
+
+  luaopen_base(luaState);
+  luaopen_table(luaState);
+  luaopen_io(luaState);
+  luaopen_string(luaState);
+  luaopen_math(luaState);
+  luaopen_debug(luaState);
+
+  if (root != NULL)
+    this->loadParams(root);
+}
+
+
+Script::~Script()
+{
+  lua_setgcthreshold(luaState, 0);  // collected garbage
+  lua_close(luaState);
+}
+
+
+void Script::loadParams(const TiXmlElement* root)
+{
+  BaseObject::loadParams(root);
+
+  LOAD_PARAM_START_CYCLE(root, object);
+  {
+    LoadParam_CYCLE(object, "object", this, Script, addObject)
+        .describe("The name of an object that is needed by a script");
+  }
+  LOAD_PARAM_END_CYCLE(object);
+
+
+  LoadParam(root, "file", this, Script, loadFileNoRet)
+      .describe("the fileName of the script, that should be loaded into this world")
+      .defaultValues("");
+}
+
+
+
+bool Script::loadFile(const std::string& filename)
+ {
+
+   if(currentFile.length() != 0)
+   {
+     printf("Could not load %s because an other file is already loaded: %s\n",filename.c_str(), currentFile.c_str());
+     return false;
+    }
+
+   int error = luaL_loadfile (luaState, filename.c_str());
+
+   if(error == 0)
+   {
+     error = lua_pcall(luaState, 0, 0, 0);
+
+     if(error == 0)
+     {
+      currentFile = filename;
+      return true;
+     }
+     else
+     {
+      reportError(error);
+     }
+
+   }
+   else
+   {
+     reportError(error);
+   }
+
+   return false;
+ }
+
+
+ void Script::addObject(const std::string& className, const std::string& objectName)
+ {
+   BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
+   WorldObject tmpObj;
+   if (scriptClass != NULL)
+   {
+     tmpObj.type = className;
+     if( !classIsRegistered(className) )
+     {
+     static_cast<ScriptClass*>(scriptClass)->registerClass(this);
+     }
+
+     BaseObject* object = ClassList::getObject(objectName, className);
+     if (object != NULL && !objectIsAdded(objectName))
+     {
+        static_cast<ScriptClass*>(scriptClass)->insertObject(this, object, false);
+        tmpObj.name = objectName;
+        registeredObjects.push_back(tmpObj);
+     }
+   }
+ }
+
+
+
+
+ bool Script::executeFile()
+ {
+   printf("WARNING: script.executeFile is not implemented yet");
+   /*if(currentFile.length() != 0)
+   {
+    int error = lua_pcall(luaState, 0, 0, 0);
+    if( error == 0)
+      return true;
+     else
+      {
+       reportError(error);
+       return false;
+      }
+ }*/
+   return false;
+ }
+
+ bool Script::selectFunction(std::string& functionName, int retCount)
+ {
+   if(returnCount == 0 && currentFunction.length() == 0) //no return values left on the stack and no other function selected
+   {
+   lua_pushlstring(luaState, functionName.c_str(), functionName.size() );
+   lua_gettable(luaState, LUA_GLOBALSINDEX);
+
+   if(lua_isfunction( luaState , -1))
+   {
+     returnCount = retCount;
+     argumentCount = 0;
+     currentFunction = functionName;
+     return true;
+   }
+   else
+    return false;
+   }
+   else
+     printf("There is an other function active ( %s ) or there are unremoved return values on the stack. Please remove them first.\n",currentFunction.c_str());
+   return false;
+ }
+
+ //return number of returned values
+ bool Script::executeFunction()
+ {
+   if(currentFunction.length() != 0 )
+   {
+    int error = lua_pcall(luaState, argumentCount, returnCount,0);
+    if(error != 0)
+    {
+     reportError(error);
+     return false;
+    }
+    else
+    {
+      currentFunction.assign("");//a function gets unusable after beeing called for the first time
+      argumentCount = 0;
+      return true;
+    }
+   }
+   else
+     printf("Error: no function selected.\n");
+ }
+
+
+ //overload this function to add different types
+ bool Script::pushParam(int param, std::string& toFunction)
+ {
+   if(currentFunction.compare(toFunction) == 0)
+   {
+     lua_pushnumber(luaState, (lua_Number) param);
+     argumentCount++;
+    return true;
+   }
+   else
+   {
+    printf("Couldn't add parameter because the wrong function is selected: %s instead of %s\n", currentFunction.c_str(), toFunction.c_str());
+    return false;
+   }
+
+ }
+
+
+ bool Script::pushParam(float param, std::string& toFunction)
+ {
+   if(currentFunction.compare(toFunction) == 0)
+   {
+     lua_pushnumber(luaState,(lua_Number) param);
+     argumentCount++;
+     return true;
+   }
+   else
+   {
+     printf("Couldn't add parameter because the wrong function is selected: %s instead of %s\n", currentFunction.c_str(), toFunction.c_str());
+     return false;
+   }
+
+ }
+
+ bool Script::pushParam(double param, std::string& toFunction)
+ {
+   if(currentFunction.compare(toFunction) == 0)
+   {
+     lua_pushnumber(luaState,(lua_Number) param);
+     argumentCount++;
+     return true;
+   }
+   else
+   {
+     printf("Couldn't add parameter because the wrong function is selected: %s instead of %s\n", currentFunction.c_str(), toFunction.c_str());
+     return false;
+   }
+
+ }
+
+ int Script::getReturnedInt()
+ {
+   int returnValue;
+   if(returnCount > 0)
+   {
+     if(lua_isnumber(luaState, -1))
+     {
+       returnValue = (int)lua_tonumber(luaState, -1);
+       returnCount--;
+       lua_pop(luaState,1);
+     }
+   }
+   return returnValue;
+ }
+
+
+ bool Script::getReturnedBool()
+ {
+   bool returnValue;
+   if(returnCount > 0)
+   {
+     if(lua_isboolean(luaState, -1))
+     {
+       returnValue = (bool)lua_toboolean(luaState, -1);
+       returnCount--;
+       lua_pop(luaState,1);
+     }
+   }
+   return returnValue;
+ }
+
+float Script::getReturnedFloat()
+ {
+   float returnValue;
+   if(returnCount > 0)
+   {
+     if(lua_isnumber(luaState, -1))
+     {
+       returnValue = (float)lua_tonumber(luaState, -1);
+       returnCount--;
+       lua_pop(luaState,1);
+     }
+   }
+   return returnValue;
+ }
+
+ void Script::getReturnedString(std::string& string)
+ {
+   const char* returnValue;
+   if(returnCount > 0)
+   {
+     if(lua_isstring(luaState, -1))
+     {
+       returnValue = lua_tostring(luaState, -1);
+       returnCount--;
+       lua_pop(luaState,1);
+     }
+   }
+  string.assign(returnValue);
+ }
+
+ int Script::reportError(int error)
+ {
+ if(error != 0)
+ {
+  const char *msg = lua_tostring(luaState, -1);
+  if (msg == NULL) msg = "(error with no message)";
+  fprintf(stderr, "ERROR: %s\n", msg);
+  lua_pop(luaState, 1);
+  return error;
+ }
+ }
+
+
+ bool Script::classIsRegistered(const std::string& type)
+ {
+   for(std::list<WorldObject>::const_iterator it = registeredObjects.begin(); it != registeredObjects.end(); it++ )
+   {
+     if( (*it).type == type)
+     {
+       return true;
+     }
+   }
+   return false;
+ }
+
+
+
+ bool Script::objectIsAdded(const std::string& name)
+ {
+   for(std::list<WorldObject>::const_iterator it = registeredObjects.begin(); it != registeredObjects.end(); it++ )
+   {
+     if( (*it).name == name)
+     {
+       return true;
+     }
+   }
+   return false;
+
+
+ }
Index: trunk/src/lib/script_engine/script.h
===================================================================
--- trunk/src/lib/script_engine/script.h	(revision 8271)
+++ trunk/src/lib/script_engine/script.h	(revision 8271)
@@ -0,0 +1,73 @@
+#ifndef _SCRIPT_H
+#define _SCRIPT_H
+
+
+#include "base_object.h"
+
+
+struct lua_State;
+
+struct WorldObject
+{
+  std::string name;
+  std::string type;
+};
+
+class Script : public BaseObject
+{
+  public:
+    Script(const TiXmlElement* root = NULL);
+    ~Script();
+    
+    /// LOADING
+    void loadParams(const TiXmlElement* root);
+
+    void loadFileNoRet(const std::string& filename) { loadFile(filename); };
+    bool loadFile(const std::string& filename);
+    void addObject(const std::string& className, const std::string& objectName);
+    
+    /// QUERRYING
+    /** @returns fileName */
+    std::string getFileName() { return currentFile; }
+    lua_State* getLuaState() const { return luaState; }
+
+
+    
+    /// EXECUTING
+    // first select function
+    bool selectFunction(std::string& functionName, int retCount);
+
+    // push parameters for luafunction
+    bool  pushParam(int param, std::string& toFunction);
+    bool  pushParam(float param, std::string& toFunction);
+    bool  pushParam(double param, std::string& toFunction);
+
+    // Execute the Function
+    bool executeFunction();
+    
+     // get returned values the last return value in lua is the first in c. TODO: change order of return
+    int   getReturnedInt();
+    bool  getReturnedBool();
+    float getReturnedFloat();
+    void  getReturnedString(std::string& string);
+
+    bool executeFile();
+
+  private:
+
+    int  reportError(int error);                      //!< Get errormessage from the lua stack and print it.
+    bool classIsRegistered(const std::string& type);  //!< Checks wheter the class "type" has already been registered with the script
+    bool objectIsAdded(const std::string& name);      //!< Checks wheter the object "name" has already been added to the script
+
+    lua_State*              luaState;                //!< The lua_State that the Script works on
+    std::string             currentFile;             //!< The file that is loaded in the script
+    std::string             currentFunction;         //!< The name of the current active function (the one that gets the pushed parameter)
+    int                     argumentCount;           //!< Number of arguments for the current function
+    int                     returnCount;             //!< Number of return values of the current function
+    
+    std::list<WorldObject>  registeredObjects;       //!< The list of all the objects and their type that have been registered with this script
+
+
+
+};
+#endif /* _SCRIPT_H */
Index: trunk/src/lib/script_engine/script_class.cc
===================================================================
--- trunk/src/lib/script_engine/script_class.cc	(revision 8271)
+++ trunk/src/lib/script_engine/script_class.cc	(revision 8271)
@@ -0,0 +1,41 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: ...
+   co-programmer: ...
+*/
+
+//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
+
+#include "script_class.h"
+
+using namespace std;
+
+
+/**
+ * standard constructor
+ * @todo this constructor is not jet implemented - do it
+*/
+ScriptClass::ScriptClass(const std::string& name, ClassID classID)
+ : BaseObject(name)
+{
+   this->setClassID(CL_SCRIPT_CLASS, "ScriptClass");
+   this->classID = classID;
+}
+
+
+/**
+ * standard deconstructor
+*/
+ScriptClass::~ScriptClass ()
+{
+  // delete what has to be deleted here
+}
Index: trunk/src/lib/script_engine/script_class.h
===================================================================
--- trunk/src/lib/script_engine/script_class.h	(revision 8271)
+++ trunk/src/lib/script_engine/script_class.h	(revision 8271)
@@ -0,0 +1,72 @@
+/*!
+ * @file script_class.h
+ * @brief Definition of ...
+*/
+
+#ifndef _SCRIPT_CLASS_H
+#define _SCRIPT_CLASS_H
+
+#include "base_object.h"
+
+#include "script.h"
+#include "lunar.h"
+
+// FORWARD DECLARATION
+
+
+/**
+ * Creates a factory to a Loadable Class.
+ * 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)
+
+
+
+//! A class for ...
+class ScriptClass : protected BaseObject
+{
+
+  public:
+    virtual ~ScriptClass();
+
+    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;
+
+  protected:
+    ScriptClass(const std::string& name, ClassID classID);
+
+  private:
+    ClassID             classID;
+};
+
+
+
+
+template <class T>
+class tScriptable : public ScriptClass
+{
+  public:
+    tScriptable(const std::string& name, ClassID classID)
+        : ScriptClass(name, classID)
+    { }
+
+    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);
+    }
+
+
+
+}
+;
+
+
+#endif /* _SCRIPT_CLASS_H */
Index: trunk/src/lib/script_engine/script_manager.cc
===================================================================
--- trunk/src/lib/script_engine/script_manager.cc	(revision 8271)
+++ trunk/src/lib/script_engine/script_manager.cc	(revision 8271)
@@ -0,0 +1,110 @@
+#include <string>
+#include <list>
+
+
+#include "script_manager.h"
+#include "lunar.h"
+
+#include "class_list.h"
+
+#include "script.h"
+#include "script_trigger.h"
+#include "luaincl.h"
+#include "loading/load_param.h"
+#include "parser/tinyxml/tinyxml.h"
+
+
+
+ScriptManager::ScriptManager(const TiXmlElement* root)
+{
+  this->setName("ScriptManager");
+
+  this->scripts = NULL;
+  this->triggers = NULL;
+
+  if (root != NULL)
+    this->loadParams(root);
+}
+
+
+
+ScriptManager::~ScriptManager()
+{
+  this->flush();
+}
+
+
+void ScriptManager::loadParams(const TiXmlElement* root)
+{
+  //BaseObject::loadParams(root);
+  {
+    LoadParamXML(root, "Scripts", this, ScriptManager, createScripts);
+
+    LoadParamXML(root, "ScriptTriggers", this, ScriptManager, createTriggers);
+  } // make shure that the loading process is finished
+
+  // fill the scripts and triggers (doing that on runtime is very slow!)
+  getTriggers();
+  getScripts();
+}
+
+
+
+void  ScriptManager::flush()
+{
+  //Delete all scripts as they aren't deleted automatically
+  if(this->getScripts())
+    while(!scripts->empty())
+      delete scripts->front();
+}
+
+void  ScriptManager::createScripts(const TiXmlElement* scripts)
+{
+
+  LOAD_PARAM_START_CYCLE(scripts, object);
+  {
+    new Script(object);
+  }
+  LOAD_PARAM_END_CYCLE(object);
+
+}
+
+void ScriptManager::createTriggers(const TiXmlElement* triggers)
+{
+  LOAD_PARAM_START_CYCLE(triggers, object);
+  {
+    new ScriptTrigger(object);
+  }
+  LOAD_PARAM_END_CYCLE(object);
+
+}
+
+
+Script* ScriptManager::getScriptByFile(const std::string& file)
+{
+  if(getScripts())
+    for(std::list<BaseObject*>::const_iterator it = scripts->begin(); it != scripts->end(); it++ )
+    {
+      if( (dynamic_cast<Script*>(*it))->getFileName().compare(file) == 0)
+      {
+        return dynamic_cast<Script*>(*it);
+      }
+    }
+
+  return NULL;
+
+}
+
+
+bool ScriptManager::getScripts()
+{
+  return (this->scripts != NULL || (this->scripts = ClassList::getList(CL_SCRIPT)) != NULL);
+}
+
+bool ScriptManager::getTriggers()
+{
+  return (this->triggers != NULL || (this->triggers = ClassList::getList(CL_SCRIPT_TRIGGER)) != NULL);
+}
+
+
+
Index: trunk/src/lib/script_engine/script_manager.h
===================================================================
--- trunk/src/lib/script_engine/script_manager.h	(revision 8271)
+++ trunk/src/lib/script_engine/script_manager.h	(revision 8271)
@@ -0,0 +1,42 @@
+#ifndef _SCRIPT_MANAGER_H
+#define _SCRIPT_MANAGER_H
+
+#include <list>
+
+#include "base_object.h"
+#include "script.h"
+
+
+class ScriptTrigger;
+class Scriptable;
+
+class ScriptManager : public BaseObject
+{
+ public:
+   ScriptManager(const TiXmlElement* root = NULL);
+   ~ScriptManager();
+
+  /// LOADING
+  virtual void loadParams(const TiXmlElement* root);
+
+  /// QUERY PROCESS
+  Script* getScriptByFile(const std::string& file);
+
+  void  flush();                                   //!< Resets the script manager
+
+ private:
+   void  createScripts(const TiXmlElement* scripts);
+   void  createTriggers(const TiXmlElement* triggers);
+
+   bool getTriggers();
+   bool getScripts();
+
+   static ScriptManager*             singletonRef;   //!< Reference to this class
+
+   const std::list<BaseObject*>*     triggers;       //!< A list of all the triggers in the world
+
+   const std::list<BaseObject*>*     scripts;        //!< A list of all the scripts in the world
+
+
+};
+#endif
Index: trunk/src/lib/util/executor/executor.h
===================================================================
--- trunk/src/lib/util/executor/executor.h	(revision 8270)
+++ trunk/src/lib/util/executor/executor.h	(revision 8271)
@@ -53,5 +53,5 @@
     // EXECUTE
     /** executes a Command. @param objec the Object, @param count how many values, @param values the Values */
-    virtual void operator()(BaseObject* object, unsigned int count, void* values) const = 0;
+    virtual void operator()(BaseObject* object, int& count, void* values) const = 0;
     /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */
     virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const = 0;
Index: trunk/src/lib/util/executor/executor_functional.h
===================================================================
--- trunk/src/lib/util/executor/executor_functional.h	(revision 8270)
+++ trunk/src/lib/util/executor/executor_functional.h	(revision 8271)
@@ -123,5 +123,5 @@
 
   /** executes a Command. @param objec the Object, @param count how many values, @param values the Values */
-  virtual void operator()(BaseObject* object, unsigned int count, void* values) const
+  virtual void operator()(BaseObject* object, int& count, void* values) const
   {
     (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)();
@@ -163,5 +163,5 @@
 
   /** executes a Command. @param objec the Object, @param count how many values, @param values the Values */
-  virtual void operator()(BaseObject* object, unsigned int count, void* values) const
+  virtual void operator()(BaseObject* object, int& count, void* values) const
   {
     const MultiType* mt = (const MultiType*)values;
@@ -227,5 +227,5 @@
 
   /** executes a Command. @param objec the Object, @param count how many values, @param values the Values */
-  virtual void operator()(BaseObject* object, unsigned int count, void* values) const
+  virtual void operator()(BaseObject* object, int& count, void* values) const
   {
     const MultiType* mt = (const MultiType*)values;
@@ -282,5 +282,5 @@
 
   /** executes a Command. @param objec the Object, @param count how many values, @param values the Values */
-  virtual void operator()(BaseObject* object, unsigned int count, void* values) const
+  virtual void operator()(BaseObject* object, int& count, void* values) const
   {
     const MultiType* mt = (const MultiType*)values;
@@ -340,5 +340,5 @@
 
   /** executes a Command. @param objec the Object, @param count how many values, @param values the Values */
-  virtual void operator()(BaseObject* object, unsigned int count, void* values) const
+  virtual void operator()(BaseObject* object, int& count, void* values) const
   {
     const MultiType* mt = (const MultiType*)values;
@@ -400,5 +400,5 @@
 
   /** executes a Command. @param objec the Object, @param count how many values, @param values the Values */
-  virtual void operator()(BaseObject* object, unsigned int count, void* values) const
+  virtual void operator()(BaseObject* object, int& count, void* values) const
   {
     const MultiType* mt = (const MultiType*)values;
Index: trunk/src/lib/util/executor/executor_lua.cc
===================================================================
--- trunk/src/lib/util/executor/executor_lua.cc	(revision 8270)
+++ trunk/src/lib/util/executor/executor_lua.cc	(revision 8271)
@@ -18,17 +18,19 @@
 #include "executor_lua.h"
 
-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_toumber(state, index); };
-template<> unsigned int fromLua<unsigned int>(lua_state* state, int index) { return (unsigned int)lua_tonumber(state, index); };
-template<> float fromLua<float>(lua_state* state, int index) { return (float)lua_tonumber(state, index); };
-template<> char fromLua<char>(lua_state* state, int index) { reutnr (char)lua_tonumber(state, index); };
-template<> const std::string& fromLua<const std::string&>(lua_state* state, int index) { return lua_tostring(state, index); };
+std::string temp;
+
+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); };
+template<> unsigned int fromLua<unsigned int>(lua_State* state, int index) { return (unsigned int)lua_tonumber(state, index); };
+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<> 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); };
-template<> void toLua<unsigned int>(lua_state* state, unsigned int value){ lua_pushnumber(state, (lua_Number) value); };
-template<> void toLua<float>(lua_state* state, float value) { lua_pushnumber(state, (lua_Number) value); };
-template<> void toLua<char>(lua_state* state, char value) { lua_pushnumber(state, (lua_Number) value); };
-template<> void toLua<const std::string&>(lua_state* state, const std::string& value) {lua_pushstring (state, value.c_str()); }
+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); };
+template<> void toLua<unsigned int>(lua_State* state, unsigned int value){ lua_pushnumber(state, (lua_Number) value); };
+template<> void toLua<float>(lua_State* state, float value) { lua_pushnumber(state, (lua_Number) value); };
+template<> void toLua<char>(lua_State* state, char value) { lua_pushnumber(state, (lua_Number) value); };
+template<> void toLua<const std::string&>(lua_State* state, const std::string& value) {lua_pushstring (state, value.c_str()); }
Index: trunk/src/lib/util/executor/executor_lua.h
===================================================================
--- trunk/src/lib/util/executor/executor_lua.h	(revision 8270)
+++ trunk/src/lib/util/executor/executor_lua.h	(revision 8271)
@@ -4,38 +4,41 @@
  */
 
-#ifndef _EXECUTOR_SPECIALS_H
-#define _EXECUTOR_SPECIALS_H
+#ifndef _EXECUTOR_LUA_H
+#define _EXECUTOR_LUA_H
 
 #include "executor.h"
 #include "compiler.h"
-
+#include "debug.h"
 #include "luaincl.h"
 
 
 
-template<typename type> type fromLua(lua_state* state, int index) { PRINTF(1)("NOT IMPLEMENTED\n"); };
-template<> bool fromLua<bool>(lua_state* state, int index);
-template<> int fromLua<int>(lua_state* state, int index);
-template<> unsigned int fromLua<unsigned int>(lua_state* state, int index);
-template<> float fromLua<float>(lua_state* state, int index);
-template<> char fromLua<char>(lua_state* state, int index);
-template<> const std::string& fromLua<const std::string&>(lua_state* state, int index);
-
-
-template<typename type> void toLua(lua_state* state, type value) { PRINTF(1)("NOT IMPLEMENTED\n"); };
-template<> void toLua<bool>(lua_state* state, bool value);
-template<> void toLua<int>(lua_state* state, int value);
-template<> void toLua<unsigned int>(lua_state* state, unsigned int value);
-template<> void toLua<float>(lua_state* state, float value);
-template<> void toLua<char>(lua_state* state, char value);
-template<> void toLua<const std::string&>(lua_state* state, const std::string& value);
+template<typename type> type fromLua(lua_State* state, int index) { PRINTF(1)("NOT IMPLEMENTED\n"); };
+template<> bool fromLua<bool>(lua_State* state, int index);
+template<> int fromLua<int>(lua_State* state, int index);
+template<> unsigned int fromLua<unsigned int>(lua_State* state, int index);
+template<> float fromLua<float>(lua_State* state, int index);
+template<> char fromLua<char>(lua_State* state, int index);
+template<> const std::string& fromLua<const std::string&>(lua_State* state, int index);
+
+
+template<typename type> void toLua(lua_State* state, type value) { PRINTF(1)("NOT IMPLEMENTED\n"); };
+template<> void toLua<bool>(lua_State* state, bool value);
+template<> void toLua<int>(lua_State* state, int value);
+template<> void toLua<unsigned int>(lua_State* state, unsigned int value);
+template<> void toLua<float>(lua_State* state, float value);
+template<> void toLua<char>(lua_State* state, char value);
+template<> void toLua<const std::string&>(lua_State* state, const std::string& value);
 
 // FORWARD DECLARATION
 
+///////////////////////
+///// WITHOUT RET /////
+///////////////////////
 
 ///////////
 //// 0 ////
 ///////////
-//! Executes a Function with a lua_state* parameter.
+//! Executes a Function with a lua_State* parameter.
 template<class T> class ExecutorLua0 : public Executor
 {
@@ -62,7 +65,8 @@
     }
 
-    virtual void operator()(BaseObject* object, unsigned int count, void* values) const
+    virtual void operator()(BaseObject* object, int& count, void* values) const
     {
       (dynamic_cast<T*>(object)->*(functionPointer))();
+      count = 0;
     }
 
@@ -72,6 +76,8 @@
     virtual Executor* clone () const
     {
-      return = new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer));
-    }
+      return new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer));
+    }
+  private:
+    void          (T::*functionPointer)();
 };
 
@@ -81,5 +87,5 @@
 //// 1 ////
 ///////////
-//! Executes a Function with a lua_state* parameter.
+//! Executes a Function with a lua_State* parameter.
 template<class T, typename type0> class ExecutorLua1 : public Executor
 {
@@ -89,5 +95,5 @@
      * @param function a Function to call
      */
-    ExecutorLua0(void(T::*function)(type0))
+    ExecutorLua1(void(T::*function)(type0))
         : Executor(ExecutorParamType<type0>())
     {
@@ -106,7 +112,8 @@
     }
 
-    virtual void operator()(BaseObject* object, unsigned int count, void* values) const
-    {
-      lua_state* state = (lua_state*)values;
+    virtual void operator()(BaseObject* object, int& count, void* values) const
+    {
+      lua_State* state = (lua_State*)values;
+      count = 0;
 
       (dynamic_cast<T*>(object)->*(functionPointer))(fromLua<type0>(state, 1));
@@ -118,6 +125,8 @@
     virtual Executor* clone () const
     {
-      return = new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer));
-    }
+      return new ExecutorLua1<T, type0>((this->functionPointer));
+    }
+  private:
+    void          (T::*functionPointer)(type0);
 };
 
@@ -127,13 +136,13 @@
 //// 2 ////
 ///////////
-//! Executes a Function with a lua_state* parameter.
-template<class T, typename type0, typename type1> class ExecutorLua1 : public Executor
-{
-  public:
-    /**
-     * @brief Constructor of a ExecutorXML
-     * @param function a Function to call
-     */
-    ExecutorLua0(void(T::*function)(type0, type1))
+//! Executes a Function with a lua_State* parameter.
+template<class T, typename type0, typename type1> class ExecutorLua2 : public Executor
+{
+  public:
+    /**
+     * @brief Constructor of a ExecutorXML
+     * @param function a Function to call
+     */
+    ExecutorLua2(void(T::*function)(type0, type1))
         : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>())
     {
@@ -152,7 +161,8 @@
     }
 
-    virtual void operator()(BaseObject* object, unsigned int count, void* values) const
-    {
-      lua_state* state = (lua_state*)values;
+    virtual void operator()(BaseObject* object, int& count, void* values) const
+    {
+      lua_State* state = (lua_State*)values;
+      count = 0;
 
       (dynamic_cast<T*>(object)->*(functionPointer))(
@@ -166,9 +176,172 @@
     virtual Executor* clone () const
     {
-      return = new ExecutorLua0<T>(ExecutorLua0<T>(this->functionPointer));
-    }
-};
-
-
-
-#endif /* _EXECUTOR_SPECIALS_H */
+      return new ExecutorLua2<T, type0, type1>(this->functionPointer);
+    }
+  private:
+    void          (T::*functionPointer)(type0, type1);
+};
+
+
+
+
+
+
+
+////////////////////
+///// WITH RET /////
+////////////////////
+
+
+///////////
+//// 0 ////
+///////////
+//! Executes a Function with a lua_State* parameter.
+template<class T, typename ret> class ExecutorLua0ret : public Executor
+{
+  public:
+    /**
+     * @brief Constructor of a ExecutorXML
+     * @param function a Function to call
+     */
+    ExecutorLua0ret(ret (T::*function)())
+        : Executor()
+    {
+      this->functionPointer = function;
+      this->functorType = Executor_Objective | Executor_NoLoadString;
+    }
+
+    /**
+     * @brief executes the Command on BaseObject
+     * @param object the BaseObject to execute this Executor on
+     * @param loadString ignored in this case
+     */
+    virtual void operator()(BaseObject* object, const SubString& = SubString()) const
+    {
+      PRINTF(1)("no usefull executor\n");
+    }
+
+    virtual void operator()(BaseObject* object, int& count, void* values) const
+    {
+      lua_State* state = (lua_State*)values;
+      count = 1;
+
+      toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))());
+    }
+
+    /**
+                       * @returns a _new_ Copy of this Executor
+     */
+    virtual Executor* clone () const
+    {
+      return new ExecutorLua0ret<T, ret>(this->functionPointer);
+    }
+  private:
+    ret           (T::*functionPointer)();
+};
+
+
+
+///////////
+//// 1 ////
+///////////
+//! Executes a Function with a lua_State* parameter.
+template<class T, typename ret, typename type0> class ExecutorLua1ret : public Executor
+{
+  public:
+    /**
+     * @brief Constructor of a ExecutorXML
+     * @param function a Function to call
+     */
+    ExecutorLua1ret(ret (T::*function)(type0))
+        : Executor(ExecutorParamType<type0>())
+    {
+      this->functionPointer = function;
+      this->functorType = Executor_Objective | Executor_NoLoadString;
+    }
+
+    /**
+     * @brief executes the Command on BaseObject
+     * @param object the BaseObject to execute this Executor on
+     * @param loadString ignored in this case
+     */
+    virtual void operator()(BaseObject* object, const SubString& = SubString()) const
+    {
+      PRINTF(1)("no usefull executor\n");
+    }
+
+    virtual void operator()(BaseObject* object, int& count, void* values) const
+    {
+      lua_State* state = (lua_State*)values;
+      count = 1;
+
+      toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
+                   fromLua<type0>(state, 1)));
+    }
+
+    /**
+     * @returns a _new_ Copy of this Executor
+     */
+    virtual Executor* clone () const
+    {
+      return new ExecutorLua1ret<T, ret, type0>(this->functionPointer);
+    }
+  private:
+    ret           (T::*functionPointer)(type0);
+};
+
+///////////
+//// 2 ////
+///////////
+//! Executes a Function with a lua_State* parameter.
+template<class T, typename ret, typename type0, typename type1> class ExecutorLua2ret : public Executor
+{
+  public:
+    /**
+     * @brief Constructor of a ExecutorXML
+     * @param function a Function to call
+     */
+    ExecutorLua2ret(ret (T::*function)(type0, type1))
+        : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>())
+    {
+      this->functionPointer = function;
+      this->functorType = Executor_Objective | Executor_NoLoadString;
+    }
+
+    /**
+     * @brief executes the Command on BaseObject
+     * @param object the BaseObject to execute this Executor on
+     * @param loadString ignored in this case
+     */
+    virtual void operator()(BaseObject* object, const SubString& = SubString()) const
+    {
+      PRINTF(1)("no usefull executor\n");
+    }
+
+    virtual void operator()(BaseObject* object, int& count, void* values) const
+    {
+      lua_State* state = (lua_State*)values;
+      count = 1;
+
+      toLua<ret>(state, (dynamic_cast<T*>(object)->*(functionPointer))(
+                   fromLua<type0>(state, 1),
+                   fromLua<type1>(state, 2) ));
+    }
+
+    /**
+     * @returns a _new_ Copy of this Executor
+     */
+    virtual Executor* clone () const
+    {
+      return new ExecutorLua2ret<T, ret, type0, type1>(this->functionPointer);
+    }
+  private:
+    ret           (T::*functionPointer)(type0, type1);
+};
+
+
+
+
+
+
+
+#endif /* _EXECUTOR_LUA_H */
Index: trunk/src/lib/util/executor/executor_xml.h
===================================================================
--- trunk/src/lib/util/executor/executor_xml.h	(revision 8270)
+++ trunk/src/lib/util/executor/executor_xml.h	(revision 8271)
@@ -1,9 +1,9 @@
 /*!
- * @file executor.h
+ * @file executor_xml.h
  * Definition of a on-screen-shell
  */
 
-#ifndef _EXECUTOR_SPECIALS_H
-#define _EXECUTOR_SPECIALS_H
+#ifndef _EXECUTOR_XML_H
+#define _EXECUTOR_XML_H
 
 #include "executor.h"
@@ -65,5 +65,5 @@
     }
 
-    virtual void operator()(BaseObject* object, unsigned int count, void* values) const
+    virtual void operator()(BaseObject* object, int& count, void* values) const
     {
       PRINTF(1)("missuse of XML-operator, OR IMPLEMENT.\n");
@@ -82,3 +82,3 @@
 };
 
-#endif /* _EXECUTOR_SPECIALS_H */
+#endif /* _EXECUTOR_XML_H */
Index: trunk/src/lib/util/loading/resource.cc
===================================================================
--- trunk/src/lib/util/loading/resource.cc	(revision 8270)
+++ trunk/src/lib/util/loading/resource.cc	(revision 8271)
@@ -26,5 +26,5 @@
 Resource::Resource (const std::string& fileName)
 {
-   this->setClassID(CL_RESOURCE, "Resource");
+//   this->setClassID(CL_RESOURCE, "Resource");
 
 }
Index: trunk/src/story_entities/game_world.cc
===================================================================
--- trunk/src/story_entities/game_world.cc	(revision 8270)
+++ trunk/src/story_entities/game_world.cc	(revision 8271)
@@ -139,5 +139,6 @@
 }
 
-
+#include "account.cc"
+#include "object.cc"
 /**
  *  loads the GameWorld by initializing all resources, and set their default values.
@@ -181,4 +182,14 @@
   this->dataXML = (TiXmlElement*)root->Clone();
 
+
+  Object* obj= new Object();
+  obj->setName("Obj");
+  Account* a = new Account();
+  a->setName("a");
+  Account *b = new Account(30);
+  b->setName("b");
+  
+  LoadParamXML(root, "ScriptManager", &this->scriptManager, ScriptManager, loadParams);
+
   delete XMLDoc;
   this->releaseLoadScreen();
@@ -191,5 +202,8 @@
 ErrorMessage GameWorld::unloadData()
 {
+
   PRINTF(3)("GameWorld::~GameWorld() - unloading the current GameWorld\n");
+  this->scriptManager.flush();
+
   delete this->shell;
 
@@ -215,4 +229,6 @@
   this->bRunning = true;
 
+  State::setScripManager(&this->scriptManager);
+
   this->run();
 }
@@ -225,4 +241,5 @@
 {
   PRINTF(3)("GameWorld::stop() - got stop signal\n");
+  State::setScripManager(NULL);
   this->bRunning = false;
 }
Index: trunk/src/story_entities/game_world.h
===================================================================
--- trunk/src/story_entities/game_world.h	(revision 8270)
+++ trunk/src/story_entities/game_world.h	(revision 8271)
@@ -11,8 +11,10 @@
 #include "game_world_data.h"
 #include "playable.h"
+#include "script_manager.h"
 
 namespace OrxShell { class Shell; };
 class WorldEntity;
 class GameRules;
+
 
 /** How many frames time values to keep
@@ -103,7 +105,7 @@
     GameRules*          gameRules;                    //!< Pointer to the data structure containig the game rules
 
-
   private:
     /* external modules interfaces */
+    ScriptManager       scriptManager;
     OrxShell::Shell*    shell;
 };
Index: trunk/src/util/state.cc
===================================================================
--- trunk/src/util/state.cc	(revision 8270)
+++ trunk/src/util/state.cc	(revision 8271)
@@ -38,5 +38,5 @@
 
 ObjectManager* State::objectManager = NULL;
-
+ScriptManager* State::scriptManager = NULL;
 
 unsigned int State::resX = 1;
Index: trunk/src/util/state.h
===================================================================
--- trunk/src/util/state.h	(revision 8270)
+++ trunk/src/util/state.h	(revision 8271)
@@ -18,4 +18,6 @@
 class ObjectManager;
 class GameRules;
+
+class ScriptManager;
 
 
@@ -92,4 +94,11 @@
 
 
+
+  ////////////////////
+  /// SCRIP_ENGINE ///
+  ////////////////////
+  static void setScripManager(ScriptManager* scriptManager) { State::scriptManager = scriptManager; };
+  static ScriptManager* getScriptManager() { return State::scriptManager; };
+
   ////////////
   /// Menu ///
@@ -116,4 +125,7 @@
 
   static SkyBox*                skyBox;            //!< The SkyBox used in the current world.
+
+  static  ScriptManager*        scriptManager;     //!< The ScriptManager.
+
   static unsigned int           resX;              //!< The X Resolution of the screen.
   static unsigned int           resY;              //!< The Y Resolution of the screen.
Index: trunk/src/world_entities/WorldEntities.am
===================================================================
--- trunk/src/world_entities/WorldEntities.am	(revision 8270)
+++ trunk/src/world_entities/WorldEntities.am	(revision 8271)
@@ -51,5 +51,7 @@
                 world_entities/elements/text_element.cc \
                 \
-                world_entities/effects/lightning_bolt.cc
+                world_entities/effects/lightning_bolt.cc \
+                \
+                world_entities/script_trigger.cc
 
 
@@ -103,3 +105,5 @@
                 elements/text_element.h \
                 \
-                effects/lightning_bolt.h
+                effects/lightning_bolt.h \
+                \
+                script_trigger.h
Index: trunk/src/world_entities/script_trigger.cc
===================================================================
--- trunk/src/world_entities/script_trigger.cc	(revision 8271)
+++ trunk/src/world_entities/script_trigger.cc	(revision 8271)
@@ -0,0 +1,195 @@
+//for testing
+#include "luaincl.h"
+#include "script_trigger.h"
+#include "class_list.h"
+#include "script.h"
+
+#include "state.h"
+ 
+ 
+ 
+ScriptTrigger::ScriptTrigger(const TiXmlElement* root)
+{
+  scriptCalled = false;
+  scriptIsOk = false;
+  loadParams(root);
+
+
+}
+
+ScriptTrigger::~ScriptTrigger()
+{
+
+}
+
+void ScriptTrigger::loadParams(const TiXmlElement* root)
+{
+  if(root != NULL)
+  {
+    WorldEntity ::loadParams(root);
+
+    LoadParam(root, "file", this, ScriptTrigger, setScript)
+        .describe("the fileName of the script, that should be triggered by this script trigger")
+        .defaultValues("");
+    LoadParam(root, "function", this, ScriptTrigger, setFunction)
+        .describe("the function of the script, that should be triggered by this script trigger")
+        .defaultValues("");
+    LoadParam(root, "abs-coor", this, ScriptTrigger, setAbsCoor)
+        .describe("where this script trigger should be located")
+        .defaultValues("");
+    LoadParam(root, "radius", this, ScriptTrigger, setRadius)
+        .describe("the fileName of the script, that should be triggered by this script trigger")
+        .defaultValues(0);
+    LoadParam(root, "delay", this, ScriptTrigger, setDelay)
+        .describe("the delay after which the funtion sould be triggered")
+        .defaultValues(0);
+    LoadParam(root, "worldentity", this, ScriptTrigger, setTarget)
+        .describe("The name of the target as it is in the *.oxw file")
+        .defaultValues("");
+    LoadParam(root, "triggerparent", this, ScriptTrigger, setTriggerParent)
+        .describe("The name of the parent as it is in the *.oxw file")
+        .defaultValues("");
+    LoadParam(root, "callonce", this, ScriptTrigger, setCallOnce)
+        .describe("True if the script shoul only be called once")
+        .defaultValues("");
+  }
+
+}
+
+
+void ScriptTrigger::setTarget(const std::string& target)
+{
+  BaseObject* targetEntity = ClassList::getObject(target, CL_WORLD_ENTITY);
+
+  if (targetEntity != NULL)
+  {
+    this->setTarget(dynamic_cast<WorldEntity*>(targetEntity));
+  }
+  else
+  {
+    PRINTF(2)("Target %s for %s::%s does not Exist\n", target.c_str(), this->getClassName(), this->getName());
+  }
+}
+
+void ScriptTrigger::setTriggerParent(const std::string& parent)
+{
+  BaseObject* parentEntity = ClassList::getObject(parent, CL_WORLD_ENTITY);
+
+  if (parentEntity != NULL)
+  {
+    this->setParent(dynamic_cast<WorldEntity*>(parentEntity));
+    this->setParentMode(PNODE_MOVEMENT);
+  }
+  else
+  {
+    PRINTF(2)("Parent %s for %s::%s does not Exist\n", parent.c_str(), this->getClassName(), this->getName());
+  }
+}
+
+void ScriptTrigger::tick(float timestep)
+{
+  printf("SCRIPTTRIGGER: tick called\n");
+ if((this->getAbsDirV()-target->getAbsDirV()).len() < radius)
+ {
+  if(!callOnce)
+   {
+    executeAction();
+   }
+  else if(callOnce && !scriptCalled)
+  {
+   executeAction();
+   scriptCalled = true;
+  }
+ }
+
+}
+
+
+void ScriptTrigger::executeAction()
+{
+     if(scriptIsOk)
+     {
+       testScriptingFramework();
+     if(!(script->selectFunction(this->functionName,0)) )
+       printf("Error ScriptTrigger: Selection of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
+     if( !(script->executeFunction()) )
+       printf("Error ScriptTrigger: Execution of %s in %s failed.\n",functionName.c_str(), script->getFileName().c_str());
+     }
+}
+
+
+void ScriptTrigger::setScript(const std::string& file)
+{
+  ScriptManager* scriptManager = State::getScriptManager();
+  if (scriptManager != NULL)
+  {
+    script = scriptManager->getScriptByFile(file);
+    if(script != NULL)
+      scriptIsOk = true;
+  }
+}
+
+
+ void ScriptTrigger::testScriptingFramework()
+ {
+   std::string file("lunartest2.lua");
+     // Script script;
+   Script* script = State::getScriptManager()->getScriptByFile(file);
+   printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState()));
+
+      // Register classes with the script
+      // Lunar<Account>::Register(&script);
+      //Lunar<Object>::Register(&script);
+
+      //Object* obj= new Object();
+      //Account a;
+      //Account *b = new Account(30);
+
+      // Add instances to the script
+      //Lunar<Object>::insertObject(&script,obj,"Obj",true);
+      //Lunar<Account>::insertObject(&script,&a,"a",false);
+      //Lunar<Account>::insertObject(&script,b,"b",true);
+       //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
+
+      //Load a file
+      //std::string file("lunartest2.lua");
+
+      //if(script.loadFile(file))
+        //printf("File %s succefully loaded\n", file.c_str());
+      //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
+
+      //execute a function
+   printf("----------- main -----------\n");
+   std::string main("main");
+   if( script->selectFunction(main,3))
+     printf("function %s selected\n",main.c_str());
+
+   script->pushParam(3.14159,main);
+   script->executeFunction();
+
+   float retf = script->getReturnedFloat();
+   printf("main returned %f\n",retf);
+
+
+   if(script->getReturnedBool())
+     printf("main returned true\n");
+   else
+     printf("main returned false\n");
+
+   int ret = script->getReturnedInt();
+   printf("main returned %i\n",ret);
+
+      //printf("-------------------------- top of the stack:%i\n",lua_gettop(script.getLuaState()));
+      //execute a 2nd function
+   printf("----------- test -----------\n");
+   std::string test("test");
+   if( script->selectFunction(test,0))
+     printf("function %s selected\n",test.c_str());
+
+   script->executeFunction();
+
+
+      //if(argc>1) lua_dofile(script.getLuaState(), argv[1]);
+   printf("-------------------------- top of the stack:%i\n",lua_gettop(script->getLuaState()));
+
+ }
Index: trunk/src/world_entities/script_trigger.h
===================================================================
--- trunk/src/world_entities/script_trigger.h	(revision 8271)
+++ trunk/src/world_entities/script_trigger.h	(revision 8271)
@@ -0,0 +1,55 @@
+#ifndef _SCRIPT_TRIGGER_H
+#define _SCRIPT_TRIGGER_H
+
+#include <string>
+
+#include "world_entity.h"
+#include "loading/load_param.h"
+#include "vector.h"
+#include "script_manager.h"
+#include "script.h"
+
+class ScriptTrigger : public WorldEntity
+{
+  public:
+    ScriptTrigger(const TiXmlElement* root = NULL);
+    ~ScriptTrigger();
+
+    ///LOADING
+    virtual void loadParams(const TiXmlElement* root);
+
+
+    /// DO WORK
+    virtual void tick(float timestep);
+    virtual void executeAction();
+    void testScriptingFramework();
+
+    /// SET MEMBER
+    void setTarget(const std::string& targetName);
+    void setTarget(WorldEntity* target) { if(target!=NULL) this->target=target; }
+    void setTriggerParent(const std::string& name);
+    void setCallOnce(const bool call) { this->callOnce = call; }
+    void setRadius(const float radius) { if(radius>0) this->radius = radius; }
+    void setDelay(const float time){if(delay>0) this->delay = delay; }
+    void setScript(const std::string& file);
+    void setFunction(const std::string& function){ this->functionName = function; }
+    
+    ///DRAWING
+    void draw()const{this->debugDraw();};
+
+  private:
+
+    WorldEntity* target;
+    bool         callOnce;
+    float        radius;
+    float        delay;
+    Script*      script;
+    std::string  functionName;
+
+    //for internal use
+    bool         scriptCalled;
+    bool         scriptIsOk;
+
+};
+
+#endif
