Index: anches/script_engine/src/lib/script_engine/LuaCallback.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/LuaCallback.cc	(revision 7687)
+++ 	(revision )
@@ -1,116 +1,0 @@
-/*
-   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: Silvan Nellen
-   co-programmer: ...
-*/
-
-//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
-
-#include "Script.h"
-#include "LuaCallback.h"
-#include "luaincl.h"
-#include "scriptable.h"
-
-#include <cassert>
-#include <string>
-#include <iostream>
-#include <stdio.h>
-
-namespace OrxScript
-{
-
-  /**
-   * @brief This function accually executes a method called by Lua.
-   * @param lua Since this function gets called by lua it has to have a lua_State as parameter
-   * @return the number of return values. (which can be found on the stack)
-   *
-   * For Lua doesn't know how to handle C++ objects it pushes the Objecttable (including the objectpointer) on top of the stack and
-   * calls this function.
-   *
-   * @todo handle an acces to a nonexistent (deleted) object
-   */
-  int luaCallback (lua_State *lua)
-  {
-
-    // Locate the psudo-index for the function number
-    int methodNumber = lua_upvalueindex (1);
-    int returnCount = 0;
-
-    bool functionSuccess = false;
-
-    // Check for the "this" table
-    if (lua_istable (lua, 1))
-    {
-      // Found the "this" table. The object pointer is at the index 0
-      lua_rawgeti (lua, 1, 0);
-
-      if (lua_islightuserdata (lua, -1))
-      {
-        // Found the pointer, need to cast it
-        Scriptable* thisPointer = (Scriptable*) lua_touserdata (lua, -1);
-
-        // Get the method index
-        int methodIndex = (int) lua_tonumber (lua, methodNumber);
-
-        // Reformat the stack so our parameters are correct
-        // Clean up the "this" table
-        lua_remove (lua, 1);
-        // Clean up the thisPointer pointer
-        lua_remove (lua, -1);
-
-        //debug
-        //std::cout<<thisPointer->whatIsThis()<<std::endl;
-
-        LuaScript* originScript = NULL;
-
-        lua_getglobal (lua, "this");
-
-        if (lua_istable (lua, 1))
-        {
-          // Found the "this" table. The object pointer is at the index 0
-          lua_rawgeti (lua, 1, 0);
-
-          if (lua_islightuserdata (lua, -1))
-          {
-            // Found the pointer, need to cast it
-            originScript = (LuaScript *) lua_touserdata (lua, -1);
-          }
-        }
-
-        if(originScript == NULL)
-        {//do something usefull
-        }
-        //debug
-        // std::cout<<originScript->whatIsThis()<<std::endl;
-
-        LuaVirtualMachine virtualMachine = originScript->getVirtualMachine();
-        //debug
-        //std::cout<<"test "<< thisPointer->methods(virtualMachine)<<std::endl;
-        // Check that the method is correct index
-        assert ((methodIndex <= thisPointer->methods(virtualMachine) ));
-        // Call the class
-        returnCount = thisPointer->scriptCalling ( virtualMachine, thisPointer->getFunctionAtIndex(methodIndex,virtualMachine));
-
-        functionSuccess = true;
-      }
-    }
-
-    if (functionSuccess == false)
-    {
-      lua_pushstring (lua, "luaCallback -> Failed to call the class function");
-      lua_error (lua);
-    }
-
-    // Number of return variables
-    return returnCount;
-  }
-}
Index: anches/script_engine/src/lib/script_engine/LuaCallback.h
===================================================================
--- /branches/script_engine/src/lib/script_engine/LuaCallback.h	(revision 7687)
+++ 	(revision )
@@ -1,11 +1,0 @@
-#ifndef __LUA_CALLBACK_H__
-#define __LUA_CALLBACK_H__
-
-struct lua_State;
-
-namespace OrxScript
-{
-  class LuaVirtualMachine;
-  int luaCallback (lua_State *lua);
-}
-#endif /* __LUA_CALLBACK_H__*/
Index: /branches/script_engine/src/lib/script_engine/Makefile.am
===================================================================
--- /branches/script_engine/src/lib/script_engine/Makefile.am	(revision 7687)
+++ /branches/script_engine/src/lib/script_engine/Makefile.am	(revision 7688)
@@ -2,7 +2,7 @@
 INCLUDES= -I../../../extern_libs
 
-noinst_LIBRARIES = libORXscript.a
+#noinst_LIBRARIES = libORXscript.a
 
-libORXscript_a_SOURCES = \
+#libORXscript_a_SOURCES = \
 		LuaCallback.cc \
 		RestoreStack.cc \
@@ -14,13 +14,13 @@
 AM_CPPFLAGS= @LUA_INCLUDES@
 
-bin_PROGRAMS = main
-main_SOURCES = \
+#bin_PROGRAMS = main
+#main_SOURCES = \
 		main.cc
-main_LDADD = libORXscript.a -L../../../extern_libs @LUA_LIBS@
+#main_LDADD = libORXscript.a -L../../../extern_libs @LUA_LIBS@
 
-main_LDFLAGS =
+#main_LDFLAGS =
 
 
-noinst_HEADERS = \
+#noinst_HEADERS = \
 		LuaCallback.h \
 		RestoreStack.h \
Index: /branches/script_engine/src/lib/script_engine/OLD/LuaCallback.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/OLD/LuaCallback.cc	(revision 7688)
+++ /branches/script_engine/src/lib/script_engine/OLD/LuaCallback.cc	(revision 7688)
@@ -0,0 +1,116 @@
+/*
+   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: Silvan Nellen
+   co-programmer: ...
+*/
+
+//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
+
+#include "Script.h"
+#include "LuaCallback.h"
+#include "luaincl.h"
+#include "scriptable.h"
+
+#include <cassert>
+#include <string>
+#include <iostream>
+#include <stdio.h>
+
+namespace OrxScript
+{
+
+  /**
+   * @brief This function accually executes a method called by Lua.
+   * @param lua Since this function gets called by lua it has to have a lua_State as parameter
+   * @return the number of return values. (which can be found on the stack)
+   *
+   * For Lua doesn't know how to handle C++ objects it pushes the Objecttable (including the objectpointer) on top of the stack and
+   * calls this function.
+   *
+   * @todo handle an acces to a nonexistent (deleted) object
+   */
+  int luaCallback (lua_State *lua)
+  {
+
+    // Locate the psudo-index for the function number
+    int methodNumber = lua_upvalueindex (1);
+    int returnCount = 0;
+
+    bool functionSuccess = false;
+
+    // Check for the "this" table
+    if (lua_istable (lua, 1))
+    {
+      // Found the "this" table. The object pointer is at the index 0
+      lua_rawgeti (lua, 1, 0);
+
+      if (lua_islightuserdata (lua, -1))
+      {
+        // Found the pointer, need to cast it
+        Scriptable* thisPointer = (Scriptable*) lua_touserdata (lua, -1);
+
+        // Get the method index
+        int methodIndex = (int) lua_tonumber (lua, methodNumber);
+
+        // Reformat the stack so our parameters are correct
+        // Clean up the "this" table
+        lua_remove (lua, 1);
+        // Clean up the thisPointer pointer
+        lua_remove (lua, -1);
+
+        //debug
+        //std::cout<<thisPointer->whatIsThis()<<std::endl;
+
+        LuaScript* originScript = NULL;
+
+        lua_getglobal (lua, "this");
+
+        if (lua_istable (lua, 1))
+        {
+          // Found the "this" table. The object pointer is at the index 0
+          lua_rawgeti (lua, 1, 0);
+
+          if (lua_islightuserdata (lua, -1))
+          {
+            // Found the pointer, need to cast it
+            originScript = (LuaScript *) lua_touserdata (lua, -1);
+          }
+        }
+
+        if(originScript == NULL)
+        {//do something usefull
+        }
+        //debug
+        // std::cout<<originScript->whatIsThis()<<std::endl;
+
+        LuaVirtualMachine virtualMachine = originScript->getVirtualMachine();
+        //debug
+        //std::cout<<"test "<< thisPointer->methods(virtualMachine)<<std::endl;
+        // Check that the method is correct index
+        assert ((methodIndex <= thisPointer->methods(virtualMachine) ));
+        // Call the class
+        returnCount = thisPointer->scriptCalling ( virtualMachine, thisPointer->getFunctionAtIndex(methodIndex,virtualMachine));
+
+        functionSuccess = true;
+      }
+    }
+
+    if (functionSuccess == false)
+    {
+      lua_pushstring (lua, "luaCallback -> Failed to call the class function");
+      lua_error (lua);
+    }
+
+    // Number of return variables
+    return returnCount;
+  }
+}
Index: /branches/script_engine/src/lib/script_engine/OLD/LuaCallback.h
===================================================================
--- /branches/script_engine/src/lib/script_engine/OLD/LuaCallback.h	(revision 7688)
+++ /branches/script_engine/src/lib/script_engine/OLD/LuaCallback.h	(revision 7688)
@@ -0,0 +1,11 @@
+#ifndef __LUA_CALLBACK_H__
+#define __LUA_CALLBACK_H__
+
+struct lua_State;
+
+namespace OrxScript
+{
+  class LuaVirtualMachine;
+  int luaCallback (lua_State *lua);
+}
+#endif /* __LUA_CALLBACK_H__*/
Index: /branches/script_engine/src/lib/script_engine/OLD/RestoreStack.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/OLD/RestoreStack.cc	(revision 7688)
+++ /branches/script_engine/src/lib/script_engine/OLD/RestoreStack.cc	(revision 7688)
@@ -0,0 +1,46 @@
+/*
+   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 "RestoreStack.h"
+#include "luaincl.h"
+
+namespace OrxScript
+{
+
+  /**
+   * @brief Stores the stack and the index to the top element
+   *
+   * @param virtualMachine the virtual machine to save
+   */
+  LuaRestoreStack::LuaRestoreStack (LuaVirtualMachine& virtualMachine) : savedState (NULL)
+  {
+    savedState = (lua_State *) virtualMachine;
+    if (virtualMachine.isOk ())
+    {
+      savedTopIndex = lua_gettop (savedState);
+    }
+  }
+  /**
+  * @brief Restores the virtual machine
+  *
+  *
+  */
+  LuaRestoreStack::~LuaRestoreStack ()
+  {
+    lua_settop (savedState, savedTopIndex);
+  }
+}
Index: /branches/script_engine/src/lib/script_engine/OLD/RestoreStack.h
===================================================================
--- /branches/script_engine/src/lib/script_engine/OLD/RestoreStack.h	(revision 7688)
+++ /branches/script_engine/src/lib/script_engine/OLD/RestoreStack.h	(revision 7688)
@@ -0,0 +1,31 @@
+#ifndef __RESTORE_STACK_H__
+#define __RESTORE_STACK_H__
+
+
+#include "VirtualMachine.h"
+/// Forward declaration
+struct lua_State;
+
+namespace OrxScript
+{
+
+  //! Class to restore the stack to the way we found it.
+  class LuaRestoreStack
+  {
+  public:
+    /**
+     * @brief Stores the stack and the index to the top element
+     *
+     * @param virtualMachine the virtual machine to save
+     */
+    LuaRestoreStack (LuaVirtualMachine& virtualMachine);
+    virtual ~LuaRestoreStack (void);
+
+  protected:
+    lua_State* savedState;
+    int savedTopIndex;
+  };
+
+}
+
+#endif // __RESTORE_STACK_H__
Index: /branches/script_engine/src/lib/script_engine/OLD/Script.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/OLD/Script.cc	(revision 7688)
+++ /branches/script_engine/src/lib/script_engine/OLD/Script.cc	(revision 7688)
@@ -0,0 +1,491 @@
+#include <cassert>
+#include <string>
+#include <iostream>
+#include "luaincl.h"
+
+#include "Script.h"
+#include "RestoreStack.h"
+#include "This.h"
+#include "LuaCallback.h"
+
+// ---------------------------------------------------------------------------
+
+namespace OrxScript
+{
+
+#define BEGIN_LUA_CHECK(vm)   lua_State *state = (lua_State *) vm; \
+                              if (vm.isOk ()) {
+#define END_LUA_CHECK         }
+
+
+  /**
+   * @brief Constructor. Sets up the lua stack and the "this" table
+   *
+   *
+   *
+   */
+
+  LuaScript::LuaScript ()
+      : methodCount (0) , argumentCount (0), functionName()
+  {
+    virtualMachine.init();
+    lua_State *state = (lua_State *) virtualMachine;
+
+    if (virtualMachine.isOk ())
+    {
+      // Create a reference to the "this" table. Each reference is unique
+      lua_newtable (state);
+      thisReference = luaL_ref (state, LUA_REGISTRYINDEX);
+
+      // Save the "this" table to index 0 of the "this" table
+      LuaRestoreStack rs (virtualMachine);
+      lua_rawgeti (state, LUA_REGISTRYINDEX, thisReference);
+      lua_pushlightuserdata (state, (void *) this);
+      lua_rawseti (state, -2, 0);
+    }
+
+  }
+
+
+  /**
+   * @brief Deconstructor
+   *
+   */
+
+  LuaScript::~LuaScript (void)
+  {
+    LuaRestoreStack rs (virtualMachine);
+
+    BEGIN_LUA_CHECK (virtualMachine)
+    // Get the reference "this" table
+    lua_rawgeti (state, LUA_REGISTRYINDEX, thisReference);
+
+    // Clear index 0
+    lua_pushnil (state);
+    lua_rawseti (state, -2, 0);
+    END_LUA_CHECK
+
+  }
+
+
+
+  /**
+   * @brief Compiles a given buffer. (reads it into the lua stack)
+   * @param pbBuffer buffer to compile
+   * @param size_t length of the buffer
+   *
+   * @return true if it succeeded
+   */
+
+  bool LuaScript::compileBuffer (unsigned char *pbBuffer, size_t szLen)
+  {
+    assert (pbBuffer != NULL && "LuaScript::compileBuffer ->  pbBuffer == NULL");
+    assert (szLen != 0 && "LuaScript::compileBuffer -> szLen == 0");
+    assert (virtualMachine.isOk () && "VM Not OK");
+
+    // Make sure we have the correct "this" table
+    LuaThis luaThis (virtualMachine, thisReference);
+
+    return virtualMachine.runBuffer (pbBuffer, szLen);
+  }
+
+
+  /**
+   * @brief Compiles a given file. (reads it into the lua stack)
+   * @param strFilename filename
+   *
+   * @return true if it succeeded
+   */
+
+  bool LuaScript::compileFile (const std::string& strFilename)
+  {
+    //assert (strFilename != NULL && "LuaScript::compileFile -> strFilename == NULL");
+    assert (virtualMachine.isOk () && "VM Not OK");
+
+    // Make sure we have the correct "this" table
+    LuaThis luaThis (virtualMachine, thisReference);
+
+    return virtualMachine.runFile (strFilename);
+  }
+
+
+  /**
+   * @brief Registers a function with Lua, the function will be registered in the "this" table
+   * @param strFuncName name of the function by which it goes by in lua
+   *
+   * @return the pseudoindex of the function
+   */
+
+  int LuaScript::registerFunction (const std::string& strFuncName)
+  {
+    //  assert (strFuncName != NULL && "LuaScript::registerFunction -> strFuncName == NULL");
+    assert (virtualMachine.isOk () && "VM Not OK");
+
+    int iMethodIdx = -1;
+
+    LuaRestoreStack rs (virtualMachine);
+
+    BEGIN_LUA_CHECK (virtualMachine)
+    iMethodIdx = ++methodCount;
+
+    // Register a function with the lua script. Added it to the "this" table
+    lua_rawgeti (state, LUA_REGISTRYINDEX, thisReference);
+
+    // Push the function and parameters
+    lua_pushstring (state, strFuncName.c_str());
+    lua_pushnumber (state, (lua_Number) iMethodIdx);
+    lua_pushcclosure (state, luaCallback, 1);
+    lua_settable (state, -3);
+
+    END_LUA_CHECK
+
+    return iMethodIdx;
+  }
+
+
+  /**
+   * @brief Selects a script function to run
+   * @param  strFuncName name of the function to run
+   *
+   * @return true on success
+   */
+  bool LuaScript::selectScriptFunction (const std::string& strFuncName)
+  {
+    //  assert (strFuncName != NULL && "LuaScript::selectScriptFunction -> strFuncName == NULL");
+    assert (virtualMachine.isOk () && "VM Not OK");
+
+    bool fSuccess = true;
+
+    BEGIN_LUA_CHECK (virtualMachine)
+    // Look up function name
+    lua_rawgeti (state, LUA_REGISTRYINDEX, thisReference);
+    lua_pushstring (state, strFuncName.c_str());
+    lua_rawget (state, -2);
+    lua_remove (state, -2);
+
+    // Put the "this" table back
+    lua_rawgeti (state, LUA_REGISTRYINDEX, thisReference);
+
+    // Check that we have a valid function
+    if (!lua_isfunction (state, -2))
+    {
+      fSuccess = false;
+      lua_pop (state, 2);
+    }
+    else
+    {
+      argumentCount = 0;
+      functionName = strFuncName;
+    }
+    END_LUA_CHECK
+
+    return fSuccess;
+  }
+
+
+  /**
+   * @brief Checks to see if a function exists
+   * @param  functionName  Function name
+   *
+   * @return true if the function exists
+   */
+  bool LuaScript::scriptHasFunction (const std::string& functionName)
+  {
+    // printf("entered scriptHasFunction\n");
+
+    //  assert (strScriptName != NULL && "LuaScript::scriptHasFunction -> strScriptName == NULL");
+    assert (virtualMachine.isOk () && "VM Not OK");
+
+    // printf("assertions passed\n");
+
+    LuaRestoreStack rs (virtualMachine);
+
+    bool fFoundFunc = false;
+
+    BEGIN_LUA_CHECK (virtualMachine)
+    lua_rawgeti (state, LUA_REGISTRYINDEX, thisReference);
+    lua_pushstring (state, functionName.c_str());
+    lua_rawget (state, -2);
+    lua_remove (state, -2);
+
+    if (lua_isfunction (state, -1))
+    {
+      fFoundFunc = true;
+    }
+    END_LUA_CHECK
+
+    return fFoundFunc;
+
+  }
+
+
+  /**
+   * @brief Adds a parameter to the parameter list
+   * @param  string  string to be added as parameter for a function.
+   *
+   */
+
+  void LuaScript::addParam (const std::string& string)
+  {
+    assert (virtualMachine.isOk () && "VM Not OK");
+
+    BEGIN_LUA_CHECK (virtualMachine);
+    lua_pushstring (state, string.c_str());
+    ++argumentCount;
+    END_LUA_CHECK;
+  }
+
+
+  /**
+   * @brief Adds a parameter to the parameter list
+   * @param  iInt  integer to be added as parameter for a function.
+   *
+   */
+
+  void LuaScript::addParam (int iInt)
+  {
+    assert (virtualMachine.isOk () && "VM Not OK");
+
+    BEGIN_LUA_CHECK (virtualMachine)
+    lua_pushnumber (state, (lua_Number) iInt);
+    ++argumentCount;
+    END_LUA_CHECK
+  }
+
+
+  /**
+   * @brief Adds a parameter to the parameter list
+   * @param  fFloat  float to be added as parameter for a function.
+   *
+   */
+  void LuaScript::addParam (float fFloat)
+  {
+    assert (virtualMachine.isOk () && "VM Not OK");
+
+    BEGIN_LUA_CHECK (virtualMachine)
+    lua_pushnumber (state, (lua_Number) fFloat);
+    ++argumentCount;
+    END_LUA_CHECK
+  }
+
+
+  /**
+   * @brief Runs the selected script function
+   * @param  nReturns the count of return values
+   *
+   * @return true on success
+   */
+  bool LuaScript::run (int nReturns /* = 0 */)
+  {
+    assert (virtualMachine.isOk () && "VM Not OK");
+
+    // At this point there should be a parameters and a function on the
+    // Lua stack. Each function get a "this" parameter as default and is
+    // pushed onto the stack when the method is selected
+
+    bool fSuccess = virtualMachine.callFunction (argumentCount + 1, nReturns);
+
+    if (fSuccess == true && nReturns > 0)
+    {
+      // Check for returns
+      handleReturns (virtualMachine, functionName);
+      lua_pop ((lua_State *) virtualMachine, nReturns);
+    }
+
+    return fSuccess;
+  }
+
+
+  /**
+   * @brief This function adds an object to a script so that the object is accessable from within the luascript.
+   *
+   * @param scriptable the scriptable object to add.
+   * @param strObjName the name that the object goes by in the script.
+   * @param luaScript  the script to which the scrtiptable is added
+   *
+   * @return a lua reference to the added object
+   *
+   *
+   *
+   */
+
+  int LuaScript::addScriptableToScript(Scriptable* scriptable, const std::string& strObjName)
+  {
+
+    lua_State *state = (lua_State *) (this->virtualMachine);
+
+    if(strObjName.compare(std::string("this")) != 0)
+    {
+      if (virtualMachine.isOk ())
+      {
+        /*create object table*/
+        // Create a reference to the "object" table and set a name for the reference. Each reference is unique
+
+        lua_newtable (state);
+        int  objRef = luaL_ref (state, LUA_REGISTRYINDEX);
+        lua_rawgeti (state, LUA_REGISTRYINDEX, objRef);
+        lua_setglobal (state, strObjName.c_str());
+
+
+        // Save the "object" table to index 0 of the "object" table
+        LuaRestoreStack rs(virtualMachine);
+        lua_rawgeti (state, LUA_REGISTRYINDEX, objRef);
+        lua_pushlightuserdata (state, scriptable);
+        lua_rawseti (state, -2, 0);
+
+        if(! addScriptableToList(scriptable,objRef))
+          std::cout<<"scriptable not added"<<std::endl;
+        if(!(scriptable->scriptableAdded(this,thisReference,objRef)))
+          std::cout<<"scriptableAdded returned false"<<std::endl;
+
+        return objRef;
+      }
+    }
+
+    return -1;
+
+  }
+
+
+
+  /**
+   * @brief Add the function to a scriptable in the Script
+   * @param strFuncName name of the function by which it goes by in lua
+   * @param toScriptable reference to the scriptable the function should be associated with
+   * @param methodIndex index of the last function.
+   *
+   * @return the pseudoindex of the function, -1 on failure
+   */
+
+  int LuaScript::addFunctionToScriptable(const std::string& strFuncName, int toScriptable, int lastMethodIndex)
+  {
+    //  assert (strFuncName != NULL && "LuaScript::registerFunction -> strFuncName == NULL");
+    assert (virtualMachine.isOk () && "VM Not OK");
+
+
+    //get the last method index from the Script
+    Scriptable* scriptable = getScriptableByReference(toScriptable);
+    int iMethodIdx = -1;
+
+    if(scriptable)
+    {
+      LuaRestoreStack rs (virtualMachine);
+
+      BEGIN_LUA_CHECK (virtualMachine)
+      // Register a function with the lua script. Added it to the "toScrtiptable" table
+      lua_rawgeti (state, LUA_REGISTRYINDEX, toScriptable);
+
+      if (lua_istable (state, 1))
+      {
+        iMethodIdx = ++lastMethodIndex;
+
+        // Push the function and parameters
+        lua_pushstring (state, strFuncName.c_str());
+        lua_pushnumber (state, (lua_Number) iMethodIdx);
+        lua_pushcclosure (state, luaCallback, 1);
+        lua_settable (state, -3);
+      }
+      END_LUA_CHECK
+
+    }
+    return iMethodIdx;
+  }
+
+
+  Scriptable* LuaScript::getScriptableByReference(int scrptblRef)
+  {
+
+    bool notFound = true;
+    std::list<Scrptbl>::iterator it = scriptableList.begin();
+
+    while(notFound && it != scriptableList.end() )
+    {
+      if((*it).scriptableRef == scrptblRef)
+      {
+        notFound = false;
+        return (*it).scriptable;
+      }
+      it++;
+    }
+
+
+    if(notFound)
+      return NULL;
+
+  }
+
+  int LuaScript::getReferenceByScriptable(Scriptable* scrptbl)
+  {
+    bool notFound = true;
+
+    std::list<Scrptbl>::iterator it = scriptableList.begin();
+
+    while(notFound && it != scriptableList.end() )
+    {
+      if((*it).scriptable == scrptbl)
+      {
+        notFound = false;
+        return (*it).scriptableRef;
+      }
+      it++;
+    }
+    if(notFound)
+      return -1;
+  }
+
+  bool LuaScript::addScriptableToList(Scriptable* scrptbl, int scriptableRef)
+  {
+    if(scrptbl)
+    {
+      if(getReferenceByScriptable(scrptbl) == -1) // Script isn't there yet
+      {
+        Scrptbl scriptableTmp;
+        scriptableTmp.scriptable = scrptbl;
+        scriptableTmp.scriptableRef = scriptableRef;
+        scriptableList.push_back(scriptableTmp);
+        return true;
+      }
+    }
+
+    return false;
+
+  }
+
+  bool LuaScript::removeScriptableFromList(Scriptable* toRemove)
+  {
+    if(toRemove)
+    {
+      int scrptbl = getReferenceByScriptable(toRemove);
+
+      if(scrptbl != -1)// if the scriptable is on the list
+      {
+        std::list<Scrptbl>::iterator it = scriptableList.begin();
+
+        while((*it).scriptable != toRemove && it != scriptableList.end() )
+        {
+          it++;
+        }
+
+        if(it != scriptableList.end())
+        {
+          scriptableList.erase(it);
+          return true;
+        }
+      }
+    }
+    return false;
+  }
+
+  bool LuaScript::removeScriptableFromList(int scriptable)
+  {
+    return removeScriptableFromList(getScriptableByReference(scriptable));
+  }
+
+
+  char LuaScript::whatIsThis()
+  {
+    char result = 'l';
+    return result;
+  }
+}
+
Index: /branches/script_engine/src/lib/script_engine/OLD/Script.h
===================================================================
--- /branches/script_engine/src/lib/script_engine/OLD/Script.h	(revision 7688)
+++ /branches/script_engine/src/lib/script_engine/OLD/Script.h	(revision 7688)
@@ -0,0 +1,92 @@
+#ifndef __LUA_SCRIPT_BASE_H__
+#define __LUA_SCRIPT_BASE_H__
+
+#include <string>
+
+#include "VirtualMachine.h"
+#include "scriptable.h"
+
+namespace OrxScript
+{
+
+  struct Scrptbl
+  {
+    Scriptable* scriptable;
+    int scriptableRef;
+  };
+
+  class LuaScript
+  {
+  public:
+    LuaScript ();
+    virtual ~LuaScript (void);
+
+
+    void init(LuaVirtualMachine& vm);
+
+    /* ------------------ Script related Functions ------------------ */
+
+    // Compile script into Virtual Machine
+    bool compileFile (const std::string& strFilename);
+    bool compileBuffer (unsigned char *pbBuffer, size_t szLen);
+
+    // Register function with Lua in the this table
+    int registerFunction (const std::string& strFuncName);
+
+
+    // Selects a Lua Script function to call
+    bool selectScriptFunction (const std::string& strFuncName);
+    void addParam (int iInt);
+    void addParam (float fFloat);
+    void addParam (const std::string& string);
+
+    // Runs the loaded script
+    bool run (int nReturns = 0);
+
+    // Checks on Virtual Machine script
+    bool scriptHasFunction (const std::string& strScriptName);
+
+    // Method indexing check
+    int methods (void) { return methodCount; }
+
+
+    // When the script calls a class method, this is called
+    virtual int scriptCalling (LuaVirtualMachine& vm, int iFunctionNumber) = 0;
+
+    // When the script function has returns
+    virtual void handleReturns (LuaVirtualMachine& vm, const std::string& strFunc) = 0;
+
+
+
+    /* ------------------- Handle external Objects ------------------ */
+
+    void removeFromScript(int referenceToScriptable) {}
+    int addScriptableToScript(Scriptable* scriptbl,const std::string& name);  // name= name the scriptable goes by in lua
+    int addFunctionToScriptable(const std::string& strFuncName, int toScriptable, int lastMethodIndex);
+
+    //Handle the Scriptable List
+    Scriptable* getScriptableByReference(int scrptblRef);
+    int getReferenceByScriptable(Scriptable* scriptable);
+    bool addScriptableToList(Scriptable* scriptbl, int scriptableRef);
+    bool removeScriptableFromList(Scriptable* scriptable);
+    bool removeScriptableFromList(int scriptable);
+
+
+
+    /* ------------------ ... ------------------ */
+
+    LuaVirtualMachine& getVirtualMachine (void) { return virtualMachine; }
+    char whatIsThis();
+
+  protected:
+    int methodCount;
+    LuaVirtualMachine virtualMachine;
+    int thisReference;
+    int argumentCount;
+    std::string functionName;
+    std::list<Scrptbl> scriptableList;
+  };
+
+}
+
+#endif // __LUA_SCRIPT_BASE_H__
Index: /branches/script_engine/src/lib/script_engine/OLD/This.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/OLD/This.cc	(revision 7688)
+++ /branches/script_engine/src/lib/script_engine/OLD/This.cc	(revision 7688)
@@ -0,0 +1,49 @@
+/*
+   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: Silvan Nellen
+   co-programmer: ...
+*/
+
+//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
+
+#include "This.h"
+#include "luaincl.h"
+
+namespace OrxScript
+{
+  LuaThis::LuaThis (LuaVirtualMachine& vm, int iRef) : oldReference (0), virtualMachine (vm)
+  {
+    lua_State *state = (lua_State *) vm;
+    if (vm.isOk ())
+    {
+      // Save the old "this" table
+      lua_getglobal (state, "this");
+      oldReference = luaL_ref (state, LUA_REGISTRYINDEX);
+
+      // replace it with our new one
+      lua_rawgeti(state, LUA_REGISTRYINDEX, iRef);
+      lua_setglobal (state, "this");
+    }
+  }
+
+  LuaThis::~LuaThis (void)
+  {
+    lua_State *state = (lua_State *) virtualMachine;
+    if (oldReference > 0 && virtualMachine.isOk ())
+    {
+      // Replace the old "this" table
+      lua_rawgeti(state, LUA_REGISTRYINDEX, oldReference);
+      lua_setglobal (state, "this");
+      luaL_unref (state, LUA_REGISTRYINDEX, oldReference);
+    }
+  }
+}
Index: /branches/script_engine/src/lib/script_engine/OLD/This.h
===================================================================
--- /branches/script_engine/src/lib/script_engine/OLD/This.h	(revision 7688)
+++ /branches/script_engine/src/lib/script_engine/OLD/This.h	(revision 7688)
@@ -0,0 +1,21 @@
+#ifndef __THIS_H__
+#define __THIS_H__
+
+#include "VirtualMachine.h"
+
+// Sets the "this" global table that scripts use
+namespace OrxScript
+{
+
+  class LuaThis
+  {
+  public:
+    LuaThis (LuaVirtualMachine& vm, int iRef);
+    virtual ~LuaThis (void);
+
+  protected:
+    int oldReference;
+    LuaVirtualMachine& virtualMachine;
+  };
+}
+#endif // __THIS_H__
Index: /branches/script_engine/src/lib/script_engine/OLD/VirtualMachine.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/OLD/VirtualMachine.cc	(revision 7688)
+++ /branches/script_engine/src/lib/script_engine/OLD/VirtualMachine.cc	(revision 7688)
@@ -0,0 +1,291 @@
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "luaincl.h"
+#include "VirtualMachine.h"
+namespace OrxScript
+{
+  // ---------------------------------------------------------------------------
+
+
+  //============================================================================
+  // int printMessage
+  //---------------------------------------------------------------------------
+  // Prints a message to the console
+  //
+  // Parameter   Dir      Description
+  // ---------   ---      -----------
+  // lua         IN       State variable
+  //
+  // Return
+  // ------
+  // Number of return varaibles on the stack
+  //
+  //============================================================================
+  static int printMessage (lua_State *lua)
+  {
+    assert (lua_isstring (lua,1));
+
+    const char *msg = lua_tostring (lua, 1);
+
+    // get caller
+    lua_Debug ar;
+    memset (&ar, 0, sizeof(ar));
+    lua_getstack (lua, 1, &ar);
+    lua_getinfo (lua, "Snl", &ar);
+
+    // debug output
+    const char *str = ar.source;
+    printf ("script: %s -- at %s(%d)\n", msg, str, ar.currentline);
+    return 0;
+  }
+
+  //============================================================================
+  // LuaVirtualMachine::LuaVirtualMachine
+  //---------------------------------------------------------------------------
+  // Constructor. Setups the default VM state
+  //
+  // Parameter   Dir      Description
+  // ---------   ---      -----------
+  //
+  //
+  // Return
+  // ------
+  // None.
+  //
+  //============================================================================
+  LuaVirtualMachine::LuaVirtualMachine (void) : luaState (NULL)
+  {
+    machineIsOk = false;
+  }
+
+  //============================================================================
+  // LuaVirtualMachine::LuaVirtualMachine
+  //---------------------------------------------------------------------------
+  // Destructor. Closes the VM
+  //
+  // Parameter   Dir      Description
+  // ---------   ---      -----------
+  //
+  //
+  // Return
+  // ------
+  // None.
+  //
+  //============================================================================
+  LuaVirtualMachine::~LuaVirtualMachine (void)
+  {
+    if (luaState != NULL)
+    {
+      lua_close (luaState);
+    }
+  }
+
+  //============================================================================
+  // LuaVirtualMachine::Panic
+  //---------------------------------------------------------------------------
+  // When things in Lua go wrong (ever called in protected mode??)
+  //
+  // Parameter   Dir      Description
+  // ---------   ---      -----------
+  // lua         IN       State variable
+  //
+  // Return
+  // ------
+  // None.
+  //
+  //============================================================================
+  void LuaVirtualMachine::panic (lua_State *lua)
+  {}
+
+  //============================================================================
+  // bool LuaVirtualMachine::init
+  //---------------------------------------------------------------------------
+  // Initialises the VM, open lua, makes sure things are OK
+  //
+  // Parameter   Dir      Description
+  // ---------   ---      -----------
+  // None.
+  //
+  // Return
+  // ------
+  // Success.
+  //
+  //============================================================================
+  bool LuaVirtualMachine::init (void)
+  {
+    // Open Lua!
+    if (isOk ()) destroy ();
+
+    luaState = lua_open ();
+
+    if (luaState)
+    {
+      machineIsOk = true;
+
+      // Load util libs into lua
+      luaopen_base (luaState);
+      luaopen_table (luaState);
+      luaopen_string (luaState);
+      luaopen_math (luaState);
+      luaopen_debug (luaState);
+      luaopen_io (luaState);
+      luaopen_loadlib (luaState);
+
+      // setup global printing (trace)
+      lua_pushcclosure (luaState, printMessage, 0);
+      lua_setglobal (luaState, "trace");
+
+      lua_atpanic (luaState, (lua_CFunction) LuaVirtualMachine::panic);
+
+      return true;
+    }
+
+    return false;
+  }
+
+  //============================================================================
+  // bool LuaVirtualMachine::destroy
+  //---------------------------------------------------------------------------
+  // Clears the current Lua state
+  //
+  // Parameter   Dir      Description
+  // ---------   ---      -----------
+  // None.
+  //
+  // Return
+  // ------
+  // Success.
+  //
+  //============================================================================
+  bool LuaVirtualMachine::destroy (void)
+  {
+    if (luaState)
+    {
+      lua_close (luaState);
+      luaState = NULL;
+      machineIsOk = false;
+    }
+    return true;
+  }
+
+
+  //============================================================================
+  // bool LuaVirtualMachine::runFile
+  //---------------------------------------------------------------------------
+  // Compiles and runs a lua script file
+  //
+  // Parameter   Dir      Description
+  // ---------   ---      -----------
+  // strFilename IN       Filename to compile and run
+  //
+  // Return
+  // ------
+  // Success.
+  //
+  //============================================================================
+  bool LuaVirtualMachine::runFile (const std::string& strFilename)
+  {
+    bool fSuccess = false;
+    int iErr = 0;
+
+    if ((iErr = luaL_loadfile (luaState, strFilename.c_str())) == 0)
+    {
+      // Call main...
+      if ((iErr = lua_pcall (luaState, 0, LUA_MULTRET, 0)) == 0)
+      {
+        fSuccess = true;
+      }
+    }
+
+    /* if (fSuccess == false)
+     {
+       if (m_pDbg != NULL) m_pDbg->ErrorRun (iErr);
+     }
+    */
+    return fSuccess;
+  }
+
+  //============================================================================
+  // bool LuaVirtualMachine::runBuffer
+  //---------------------------------------------------------------------------
+  // Compiles and runs a pre-compiled data buffer
+  //
+  // Parameter   Dir      Description
+  // ---------   ---      -----------
+  // pbBuffer    IN       Buffer to run
+  // szLen       IN       Length of buffer
+  // strName     IN       Name of Buffer
+  //
+  // Return
+  // ------
+  // Success.
+  //
+  //============================================================================
+  bool LuaVirtualMachine::runBuffer (const unsigned char *pbBuffer, size_t szLen, const char *strName /* = NULL */)
+  {
+    bool fSuccess = false;
+    int iErr = 0;
+
+    if (strName == NULL)
+    {
+      strName = "Temp";
+    }
+
+    if ((iErr = luaL_loadbuffer (luaState, (const char *) pbBuffer, szLen, strName)) == 0)
+    {
+      // Call main...
+      if ((iErr = lua_pcall (luaState, 0, LUA_MULTRET, 0)) == 0)
+      {
+        fSuccess = true;
+      }
+    }
+
+    /* if (fSuccess == false)
+     {
+       if (m_pDbg != NULL) m_pDbg->ErrorRun (iErr);
+     }
+    */
+    return fSuccess;
+
+  }
+
+  //============================================================================
+  // LuaVirtualMachine::callFunction
+  //---------------------------------------------------------------------------
+  // Calls a function that is already on the stack
+  //
+  // Parameter   Dir      Description
+  // ---------   ---      -----------
+  // nArgs       IN       Args that are aleady on the stack
+  // nReturns    IN       Number of expected returns (will be on the stack)
+  //
+  // Return
+  // ------
+  // Success.
+  //
+  //============================================================================
+  bool LuaVirtualMachine::callFunction (int nArgs, int nReturns /* = 0 */)
+  {
+    bool fSuccess = false;
+
+    if (lua_isfunction (luaState, -nArgs-1))
+    {
+      int iErr = 0;
+      iErr = lua_pcall (luaState, nArgs, nReturns, 0);
+
+      if (iErr == 0)
+      {
+        fSuccess = true;
+      }
+      /*else
+      {
+        if (m_pDbg != NULL) m_pDbg->ErrorRun (iErr);
+      }
+      */
+    }
+
+    return fSuccess;
+  }
+}
Index: /branches/script_engine/src/lib/script_engine/OLD/VirtualMachine.h
===================================================================
--- /branches/script_engine/src/lib/script_engine/OLD/VirtualMachine.h	(revision 7688)
+++ /branches/script_engine/src/lib/script_engine/OLD/VirtualMachine.h	(revision 7688)
@@ -0,0 +1,43 @@
+#ifndef __LUA_VIRTUAL_MACHINE_H__
+#define __LUA_VIRTUAL_MACHINE_H__
+
+#include <string>
+
+struct lua_State;
+namespace OrxScript
+{
+  class LuaVirtualMachine
+  {
+  public:
+    LuaVirtualMachine (void);
+    virtual ~LuaVirtualMachine (void);
+
+    bool init(void);
+    bool destroy (void);
+
+    // Load and run script elements
+    bool runFile (const std::string& strFilename);
+    bool runBuffer (const unsigned char *pbBuffer, size_t szLen, const char *strName = NULL);
+
+    // C-Api into script
+    bool callFunction (int nArgs, int nReturns = 0);
+
+    // Get the state of the lua stack (use the cast operator)
+    lua_State* getState (void) const{ return luaState; }
+    operator lua_State* (void) const { return luaState; }
+
+    static void panic (lua_State *lua);
+
+    // Check if the VM is OK and can be used still
+    virtual bool isOk (void) { return machineIsOk; }
+
+    // For debugging
+    //void AttachDebugger (CLuaDebugger *dbg) { m_pDbg = dbg; }
+
+  protected:
+    lua_State* luaState;
+    bool machineIsOk;
+    // CLuaDebugger *m_pDbg;
+  };
+}
+#endif
Index: /branches/script_engine/src/lib/script_engine/OLD/main.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/OLD/main.cc	(revision 7688)
+++ /branches/script_engine/src/lib/script_engine/OLD/main.cc	(revision 7688)
@@ -0,0 +1,300 @@
+#include <iostream>
+#include <string>
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "luaincl.h"
+#include "VirtualMachine.h"
+#include "Script.h"
+#include "LuaCallback.h"
+#include "RestoreStack.h"
+#include "scriptable.h"
+
+
+using namespace OrxScript;
+
+//HACK !!!
+/**
+ * @brief This function adds an object to a script so that the object is accessable from within the luascript. this function is later included in LuaScript as a method
+ *
+ * @param scriptable the scriptable object to add.
+ * @param strObjName the name that the object goes by in the script.
+ * @param luaScript  the script to which the scrtiptable is added
+ *
+ * @return a reference to the added object
+ *
+ *
+ * @todo add this function as a method to LuaScript
+ */
+
+
+int addObjectToScript(Scriptable* scriptable, const std::string& strObjName, LuaScript& luaScript)
+{
+
+  lua_State *state = (lua_State *) (luaScript.getVirtualMachine());
+  LuaVirtualMachine& virtualMachine = luaScript.getVirtualMachine();
+
+  //if() TODO: check if strObjName isn't "this"
+  if (virtualMachine.isOk ())
+  {
+    /*create object table*/
+    // Create a reference to the "object" table and set a name for the reference. Each reference is unique
+
+    lua_newtable (state);
+    int  objRef = luaL_ref (state, LUA_REGISTRYINDEX);
+    lua_rawgeti (state, LUA_REGISTRYINDEX, objRef);
+    lua_setglobal (state, strObjName.c_str());
+
+
+    // Save the "object" table to index 0 of the "object" table
+    LuaRestoreStack rs(virtualMachine);
+    lua_rawgeti (state, LUA_REGISTRYINDEX, objRef);
+    lua_pushlightuserdata (state, scriptable);
+    lua_rawseti (state, -2, 0);
+
+
+
+    return objRef;
+  }
+
+}
+
+
+/**
+ * @brief This function adds a function to a scriptable object in the lua state so that the function is accessable from within the luascript. this function is later included in LuaScript as a method
+           *
+           * @param scriptableRef a reference to the scriptable object
+           * @param strFuncName the name that the function goes by in the script.
+           * @param luaScript  the script to which the function is added
+           *
+           * @returns the pseudoindex of the function (The first function added has index 0, the 2nd 1 and so on)
+           *
+           * @todo add this function as a method to LuaScript
+ */
+
+
+int addFunctionToScriptable(int scriptableRef, const std::string& strFuncName, LuaScript& luaScript)
+{
+  lua_State *state = (lua_State *) (luaScript.getVirtualMachine());
+  LuaVirtualMachine& vm = luaScript.getVirtualMachine();
+  int iMethodIdx = -1;
+
+  if (vm.isOk ())
+  {
+    /* Add function */
+    LuaRestoreStack rs (vm);
+    iMethodIdx = 0;
+    lua_rawgeti (state, LUA_REGISTRYINDEX, scriptableRef);
+    lua_pushstring (state, strFuncName.c_str());
+    lua_pushnumber (state, (lua_Number) iMethodIdx);
+    lua_pushcclosure (state, luaCallback, 1);
+    lua_settable (state, -3);
+  }
+
+  return iMethodIdx;
+}
+
+class objectOne : public Scriptable
+{
+public:
+  objectOne () : Scriptable ()
+  {
+  }
+
+  int scriptCalling (LuaVirtualMachine& vm, std::string functionName)
+  {
+    //switch (iFunctionNumber) //- methodBase) uncomment this when methodBase gets correclty set in the Scriptable class
+    if(functionName == "printNameOne")
+    {
+      //case 0:
+      return printNameOne (vm);
+    }
+
+    return 0;
+  }
+
+
+  int printNameOne(LuaVirtualMachine& vm)
+  {
+    std::cout<<"Hi I'm Object 1 !"<<std::endl;
+    return 0;
+  }
+
+  void handleReturns (LuaVirtualMachine& vm, const std::string& strFunc)
+  {
+  }
+
+}
+;
+
+class objectTwo : public Scriptable
+{
+public:
+  objectTwo () : Scriptable ()
+  {
+    registerFunction(std::string("printNameTwo"));
+    // registerFunction(std::string("printHello"));
+
+  }
+
+  int scriptCalling (LuaVirtualMachine& vm, std::string functionName)
+  {
+    //switch (iFunctionNumber) //- m_iMethodBase) //TODO:find a way to determine the function number somehow: this works just incidentally
+    if(functionName == "printNameTwo")
+    {
+      //case 0:
+
+      return printNameTwo (vm);
+    }
+
+    return 0;
+  }
+
+
+  int printNameTwo(LuaVirtualMachine& vm)
+  {
+    std::cout<<"Hi I'm Object 2 !\n"<<std::endl;
+    return 0;
+  }
+
+  int printHello(LuaVirtualMachine& vm)
+  {
+    std::cout<<"Nice to meet you!\n"<<std::endl;
+    return 0;
+  }
+
+  void handleReturns (LuaVirtualMachine& vm, const std::string& strFunc)
+  {
+  }
+
+}
+;
+
+
+
+
+class CMyScript : public LuaScript
+{
+public:
+  CMyScript () : LuaScript ()
+  {
+    // m_iMethodBase = registerFunction ("hello1");
+    //registerFunction ("hello2");
+    //registerFunction ("hello3");
+  }
+
+  int scriptCalling (LuaVirtualMachine& vm, int iFunctionNumber)
+  {
+    /*switch (iFunctionNumber - m_iMethodBase)
+    {
+      case 0:
+        return Hello1 (vm);
+      case 1:
+        return Hello2 (vm);
+      case 2:
+        return Hello3 (vm);
+    }
+
+    return 0;*/
+  }
+
+  int Hello1 (LuaVirtualMachine& vm)
+  {
+    printf ("Hellow (1)\n");
+    return 0;
+  }
+
+  int Hello2 (LuaVirtualMachine& vm)
+  {
+    lua_State *state = (lua_State *) vm;
+
+    int iNumber = (int) lua_tonumber (state, -2);
+    int iNumber2 = (int) lua_tonumber (state, -1);
+    printf ("Hellow (2) -> %d\n", iNumber);
+    printf ("Second argument was %d\n",iNumber2);
+    return 0;
+  }
+
+  int Hello3 (LuaVirtualMachine& vm)
+  {
+    lua_State *state = (lua_State *) vm;
+
+    int iNumber = (int) lua_tonumber (state, -1);
+    printf ("Hello (3) -> %d\n", iNumber);
+    lua_pushnumber (state, iNumber + 2);
+    return 1;
+  }
+
+
+  void handleReturns (LuaVirtualMachine& vm, const std::string& strFunc)
+  {
+    if (strcmp (strFunc.c_str(), "divideMe") == 0)
+    {
+      // frames returns an answer of the stack
+      lua_State *state = (lua_State *) vm;
+      int itop = lua_gettop (state);
+      int iType = lua_type (state, -1);
+      const char *s = lua_typename (state, iType);
+      double fFrameCount = lua_tonumber (state, -1);
+
+      printf ("frame count = %f\n", fFrameCount);
+    }
+  }
+
+protected:
+  int m_iMethodBase;
+};
+
+//! main  test routine
+int main (int argc, const char** argv)
+{
+
+  std::cout << "== lua-testing environment ==\n" << std::endl;
+
+
+
+  CMyScript ms;
+
+  objectOne ob1;
+  objectTwo ob2;
+  //CMyScript ob1 (vm2);
+
+  //addObjectToScript(&ob1, "obOne", ms, "printNameOne");
+  int obTwoRef = ms.addScriptableToScript(&ob2, "object");
+  // ms.addFunctionToScriptable("printNameTwo",obTwoRef,-1);
+
+  ms.compileFile ("luascript1.lua");
+
+
+  int iTopS = lua_gettop ((lua_State *) ms.getVirtualMachine());
+
+
+  assert (ms.scriptHasFunction ("CountAndCall"));
+  assert (!ms.scriptHasFunction ("countAndCall"));
+  assert (!ms.scriptHasFunction ("test"));
+
+  ms.selectScriptFunction ("CountAndCall");
+  ms.addParam (2);
+  bool res = ms.run ();
+  printf("ms.run returned %b\n",res);
+
+  /* Debug Output
+  lua_State* state =  (lua_State *) (ms.vm());
+  lua_Debug debug;
+  //lua_getfield(state, LUA_GLOBALSINDEX, "CountAndCall" );
+  lua_getinfo( state, "Sl", &debug );
+  std::cout << debug.name<< std::endl;
+  */
+
+  /*ms.selectScriptFunction ("divideMe");
+  ms.addParam (33);
+  ms.run (1);
+
+  ms.selectScriptFunction ("returnToMe");
+  ms.addParam (10);
+  ms.run (0);
+  */
+  return 0 ;
+
+}
Index: /branches/script_engine/src/lib/script_engine/OLD/scriptable.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/OLD/scriptable.cc	(revision 7688)
+++ /branches/script_engine/src/lib/script_engine/OLD/scriptable.cc	(revision 7688)
@@ -0,0 +1,409 @@
+#include <cassert>
+#include <string>
+#include <iostream>
+
+#include <map>
+#include <list>
+
+#include "luaincl.h"
+#include "Script.h"
+#include "LuaCallback.h"
+#include "scriptable.h"
+
+// ---------------------------------------------------------------------------
+namespace OrxScript
+{
+  /**
+   * @brief Constructor
+   *
+   */
+  Scriptable::Scriptable ()
+  {
+  }
+
+  /**
+   * @brief Deconstructor
+   *
+   * The Deconstructor tells all the scripts, that it is part of, that it is deleted.
+   *
+   */
+  Scriptable::~Scriptable (void)
+  {
+    std::list<Script>::iterator it;
+    for(it = scriptList.begin();it != scriptList.end(); it++)
+    {
+      (*it).script->removeFromScript((*it).thisReference);
+    }
+
+  }
+
+
+  //Method indexing check
+  int Scriptable::methods (LuaVirtualMachine& virtualMachine)
+  {
+    LuaScript* script =(getScriptByVirtualMachine(virtualMachine))->script;
+    if(script)
+    {
+      int lastMethod = getLastMethodIndexByPointer(script);
+      if(lastMethod != -1)
+        return lastMethod;
+    }
+
+    return -1;
+  }
+
+
+  /**
+   * @brief  Tells the scriptable that it got added to a script
+   * @param  toScript a pointer to the script the object got added
+   * @param
+   * @param  reference a reference to the scriptable in that partilular script
+   *
+   *  The scriptable will register all its functions to the table at "reference"
+   *  with the script.
+   *
+   */
+
+  bool Scriptable::scriptableAdded(LuaScript* toScript, int toScriptRef, int reference)
+  {
+
+    bool success = true ;
+    if(!scriptIsInScriptList(toScript))// look if the scriptable isn't already added.
+      if(toScript)
+      {
+        Script newScript;
+        newScript.script = toScript;
+        newScript.scriptReference = toScriptRef;
+        newScript.thisReference = reference;
+        newScript.lastMethodIndex = -1;
+        newScript.methodBase = -1;
+
+        scriptList.push_back(newScript);
+
+        int methodIndex;
+        Script* tmpScript = getScriptByPointer(toScript);
+
+        //add all the functions to the script
+        std::list<std::string>::const_iterator it;
+
+        for(it = functionList.begin();it != functionList.end(); it++)
+        {
+
+          if(tmpScript)
+          {
+            methodIndex = toScript->addFunctionToScriptable(*it, tmpScript->thisReference, tmpScript->lastMethodIndex);
+
+
+            if(newScript.methodBase = -1)
+            {
+              if(methodIndex != -1)
+              {
+                std::cout<<"methodIndex is "<<methodIndex<<std::endl;
+                tmpScript->methodBase= methodIndex;
+                tmpScript->lastMethodIndex= methodIndex;
+                tmpScript->functionMap[newScript.methodBase] = *it;
+              }
+              else{success = false; break;}
+            }
+
+            else if(methodIndex != -1)
+            {
+
+              tmpScript->lastMethodIndex = methodIndex;
+              tmpScript->functionMap[newScript.lastMethodIndex] = *it;
+            }
+            else{success= false;break;}
+
+          }
+        }
+
+
+
+      }
+      else
+      {
+        success = false;
+      }
+
+    return success;
+
+  }
+
+
+
+  /**
+    * @brief  Register a function with the scriptable
+    * @param  functionName function name
+    *
+    *
+   */
+
+  void Scriptable::registerFunction(std::string functionName)
+  {
+    //check whether the function is already registered
+    std::list<std::string>::iterator it;
+    for(it = functionList.begin();it != functionList.end(); it++)
+    {
+      if((*it).compare(functionName) == 0)
+      {
+        break;
+      }
+
+    }
+
+    if(it == functionList.end()) // if the functoin wasn't found
+      functionList.push_back(functionName);
+  }
+
+
+  /**
+   * @brief  Get the function name of the function at index
+   * @param  index
+   *
+   * @return the function name on success.
+   *
+   * This function is used in the ScriptCalling function
+   */
+  std::string Scriptable::getFunctionAtIndex(int index, LuaVirtualMachine& virtualMachine)
+  {
+    lua_State * luaState = (lua_State* ) virtualMachine;
+
+    if(virtualMachine.isOk())
+    {
+      lua_getglobal (luaState, "this");
+
+      if (lua_istable (luaState, 1))
+      {
+        // Found the "this" table. The object pointer is at the index 0
+        lua_rawgeti (luaState, 1, 0);
+
+        if (lua_islightuserdata (luaState, -1))
+        {
+          // Found the pointer, need to cast it
+          LuaScript* thisPointer = (LuaScript *) lua_touserdata (luaState, -1);
+
+          if(thisPointer != NULL)
+          {
+            Script* script = getScriptByPointer(thisPointer);
+            if( script != NULL)
+            {
+              std::map<int, std::string>::const_iterator it = script->functionMap.find(index);
+              if(it != script->functionMap.end())//if found
+                return script->functionMap[index];
+            }
+
+          }
+        }
+      }
+    }
+    return "";
+  }
+
+
+  /**
+   * @brief Gets the lastMethod index associated with the LuaScript
+   * @param the luaScript
+   *
+   * @return  A lua reference to the last function of the Scriptable
+   *
+   *
+   */
+
+  int Scriptable::getLastMethodIndexByPointer(LuaScript* luaScript)
+  {
+    if( luaScript )
+    {
+      Script* script = (getScriptByPointer(luaScript));
+      if(script)
+      {
+        return (script->lastMethodIndex);
+      }
+    }
+
+    return -1;
+  }
+
+
+  /**
+   * @brief Gets the functionMap Associated with a LuaScript
+   * @param the LuaScript
+   *
+   * @return A pointer to the functionMap, NULL on failure
+   *
+   *
+   */
+
+  std::map<int, std::string>* Scriptable::getFunctionMapByPointer(LuaScript* scriptPointer)
+  {
+    bool notFound = true;
+    if(scriptPointer)
+    {
+      std::list<Script>::iterator it = scriptList.begin();
+
+
+      while(notFound && it !=scriptList.end() )
+      {
+        if((*it).script == scriptPointer)
+        {
+          notFound = false;
+          return &(it->functionMap);
+        }
+        it++;
+      }
+    }
+
+    if(notFound)
+      return NULL;
+
+  }
+
+
+  /**
+   * @brief Gets the internal representation of a LuaScript by its pointer.
+   * @param script the LuaScript
+   *
+   * @return returns the script if it was found, NULL else.
+   *
+   *
+   */
+
+  Script* Scriptable::getScriptByPointer(LuaScript* script)
+  {
+    bool notFound = true;
+
+    if(script)
+    {
+      std::list<Script>::iterator it = scriptList.begin();
+
+      while(notFound && it != scriptList.end() )
+      {
+        if((*it).script == script)
+        {
+          notFound = false;
+          return &(*it);
+        }
+        it++;
+      }
+
+    }
+    if(notFound)
+      return NULL;
+
+  }
+
+
+  /**
+   * @brief Extracts the Script out of the virtual machine
+   * @param virtualMachine the virtualMachine to search for the script
+   *
+   * @return The Script. If there was an error it returns NULL
+   *
+   *
+   */
+  Script* Scriptable::getScriptByVirtualMachine(LuaVirtualMachine& virtualMachine)
+  {
+
+    if(virtualMachine.isOk())
+    {
+      lua_State * luaState = (lua_State* ) virtualMachine;
+      lua_getglobal (luaState, "this");
+
+      if (lua_istable (luaState, 1))
+      {
+        // Found the "this" table. The object pointer is at the index 0
+        lua_rawgeti (luaState, 1, 0);
+
+        if (lua_islightuserdata (luaState, -1))
+        {
+          // Found the pointer, need to cast it
+          LuaScript* thisPointer = (LuaScript *) lua_touserdata (luaState, -1);
+          Script* script = getScriptByPointer(thisPointer);
+
+          if(script)
+            return script;
+          else
+            return NULL;
+        }
+      }
+    }
+
+
+  }
+
+
+  /**
+   * @brief Checks if "this" Scriptable is already registred with a LuaScript
+   * @param script The LuaScript
+   *
+   * @return true when the Scriptable is alreads registered with that script, flase else.
+   *
+   *
+   */
+  bool Scriptable::scriptIsInScriptList(LuaScript* script)
+  {
+    bool notFound = true;
+
+    if(script)
+    {
+      std::list<Script>::iterator it = scriptList.begin();
+
+
+      while( notFound && it !=scriptList.end() )
+      {
+        if((*it).script == script)
+        {
+          notFound = false;
+          break;
+        }
+        it++;
+      }
+
+    }
+    return !notFound;
+
+  }
+
+
+  /**
+   * @brief Removes a LuaScript from the scriptList
+   * @param deleted LuaScript that is about to be deleted
+   *
+   * This function has to be called int the destructor of the LuaScript.
+   *
+   *
+   */
+
+  void Scriptable::scriptDeleted(LuaScript* deleted)
+  {
+    if(deleted)
+    {
+      Script* script = getScriptByPointer(deleted);
+      if(script)
+      {
+        std::list<Script>::iterator it = scriptList.begin();
+
+
+        while((*it).script != deleted && it != scriptList.end() )
+        {
+          it++;
+        }
+
+        if(it != scriptList.end())
+        {
+          scriptList.erase(it);
+        }
+
+
+      }
+    }
+
+  }
+
+
+
+  char Scriptable::whatIsThis()
+  {
+    char result = 's';
+    return result;
+  }
+}
Index: /branches/script_engine/src/lib/script_engine/OLD/scriptable.h
===================================================================
--- /branches/script_engine/src/lib/script_engine/OLD/scriptable.h	(revision 7688)
+++ /branches/script_engine/src/lib/script_engine/OLD/scriptable.h	(revision 7688)
@@ -0,0 +1,72 @@
+#ifndef __SCRIPTABLE_H__
+#define __SCRIPTABLE_H__
+
+#include <string>
+#include <map>
+#include <list>
+
+#include "VirtualMachine.h"
+
+namespace OrxScript
+{
+  class LuaScript;
+
+  //internal representation of a LuaScript
+  struct Script
+  {
+    int lastMethodIndex;
+    int methodBase;
+    int thisReference;
+    LuaScript* script;
+    int scriptReference; // reference to the script in its own lua_State
+    std::map<int, std::string> functionMap;
+  };
+
+  class Scriptable
+  {
+    friend class LuaScript;
+
+  public:
+    Scriptable (void);
+    virtual ~Scriptable (void);
+
+    // Method indexing check
+    int methods (LuaVirtualMachine& virtualMachine);
+    //int methods(){;return 1;} //BAD BAD HACK HACK HACK !!!!!!!!!!!!!!
+
+    char whatIsThis();
+
+    // When the script calls a class method, this is called
+    virtual int scriptCalling (LuaVirtualMachine& vm, std::string functionName) = 0;
+
+    // When the script function has returns
+    virtual void handleReturns (LuaVirtualMachine& vm, const std::string& strFunc) = 0;
+
+    std::string getFunctionAtIndex(int index, LuaVirtualMachine& virtualMachine);
+
+  protected:
+    void registerFunction(std::string functionName);//Adds a function to the internal function list
+  private:
+    bool scriptableAdded(LuaScript* script, int scriptRef, int reference);
+    //void scriptableFunctionAdded(LuaScript* script, int reference);
+
+
+    Script* getScriptByPointer(LuaScript* script);
+    Script* getScriptByVirtualMachine(LuaVirtualMachine& virtualMachine);
+    std::map<int, std::string>* getFunctionMapByPointer(LuaScript* scriptPointer);
+    int getLastMethodIndexByPointer(LuaScript* script);
+
+
+    bool scriptIsInScriptList(LuaScript* script);
+
+    void scriptDeleted(LuaScript* deleted);
+
+
+
+    std::list<std::string> functionList;
+    std::list<Script> scriptList;
+  };
+
+}
+
+#endif // __SCRIPTABLE_H__
Index: anches/script_engine/src/lib/script_engine/RestoreStack.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/RestoreStack.cc	(revision 7687)
+++ 	(revision )
@@ -1,46 +1,0 @@
-/*
-   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 "RestoreStack.h"
-#include "luaincl.h"
-
-namespace OrxScript
-{
-
-  /**
-   * @brief Stores the stack and the index to the top element
-   *
-   * @param virtualMachine the virtual machine to save
-   */
-  LuaRestoreStack::LuaRestoreStack (LuaVirtualMachine& virtualMachine) : savedState (NULL)
-  {
-    savedState = (lua_State *) virtualMachine;
-    if (virtualMachine.isOk ())
-    {
-      savedTopIndex = lua_gettop (savedState);
-    }
-  }
-  /**
-  * @brief Restores the virtual machine
-  *
-  *
-  */
-  LuaRestoreStack::~LuaRestoreStack ()
-  {
-    lua_settop (savedState, savedTopIndex);
-  }
-}
Index: anches/script_engine/src/lib/script_engine/RestoreStack.h
===================================================================
--- /branches/script_engine/src/lib/script_engine/RestoreStack.h	(revision 7687)
+++ 	(revision )
@@ -1,31 +1,0 @@
-#ifndef __RESTORE_STACK_H__
-#define __RESTORE_STACK_H__
-
-
-#include "VirtualMachine.h"
-/// Forward declaration
-struct lua_State;
-
-namespace OrxScript
-{
-
-  //! Class to restore the stack to the way we found it.
-  class LuaRestoreStack
-  {
-  public:
-    /**
-     * @brief Stores the stack and the index to the top element
-     *
-     * @param virtualMachine the virtual machine to save
-     */
-    LuaRestoreStack (LuaVirtualMachine& virtualMachine);
-    virtual ~LuaRestoreStack (void);
-
-  protected:
-    lua_State* savedState;
-    int savedTopIndex;
-  };
-
-}
-
-#endif // __RESTORE_STACK_H__
Index: anches/script_engine/src/lib/script_engine/Script.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/Script.cc	(revision 7687)
+++ 	(revision )
@@ -1,491 +1,0 @@
-#include <cassert>
-#include <string>
-#include <iostream>
-#include "luaincl.h"
-
-#include "Script.h"
-#include "RestoreStack.h"
-#include "This.h"
-#include "LuaCallback.h"
-
-// ---------------------------------------------------------------------------
-
-namespace OrxScript
-{
-
-#define BEGIN_LUA_CHECK(vm)   lua_State *state = (lua_State *) vm; \
-                              if (vm.isOk ()) {
-#define END_LUA_CHECK         }
-
-
-  /**
-   * @brief Constructor. Sets up the lua stack and the "this" table
-   *
-   *
-   *
-   */
-
-  LuaScript::LuaScript ()
-      : methodCount (0) , argumentCount (0), functionName()
-  {
-    virtualMachine.init();
-    lua_State *state = (lua_State *) virtualMachine;
-
-    if (virtualMachine.isOk ())
-    {
-      // Create a reference to the "this" table. Each reference is unique
-      lua_newtable (state);
-      thisReference = luaL_ref (state, LUA_REGISTRYINDEX);
-
-      // Save the "this" table to index 0 of the "this" table
-      LuaRestoreStack rs (virtualMachine);
-      lua_rawgeti (state, LUA_REGISTRYINDEX, thisReference);
-      lua_pushlightuserdata (state, (void *) this);
-      lua_rawseti (state, -2, 0);
-    }
-
-  }
-
-
-  /**
-   * @brief Deconstructor
-   *
-   */
-
-  LuaScript::~LuaScript (void)
-  {
-    LuaRestoreStack rs (virtualMachine);
-
-    BEGIN_LUA_CHECK (virtualMachine)
-    // Get the reference "this" table
-    lua_rawgeti (state, LUA_REGISTRYINDEX, thisReference);
-
-    // Clear index 0
-    lua_pushnil (state);
-    lua_rawseti (state, -2, 0);
-    END_LUA_CHECK
-
-  }
-
-
-
-  /**
-   * @brief Compiles a given buffer. (reads it into the lua stack)
-   * @param pbBuffer buffer to compile
-   * @param size_t length of the buffer
-   *
-   * @return true if it succeeded
-   */
-
-  bool LuaScript::compileBuffer (unsigned char *pbBuffer, size_t szLen)
-  {
-    assert (pbBuffer != NULL && "LuaScript::compileBuffer ->  pbBuffer == NULL");
-    assert (szLen != 0 && "LuaScript::compileBuffer -> szLen == 0");
-    assert (virtualMachine.isOk () && "VM Not OK");
-
-    // Make sure we have the correct "this" table
-    LuaThis luaThis (virtualMachine, thisReference);
-
-    return virtualMachine.runBuffer (pbBuffer, szLen);
-  }
-
-
-  /**
-   * @brief Compiles a given file. (reads it into the lua stack)
-   * @param strFilename filename
-   *
-   * @return true if it succeeded
-   */
-
-  bool LuaScript::compileFile (const std::string& strFilename)
-  {
-    //assert (strFilename != NULL && "LuaScript::compileFile -> strFilename == NULL");
-    assert (virtualMachine.isOk () && "VM Not OK");
-
-    // Make sure we have the correct "this" table
-    LuaThis luaThis (virtualMachine, thisReference);
-
-    return virtualMachine.runFile (strFilename);
-  }
-
-
-  /**
-   * @brief Registers a function with Lua, the function will be registered in the "this" table
-   * @param strFuncName name of the function by which it goes by in lua
-   *
-   * @return the pseudoindex of the function
-   */
-
-  int LuaScript::registerFunction (const std::string& strFuncName)
-  {
-    //  assert (strFuncName != NULL && "LuaScript::registerFunction -> strFuncName == NULL");
-    assert (virtualMachine.isOk () && "VM Not OK");
-
-    int iMethodIdx = -1;
-
-    LuaRestoreStack rs (virtualMachine);
-
-    BEGIN_LUA_CHECK (virtualMachine)
-    iMethodIdx = ++methodCount;
-
-    // Register a function with the lua script. Added it to the "this" table
-    lua_rawgeti (state, LUA_REGISTRYINDEX, thisReference);
-
-    // Push the function and parameters
-    lua_pushstring (state, strFuncName.c_str());
-    lua_pushnumber (state, (lua_Number) iMethodIdx);
-    lua_pushcclosure (state, luaCallback, 1);
-    lua_settable (state, -3);
-
-    END_LUA_CHECK
-
-    return iMethodIdx;
-  }
-
-
-  /**
-   * @brief Selects a script function to run
-   * @param  strFuncName name of the function to run
-   *
-   * @return true on success
-   */
-  bool LuaScript::selectScriptFunction (const std::string& strFuncName)
-  {
-    //  assert (strFuncName != NULL && "LuaScript::selectScriptFunction -> strFuncName == NULL");
-    assert (virtualMachine.isOk () && "VM Not OK");
-
-    bool fSuccess = true;
-
-    BEGIN_LUA_CHECK (virtualMachine)
-    // Look up function name
-    lua_rawgeti (state, LUA_REGISTRYINDEX, thisReference);
-    lua_pushstring (state, strFuncName.c_str());
-    lua_rawget (state, -2);
-    lua_remove (state, -2);
-
-    // Put the "this" table back
-    lua_rawgeti (state, LUA_REGISTRYINDEX, thisReference);
-
-    // Check that we have a valid function
-    if (!lua_isfunction (state, -2))
-    {
-      fSuccess = false;
-      lua_pop (state, 2);
-    }
-    else
-    {
-      argumentCount = 0;
-      functionName = strFuncName;
-    }
-    END_LUA_CHECK
-
-    return fSuccess;
-  }
-
-
-  /**
-   * @brief Checks to see if a function exists
-   * @param  functionName  Function name
-   *
-   * @return true if the function exists
-   */
-  bool LuaScript::scriptHasFunction (const std::string& functionName)
-  {
-    // printf("entered scriptHasFunction\n");
-
-    //  assert (strScriptName != NULL && "LuaScript::scriptHasFunction -> strScriptName == NULL");
-    assert (virtualMachine.isOk () && "VM Not OK");
-
-    // printf("assertions passed\n");
-
-    LuaRestoreStack rs (virtualMachine);
-
-    bool fFoundFunc = false;
-
-    BEGIN_LUA_CHECK (virtualMachine)
-    lua_rawgeti (state, LUA_REGISTRYINDEX, thisReference);
-    lua_pushstring (state, functionName.c_str());
-    lua_rawget (state, -2);
-    lua_remove (state, -2);
-
-    if (lua_isfunction (state, -1))
-    {
-      fFoundFunc = true;
-    }
-    END_LUA_CHECK
-
-    return fFoundFunc;
-
-  }
-
-
-  /**
-   * @brief Adds a parameter to the parameter list
-   * @param  string  string to be added as parameter for a function.
-   *
-   */
-
-  void LuaScript::addParam (const std::string& string)
-  {
-    assert (virtualMachine.isOk () && "VM Not OK");
-
-    BEGIN_LUA_CHECK (virtualMachine);
-    lua_pushstring (state, string.c_str());
-    ++argumentCount;
-    END_LUA_CHECK;
-  }
-
-
-  /**
-   * @brief Adds a parameter to the parameter list
-   * @param  iInt  integer to be added as parameter for a function.
-   *
-   */
-
-  void LuaScript::addParam (int iInt)
-  {
-    assert (virtualMachine.isOk () && "VM Not OK");
-
-    BEGIN_LUA_CHECK (virtualMachine)
-    lua_pushnumber (state, (lua_Number) iInt);
-    ++argumentCount;
-    END_LUA_CHECK
-  }
-
-
-  /**
-   * @brief Adds a parameter to the parameter list
-   * @param  fFloat  float to be added as parameter for a function.
-   *
-   */
-  void LuaScript::addParam (float fFloat)
-  {
-    assert (virtualMachine.isOk () && "VM Not OK");
-
-    BEGIN_LUA_CHECK (virtualMachine)
-    lua_pushnumber (state, (lua_Number) fFloat);
-    ++argumentCount;
-    END_LUA_CHECK
-  }
-
-
-  /**
-   * @brief Runs the selected script function
-   * @param  nReturns the count of return values
-   *
-   * @return true on success
-   */
-  bool LuaScript::run (int nReturns /* = 0 */)
-  {
-    assert (virtualMachine.isOk () && "VM Not OK");
-
-    // At this point there should be a parameters and a function on the
-    // Lua stack. Each function get a "this" parameter as default and is
-    // pushed onto the stack when the method is selected
-
-    bool fSuccess = virtualMachine.callFunction (argumentCount + 1, nReturns);
-
-    if (fSuccess == true && nReturns > 0)
-    {
-      // Check for returns
-      handleReturns (virtualMachine, functionName);
-      lua_pop ((lua_State *) virtualMachine, nReturns);
-    }
-
-    return fSuccess;
-  }
-
-
-  /**
-   * @brief This function adds an object to a script so that the object is accessable from within the luascript.
-   *
-   * @param scriptable the scriptable object to add.
-   * @param strObjName the name that the object goes by in the script.
-   * @param luaScript  the script to which the scrtiptable is added
-   *
-   * @return a lua reference to the added object
-   *
-   *
-   *
-   */
-
-  int LuaScript::addScriptableToScript(Scriptable* scriptable, const std::string& strObjName)
-  {
-
-    lua_State *state = (lua_State *) (this->virtualMachine);
-
-    if(strObjName.compare(std::string("this")) != 0)
-    {
-      if (virtualMachine.isOk ())
-      {
-        /*create object table*/
-        // Create a reference to the "object" table and set a name for the reference. Each reference is unique
-
-        lua_newtable (state);
-        int  objRef = luaL_ref (state, LUA_REGISTRYINDEX);
-        lua_rawgeti (state, LUA_REGISTRYINDEX, objRef);
-        lua_setglobal (state, strObjName.c_str());
-
-
-        // Save the "object" table to index 0 of the "object" table
-        LuaRestoreStack rs(virtualMachine);
-        lua_rawgeti (state, LUA_REGISTRYINDEX, objRef);
-        lua_pushlightuserdata (state, scriptable);
-        lua_rawseti (state, -2, 0);
-
-        if(! addScriptableToList(scriptable,objRef))
-          std::cout<<"scriptable not added"<<std::endl;
-        if(!(scriptable->scriptableAdded(this,thisReference,objRef)))
-          std::cout<<"scriptableAdded returned false"<<std::endl;
-
-        return objRef;
-      }
-    }
-
-    return -1;
-
-  }
-
-
-
-  /**
-   * @brief Add the function to a scriptable in the Script
-   * @param strFuncName name of the function by which it goes by in lua
-   * @param toScriptable reference to the scriptable the function should be associated with
-   * @param methodIndex index of the last function.
-   *
-   * @return the pseudoindex of the function, -1 on failure
-   */
-
-  int LuaScript::addFunctionToScriptable(const std::string& strFuncName, int toScriptable, int lastMethodIndex)
-  {
-    //  assert (strFuncName != NULL && "LuaScript::registerFunction -> strFuncName == NULL");
-    assert (virtualMachine.isOk () && "VM Not OK");
-
-
-    //get the last method index from the Script
-    Scriptable* scriptable = getScriptableByReference(toScriptable);
-    int iMethodIdx = -1;
-
-    if(scriptable)
-    {
-      LuaRestoreStack rs (virtualMachine);
-
-      BEGIN_LUA_CHECK (virtualMachine)
-      // Register a function with the lua script. Added it to the "toScrtiptable" table
-      lua_rawgeti (state, LUA_REGISTRYINDEX, toScriptable);
-
-      if (lua_istable (state, 1))
-      {
-        iMethodIdx = ++lastMethodIndex;
-
-        // Push the function and parameters
-        lua_pushstring (state, strFuncName.c_str());
-        lua_pushnumber (state, (lua_Number) iMethodIdx);
-        lua_pushcclosure (state, luaCallback, 1);
-        lua_settable (state, -3);
-      }
-      END_LUA_CHECK
-
-    }
-    return iMethodIdx;
-  }
-
-
-  Scriptable* LuaScript::getScriptableByReference(int scrptblRef)
-  {
-
-    bool notFound = true;
-    std::list<Scrptbl>::iterator it = scriptableList.begin();
-
-    while(notFound && it != scriptableList.end() )
-    {
-      if((*it).scriptableRef == scrptblRef)
-      {
-        notFound = false;
-        return (*it).scriptable;
-      }
-      it++;
-    }
-
-
-    if(notFound)
-      return NULL;
-
-  }
-
-  int LuaScript::getReferenceByScriptable(Scriptable* scrptbl)
-  {
-    bool notFound = true;
-
-    std::list<Scrptbl>::iterator it = scriptableList.begin();
-
-    while(notFound && it != scriptableList.end() )
-    {
-      if((*it).scriptable == scrptbl)
-      {
-        notFound = false;
-        return (*it).scriptableRef;
-      }
-      it++;
-    }
-    if(notFound)
-      return -1;
-  }
-
-  bool LuaScript::addScriptableToList(Scriptable* scrptbl, int scriptableRef)
-  {
-    if(scrptbl)
-    {
-      if(getReferenceByScriptable(scrptbl) == -1) // Script isn't there yet
-      {
-        Scrptbl scriptableTmp;
-        scriptableTmp.scriptable = scrptbl;
-        scriptableTmp.scriptableRef = scriptableRef;
-        scriptableList.push_back(scriptableTmp);
-        return true;
-      }
-    }
-
-    return false;
-
-  }
-
-  bool LuaScript::removeScriptableFromList(Scriptable* toRemove)
-  {
-    if(toRemove)
-    {
-      int scrptbl = getReferenceByScriptable(toRemove);
-
-      if(scrptbl != -1)// if the scriptable is on the list
-      {
-        std::list<Scrptbl>::iterator it = scriptableList.begin();
-
-        while((*it).scriptable != toRemove && it != scriptableList.end() )
-        {
-          it++;
-        }
-
-        if(it != scriptableList.end())
-        {
-          scriptableList.erase(it);
-          return true;
-        }
-      }
-    }
-    return false;
-  }
-
-  bool LuaScript::removeScriptableFromList(int scriptable)
-  {
-    return removeScriptableFromList(getScriptableByReference(scriptable));
-  }
-
-
-  char LuaScript::whatIsThis()
-  {
-    char result = 'l';
-    return result;
-  }
-}
-
Index: anches/script_engine/src/lib/script_engine/Script.h
===================================================================
--- /branches/script_engine/src/lib/script_engine/Script.h	(revision 7687)
+++ 	(revision )
@@ -1,92 +1,0 @@
-#ifndef __LUA_SCRIPT_BASE_H__
-#define __LUA_SCRIPT_BASE_H__
-
-#include <string>
-
-#include "VirtualMachine.h"
-#include "scriptable.h"
-
-namespace OrxScript
-{
-
-  struct Scrptbl
-  {
-    Scriptable* scriptable;
-    int scriptableRef;
-  };
-
-  class LuaScript
-  {
-  public:
-    LuaScript ();
-    virtual ~LuaScript (void);
-
-
-    void init(LuaVirtualMachine& vm);
-
-    /* ------------------ Script related Functions ------------------ */
-
-    // Compile script into Virtual Machine
-    bool compileFile (const std::string& strFilename);
-    bool compileBuffer (unsigned char *pbBuffer, size_t szLen);
-
-    // Register function with Lua in the this table
-    int registerFunction (const std::string& strFuncName);
-
-
-    // Selects a Lua Script function to call
-    bool selectScriptFunction (const std::string& strFuncName);
-    void addParam (int iInt);
-    void addParam (float fFloat);
-    void addParam (const std::string& string);
-
-    // Runs the loaded script
-    bool run (int nReturns = 0);
-
-    // Checks on Virtual Machine script
-    bool scriptHasFunction (const std::string& strScriptName);
-
-    // Method indexing check
-    int methods (void) { return methodCount; }
-
-
-    // When the script calls a class method, this is called
-    virtual int scriptCalling (LuaVirtualMachine& vm, int iFunctionNumber) = 0;
-
-    // When the script function has returns
-    virtual void handleReturns (LuaVirtualMachine& vm, const std::string& strFunc) = 0;
-
-
-
-    /* ------------------- Handle external Objects ------------------ */
-
-    void removeFromScript(int referenceToScriptable) {}
-    int addScriptableToScript(Scriptable* scriptbl,const std::string& name);  // name= name the scriptable goes by in lua
-    int addFunctionToScriptable(const std::string& strFuncName, int toScriptable, int lastMethodIndex);
-
-    //Handle the Scriptable List
-    Scriptable* getScriptableByReference(int scrptblRef);
-    int getReferenceByScriptable(Scriptable* scriptable);
-    bool addScriptableToList(Scriptable* scriptbl, int scriptableRef);
-    bool removeScriptableFromList(Scriptable* scriptable);
-    bool removeScriptableFromList(int scriptable);
-
-
-
-    /* ------------------ ... ------------------ */
-
-    LuaVirtualMachine& getVirtualMachine (void) { return virtualMachine; }
-    char whatIsThis();
-
-  protected:
-    int methodCount;
-    LuaVirtualMachine virtualMachine;
-    int thisReference;
-    int argumentCount;
-    std::string functionName;
-    std::list<Scrptbl> scriptableList;
-  };
-
-}
-
-#endif // __LUA_SCRIPT_BASE_H__
Index: anches/script_engine/src/lib/script_engine/This.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/This.cc	(revision 7687)
+++ 	(revision )
@@ -1,49 +1,0 @@
-/*
-   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: Silvan Nellen
-   co-programmer: ...
-*/
-
-//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
-
-#include "This.h"
-#include "luaincl.h"
-
-namespace OrxScript
-{
-  LuaThis::LuaThis (LuaVirtualMachine& vm, int iRef) : oldReference (0), virtualMachine (vm)
-  {
-    lua_State *state = (lua_State *) vm;
-    if (vm.isOk ())
-    {
-      // Save the old "this" table
-      lua_getglobal (state, "this");
-      oldReference = luaL_ref (state, LUA_REGISTRYINDEX);
-
-      // replace it with our new one
-      lua_rawgeti(state, LUA_REGISTRYINDEX, iRef);
-      lua_setglobal (state, "this");
-    }
-  }
-
-  LuaThis::~LuaThis (void)
-  {
-    lua_State *state = (lua_State *) virtualMachine;
-    if (oldReference > 0 && virtualMachine.isOk ())
-    {
-      // Replace the old "this" table
-      lua_rawgeti(state, LUA_REGISTRYINDEX, oldReference);
-      lua_setglobal (state, "this");
-      luaL_unref (state, LUA_REGISTRYINDEX, oldReference);
-    }
-  }
-}
Index: anches/script_engine/src/lib/script_engine/This.h
===================================================================
--- /branches/script_engine/src/lib/script_engine/This.h	(revision 7687)
+++ 	(revision )
@@ -1,21 +1,0 @@
-#ifndef __THIS_H__
-#define __THIS_H__
-
-#include "VirtualMachine.h"
-
-// Sets the "this" global table that scripts use
-namespace OrxScript
-{
-
-  class LuaThis
-  {
-  public:
-    LuaThis (LuaVirtualMachine& vm, int iRef);
-    virtual ~LuaThis (void);
-
-  protected:
-    int oldReference;
-    LuaVirtualMachine& virtualMachine;
-  };
-}
-#endif // __THIS_H__
Index: anches/script_engine/src/lib/script_engine/VirtualMachine.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/VirtualMachine.cc	(revision 7687)
+++ 	(revision )
@@ -1,291 +1,0 @@
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "luaincl.h"
-#include "VirtualMachine.h"
-namespace OrxScript
-{
-  // ---------------------------------------------------------------------------
-
-
-  //============================================================================
-  // int printMessage
-  //---------------------------------------------------------------------------
-  // Prints a message to the console
-  //
-  // Parameter   Dir      Description
-  // ---------   ---      -----------
-  // lua         IN       State variable
-  //
-  // Return
-  // ------
-  // Number of return varaibles on the stack
-  //
-  //============================================================================
-  static int printMessage (lua_State *lua)
-  {
-    assert (lua_isstring (lua,1));
-
-    const char *msg = lua_tostring (lua, 1);
-
-    // get caller
-    lua_Debug ar;
-    memset (&ar, 0, sizeof(ar));
-    lua_getstack (lua, 1, &ar);
-    lua_getinfo (lua, "Snl", &ar);
-
-    // debug output
-    const char *str = ar.source;
-    printf ("script: %s -- at %s(%d)\n", msg, str, ar.currentline);
-    return 0;
-  }
-
-  //============================================================================
-  // LuaVirtualMachine::LuaVirtualMachine
-  //---------------------------------------------------------------------------
-  // Constructor. Setups the default VM state
-  //
-  // Parameter   Dir      Description
-  // ---------   ---      -----------
-  //
-  //
-  // Return
-  // ------
-  // None.
-  //
-  //============================================================================
-  LuaVirtualMachine::LuaVirtualMachine (void) : luaState (NULL)
-  {
-    machineIsOk = false;
-  }
-
-  //============================================================================
-  // LuaVirtualMachine::LuaVirtualMachine
-  //---------------------------------------------------------------------------
-  // Destructor. Closes the VM
-  //
-  // Parameter   Dir      Description
-  // ---------   ---      -----------
-  //
-  //
-  // Return
-  // ------
-  // None.
-  //
-  //============================================================================
-  LuaVirtualMachine::~LuaVirtualMachine (void)
-  {
-    if (luaState != NULL)
-    {
-      lua_close (luaState);
-    }
-  }
-
-  //============================================================================
-  // LuaVirtualMachine::Panic
-  //---------------------------------------------------------------------------
-  // When things in Lua go wrong (ever called in protected mode??)
-  //
-  // Parameter   Dir      Description
-  // ---------   ---      -----------
-  // lua         IN       State variable
-  //
-  // Return
-  // ------
-  // None.
-  //
-  //============================================================================
-  void LuaVirtualMachine::panic (lua_State *lua)
-  {}
-
-  //============================================================================
-  // bool LuaVirtualMachine::init
-  //---------------------------------------------------------------------------
-  // Initialises the VM, open lua, makes sure things are OK
-  //
-  // Parameter   Dir      Description
-  // ---------   ---      -----------
-  // None.
-  //
-  // Return
-  // ------
-  // Success.
-  //
-  //============================================================================
-  bool LuaVirtualMachine::init (void)
-  {
-    // Open Lua!
-    if (isOk ()) destroy ();
-
-    luaState = lua_open ();
-
-    if (luaState)
-    {
-      machineIsOk = true;
-
-      // Load util libs into lua
-      luaopen_base (luaState);
-      luaopen_table (luaState);
-      luaopen_string (luaState);
-      luaopen_math (luaState);
-      luaopen_debug (luaState);
-      luaopen_io (luaState);
-      luaopen_loadlib (luaState);
-
-      // setup global printing (trace)
-      lua_pushcclosure (luaState, printMessage, 0);
-      lua_setglobal (luaState, "trace");
-
-      lua_atpanic (luaState, (lua_CFunction) LuaVirtualMachine::panic);
-
-      return true;
-    }
-
-    return false;
-  }
-
-  //============================================================================
-  // bool LuaVirtualMachine::destroy
-  //---------------------------------------------------------------------------
-  // Clears the current Lua state
-  //
-  // Parameter   Dir      Description
-  // ---------   ---      -----------
-  // None.
-  //
-  // Return
-  // ------
-  // Success.
-  //
-  //============================================================================
-  bool LuaVirtualMachine::destroy (void)
-  {
-    if (luaState)
-    {
-      lua_close (luaState);
-      luaState = NULL;
-      machineIsOk = false;
-    }
-    return true;
-  }
-
-
-  //============================================================================
-  // bool LuaVirtualMachine::runFile
-  //---------------------------------------------------------------------------
-  // Compiles and runs a lua script file
-  //
-  // Parameter   Dir      Description
-  // ---------   ---      -----------
-  // strFilename IN       Filename to compile and run
-  //
-  // Return
-  // ------
-  // Success.
-  //
-  //============================================================================
-  bool LuaVirtualMachine::runFile (const std::string& strFilename)
-  {
-    bool fSuccess = false;
-    int iErr = 0;
-
-    if ((iErr = luaL_loadfile (luaState, strFilename.c_str())) == 0)
-    {
-      // Call main...
-      if ((iErr = lua_pcall (luaState, 0, LUA_MULTRET, 0)) == 0)
-      {
-        fSuccess = true;
-      }
-    }
-
-    /* if (fSuccess == false)
-     {
-       if (m_pDbg != NULL) m_pDbg->ErrorRun (iErr);
-     }
-    */
-    return fSuccess;
-  }
-
-  //============================================================================
-  // bool LuaVirtualMachine::runBuffer
-  //---------------------------------------------------------------------------
-  // Compiles and runs a pre-compiled data buffer
-  //
-  // Parameter   Dir      Description
-  // ---------   ---      -----------
-  // pbBuffer    IN       Buffer to run
-  // szLen       IN       Length of buffer
-  // strName     IN       Name of Buffer
-  //
-  // Return
-  // ------
-  // Success.
-  //
-  //============================================================================
-  bool LuaVirtualMachine::runBuffer (const unsigned char *pbBuffer, size_t szLen, const char *strName /* = NULL */)
-  {
-    bool fSuccess = false;
-    int iErr = 0;
-
-    if (strName == NULL)
-    {
-      strName = "Temp";
-    }
-
-    if ((iErr = luaL_loadbuffer (luaState, (const char *) pbBuffer, szLen, strName)) == 0)
-    {
-      // Call main...
-      if ((iErr = lua_pcall (luaState, 0, LUA_MULTRET, 0)) == 0)
-      {
-        fSuccess = true;
-      }
-    }
-
-    /* if (fSuccess == false)
-     {
-       if (m_pDbg != NULL) m_pDbg->ErrorRun (iErr);
-     }
-    */
-    return fSuccess;
-
-  }
-
-  //============================================================================
-  // LuaVirtualMachine::callFunction
-  //---------------------------------------------------------------------------
-  // Calls a function that is already on the stack
-  //
-  // Parameter   Dir      Description
-  // ---------   ---      -----------
-  // nArgs       IN       Args that are aleady on the stack
-  // nReturns    IN       Number of expected returns (will be on the stack)
-  //
-  // Return
-  // ------
-  // Success.
-  //
-  //============================================================================
-  bool LuaVirtualMachine::callFunction (int nArgs, int nReturns /* = 0 */)
-  {
-    bool fSuccess = false;
-
-    if (lua_isfunction (luaState, -nArgs-1))
-    {
-      int iErr = 0;
-      iErr = lua_pcall (luaState, nArgs, nReturns, 0);
-
-      if (iErr == 0)
-      {
-        fSuccess = true;
-      }
-      /*else
-      {
-        if (m_pDbg != NULL) m_pDbg->ErrorRun (iErr);
-      }
-      */
-    }
-
-    return fSuccess;
-  }
-}
Index: anches/script_engine/src/lib/script_engine/VirtualMachine.h
===================================================================
--- /branches/script_engine/src/lib/script_engine/VirtualMachine.h	(revision 7687)
+++ 	(revision )
@@ -1,43 +1,0 @@
-#ifndef __LUA_VIRTUAL_MACHINE_H__
-#define __LUA_VIRTUAL_MACHINE_H__
-
-#include <string>
-
-struct lua_State;
-namespace OrxScript
-{
-  class LuaVirtualMachine
-  {
-  public:
-    LuaVirtualMachine (void);
-    virtual ~LuaVirtualMachine (void);
-
-    bool init(void);
-    bool destroy (void);
-
-    // Load and run script elements
-    bool runFile (const std::string& strFilename);
-    bool runBuffer (const unsigned char *pbBuffer, size_t szLen, const char *strName = NULL);
-
-    // C-Api into script
-    bool callFunction (int nArgs, int nReturns = 0);
-
-    // Get the state of the lua stack (use the cast operator)
-    lua_State* getState (void) const{ return luaState; }
-    operator lua_State* (void) const { return luaState; }
-
-    static void panic (lua_State *lua);
-
-    // Check if the VM is OK and can be used still
-    virtual bool isOk (void) { return machineIsOk; }
-
-    // For debugging
-    //void AttachDebugger (CLuaDebugger *dbg) { m_pDbg = dbg; }
-
-  protected:
-    lua_State* luaState;
-    bool machineIsOk;
-    // CLuaDebugger *m_pDbg;
-  };
-}
-#endif
Index: anches/script_engine/src/lib/script_engine/main.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/main.cc	(revision 7687)
+++ 	(revision )
@@ -1,300 +1,0 @@
-#include <iostream>
-#include <string>
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "luaincl.h"
-#include "VirtualMachine.h"
-#include "Script.h"
-#include "LuaCallback.h"
-#include "RestoreStack.h"
-#include "scriptable.h"
-
-
-using namespace OrxScript;
-
-//HACK !!!
-/**
- * @brief This function adds an object to a script so that the object is accessable from within the luascript. this function is later included in LuaScript as a method
- *
- * @param scriptable the scriptable object to add.
- * @param strObjName the name that the object goes by in the script.
- * @param luaScript  the script to which the scrtiptable is added
- *
- * @return a reference to the added object
- *
- *
- * @todo add this function as a method to LuaScript
- */
-
-
-int addObjectToScript(Scriptable* scriptable, const std::string& strObjName, LuaScript& luaScript)
-{
-
-  lua_State *state = (lua_State *) (luaScript.getVirtualMachine());
-  LuaVirtualMachine& virtualMachine = luaScript.getVirtualMachine();
-
-  //if() TODO: check if strObjName isn't "this"
-  if (virtualMachine.isOk ())
-  {
-    /*create object table*/
-    // Create a reference to the "object" table and set a name for the reference. Each reference is unique
-
-    lua_newtable (state);
-    int  objRef = luaL_ref (state, LUA_REGISTRYINDEX);
-    lua_rawgeti (state, LUA_REGISTRYINDEX, objRef);
-    lua_setglobal (state, strObjName.c_str());
-
-
-    // Save the "object" table to index 0 of the "object" table
-    LuaRestoreStack rs(virtualMachine);
-    lua_rawgeti (state, LUA_REGISTRYINDEX, objRef);
-    lua_pushlightuserdata (state, scriptable);
-    lua_rawseti (state, -2, 0);
-
-
-
-    return objRef;
-  }
-
-}
-
-
-/**
- * @brief This function adds a function to a scriptable object in the lua state so that the function is accessable from within the luascript. this function is later included in LuaScript as a method
-           *
-           * @param scriptableRef a reference to the scriptable object
-           * @param strFuncName the name that the function goes by in the script.
-           * @param luaScript  the script to which the function is added
-           *
-           * @returns the pseudoindex of the function (The first function added has index 0, the 2nd 1 and so on)
-           *
-           * @todo add this function as a method to LuaScript
- */
-
-
-int addFunctionToScriptable(int scriptableRef, const std::string& strFuncName, LuaScript& luaScript)
-{
-  lua_State *state = (lua_State *) (luaScript.getVirtualMachine());
-  LuaVirtualMachine& vm = luaScript.getVirtualMachine();
-  int iMethodIdx = -1;
-
-  if (vm.isOk ())
-  {
-    /* Add function */
-    LuaRestoreStack rs (vm);
-    iMethodIdx = 0;
-    lua_rawgeti (state, LUA_REGISTRYINDEX, scriptableRef);
-    lua_pushstring (state, strFuncName.c_str());
-    lua_pushnumber (state, (lua_Number) iMethodIdx);
-    lua_pushcclosure (state, luaCallback, 1);
-    lua_settable (state, -3);
-  }
-
-  return iMethodIdx;
-}
-
-class objectOne : public Scriptable
-{
-public:
-  objectOne () : Scriptable ()
-  {
-  }
-
-  int scriptCalling (LuaVirtualMachine& vm, std::string functionName)
-  {
-    //switch (iFunctionNumber) //- methodBase) uncomment this when methodBase gets correclty set in the Scriptable class
-    if(functionName == "printNameOne")
-    {
-      //case 0:
-      return printNameOne (vm);
-    }
-
-    return 0;
-  }
-
-
-  int printNameOne(LuaVirtualMachine& vm)
-  {
-    std::cout<<"Hi I'm Object 1 !"<<std::endl;
-    return 0;
-  }
-
-  void handleReturns (LuaVirtualMachine& vm, const std::string& strFunc)
-  {
-  }
-
-}
-;
-
-class objectTwo : public Scriptable
-{
-public:
-  objectTwo () : Scriptable ()
-  {
-    registerFunction(std::string("printNameTwo"));
-    // registerFunction(std::string("printHello"));
-
-  }
-
-  int scriptCalling (LuaVirtualMachine& vm, std::string functionName)
-  {
-    //switch (iFunctionNumber) //- m_iMethodBase) //TODO:find a way to determine the function number somehow: this works just incidentally
-    if(functionName == "printNameTwo")
-    {
-      //case 0:
-
-      return printNameTwo (vm);
-    }
-
-    return 0;
-  }
-
-
-  int printNameTwo(LuaVirtualMachine& vm)
-  {
-    std::cout<<"Hi I'm Object 2 !\n"<<std::endl;
-    return 0;
-  }
-
-  int printHello(LuaVirtualMachine& vm)
-  {
-    std::cout<<"Nice to meet you!\n"<<std::endl;
-    return 0;
-  }
-
-  void handleReturns (LuaVirtualMachine& vm, const std::string& strFunc)
-  {
-  }
-
-}
-;
-
-
-
-
-class CMyScript : public LuaScript
-{
-public:
-  CMyScript () : LuaScript ()
-  {
-    // m_iMethodBase = registerFunction ("hello1");
-    //registerFunction ("hello2");
-    //registerFunction ("hello3");
-  }
-
-  int scriptCalling (LuaVirtualMachine& vm, int iFunctionNumber)
-  {
-    /*switch (iFunctionNumber - m_iMethodBase)
-    {
-      case 0:
-        return Hello1 (vm);
-      case 1:
-        return Hello2 (vm);
-      case 2:
-        return Hello3 (vm);
-    }
-
-    return 0;*/
-  }
-
-  int Hello1 (LuaVirtualMachine& vm)
-  {
-    printf ("Hellow (1)\n");
-    return 0;
-  }
-
-  int Hello2 (LuaVirtualMachine& vm)
-  {
-    lua_State *state = (lua_State *) vm;
-
-    int iNumber = (int) lua_tonumber (state, -2);
-    int iNumber2 = (int) lua_tonumber (state, -1);
-    printf ("Hellow (2) -> %d\n", iNumber);
-    printf ("Second argument was %d\n",iNumber2);
-    return 0;
-  }
-
-  int Hello3 (LuaVirtualMachine& vm)
-  {
-    lua_State *state = (lua_State *) vm;
-
-    int iNumber = (int) lua_tonumber (state, -1);
-    printf ("Hello (3) -> %d\n", iNumber);
-    lua_pushnumber (state, iNumber + 2);
-    return 1;
-  }
-
-
-  void handleReturns (LuaVirtualMachine& vm, const std::string& strFunc)
-  {
-    if (strcmp (strFunc.c_str(), "divideMe") == 0)
-    {
-      // frames returns an answer of the stack
-      lua_State *state = (lua_State *) vm;
-      int itop = lua_gettop (state);
-      int iType = lua_type (state, -1);
-      const char *s = lua_typename (state, iType);
-      double fFrameCount = lua_tonumber (state, -1);
-
-      printf ("frame count = %f\n", fFrameCount);
-    }
-  }
-
-protected:
-  int m_iMethodBase;
-};
-
-//! main  test routine
-int main (int argc, const char** argv)
-{
-
-  std::cout << "== lua-testing environment ==\n" << std::endl;
-
-
-
-  CMyScript ms;
-
-  objectOne ob1;
-  objectTwo ob2;
-  //CMyScript ob1 (vm2);
-
-  //addObjectToScript(&ob1, "obOne", ms, "printNameOne");
-  int obTwoRef = ms.addScriptableToScript(&ob2, "object");
-  // ms.addFunctionToScriptable("printNameTwo",obTwoRef,-1);
-
-  ms.compileFile ("luascript1.lua");
-
-
-  int iTopS = lua_gettop ((lua_State *) ms.getVirtualMachine());
-
-
-  assert (ms.scriptHasFunction ("CountAndCall"));
-  assert (!ms.scriptHasFunction ("countAndCall"));
-  assert (!ms.scriptHasFunction ("test"));
-
-  ms.selectScriptFunction ("CountAndCall");
-  ms.addParam (2);
-  bool res = ms.run ();
-  printf("ms.run returned %b\n",res);
-
-  /* Debug Output
-  lua_State* state =  (lua_State *) (ms.vm());
-  lua_Debug debug;
-  //lua_getfield(state, LUA_GLOBALSINDEX, "CountAndCall" );
-  lua_getinfo( state, "Sl", &debug );
-  std::cout << debug.name<< std::endl;
-  */
-
-  /*ms.selectScriptFunction ("divideMe");
-  ms.addParam (33);
-  ms.run (1);
-
-  ms.selectScriptFunction ("returnToMe");
-  ms.addParam (10);
-  ms.run (0);
-  */
-  return 0 ;
-
-}
Index: anches/script_engine/src/lib/script_engine/scriptable.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/scriptable.cc	(revision 7687)
+++ 	(revision )
@@ -1,409 +1,0 @@
-#include <cassert>
-#include <string>
-#include <iostream>
-
-#include <map>
-#include <list>
-
-#include "luaincl.h"
-#include "Script.h"
-#include "LuaCallback.h"
-#include "scriptable.h"
-
-// ---------------------------------------------------------------------------
-namespace OrxScript
-{
-  /**
-   * @brief Constructor
-   *
-   */
-  Scriptable::Scriptable ()
-  {
-  }
-
-  /**
-   * @brief Deconstructor
-   *
-   * The Deconstructor tells all the scripts, that it is part of, that it is deleted.
-   *
-   */
-  Scriptable::~Scriptable (void)
-  {
-    std::list<Script>::iterator it;
-    for(it = scriptList.begin();it != scriptList.end(); it++)
-    {
-      (*it).script->removeFromScript((*it).thisReference);
-    }
-
-  }
-
-
-  //Method indexing check
-  int Scriptable::methods (LuaVirtualMachine& virtualMachine)
-  {
-    LuaScript* script =(getScriptByVirtualMachine(virtualMachine))->script;
-    if(script)
-    {
-      int lastMethod = getLastMethodIndexByPointer(script);
-      if(lastMethod != -1)
-        return lastMethod;
-    }
-
-    return -1;
-  }
-
-
-  /**
-   * @brief  Tells the scriptable that it got added to a script
-   * @param  toScript a pointer to the script the object got added
-   * @param
-   * @param  reference a reference to the scriptable in that partilular script
-   *
-   *  The scriptable will register all its functions to the table at "reference"
-   *  with the script.
-   *
-   */
-
-  bool Scriptable::scriptableAdded(LuaScript* toScript, int toScriptRef, int reference)
-  {
-
-    bool success = true ;
-    if(!scriptIsInScriptList(toScript))// look if the scriptable isn't already added.
-      if(toScript)
-      {
-        Script newScript;
-        newScript.script = toScript;
-        newScript.scriptReference = toScriptRef;
-        newScript.thisReference = reference;
-        newScript.lastMethodIndex = -1;
-        newScript.methodBase = -1;
-
-        scriptList.push_back(newScript);
-
-        int methodIndex;
-        Script* tmpScript = getScriptByPointer(toScript);
-
-        //add all the functions to the script
-        std::list<std::string>::const_iterator it;
-
-        for(it = functionList.begin();it != functionList.end(); it++)
-        {
-
-          if(tmpScript)
-          {
-            methodIndex = toScript->addFunctionToScriptable(*it, tmpScript->thisReference, tmpScript->lastMethodIndex);
-
-
-            if(newScript.methodBase = -1)
-            {
-              if(methodIndex != -1)
-              {
-                std::cout<<"methodIndex is "<<methodIndex<<std::endl;
-                tmpScript->methodBase= methodIndex;
-                tmpScript->lastMethodIndex= methodIndex;
-                tmpScript->functionMap[newScript.methodBase] = *it;
-              }
-              else{success = false; break;}
-            }
-
-            else if(methodIndex != -1)
-            {
-
-              tmpScript->lastMethodIndex = methodIndex;
-              tmpScript->functionMap[newScript.lastMethodIndex] = *it;
-            }
-            else{success= false;break;}
-
-          }
-        }
-
-
-
-      }
-      else
-      {
-        success = false;
-      }
-
-    return success;
-
-  }
-
-
-
-  /**
-    * @brief  Register a function with the scriptable
-    * @param  functionName function name
-    *
-    *
-   */
-
-  void Scriptable::registerFunction(std::string functionName)
-  {
-    //check whether the function is already registered
-    std::list<std::string>::iterator it;
-    for(it = functionList.begin();it != functionList.end(); it++)
-    {
-      if((*it).compare(functionName) == 0)
-      {
-        break;
-      }
-
-    }
-
-    if(it == functionList.end()) // if the functoin wasn't found
-      functionList.push_back(functionName);
-  }
-
-
-  /**
-   * @brief  Get the function name of the function at index
-   * @param  index
-   *
-   * @return the function name on success.
-   *
-   * This function is used in the ScriptCalling function
-   */
-  std::string Scriptable::getFunctionAtIndex(int index, LuaVirtualMachine& virtualMachine)
-  {
-    lua_State * luaState = (lua_State* ) virtualMachine;
-
-    if(virtualMachine.isOk())
-    {
-      lua_getglobal (luaState, "this");
-
-      if (lua_istable (luaState, 1))
-      {
-        // Found the "this" table. The object pointer is at the index 0
-        lua_rawgeti (luaState, 1, 0);
-
-        if (lua_islightuserdata (luaState, -1))
-        {
-          // Found the pointer, need to cast it
-          LuaScript* thisPointer = (LuaScript *) lua_touserdata (luaState, -1);
-
-          if(thisPointer != NULL)
-          {
-            Script* script = getScriptByPointer(thisPointer);
-            if( script != NULL)
-            {
-              std::map<int, std::string>::const_iterator it = script->functionMap.find(index);
-              if(it != script->functionMap.end())//if found
-                return script->functionMap[index];
-            }
-
-          }
-        }
-      }
-    }
-    return "";
-  }
-
-
-  /**
-   * @brief Gets the lastMethod index associated with the LuaScript
-   * @param the luaScript
-   *
-   * @return  A lua reference to the last function of the Scriptable
-   *
-   *
-   */
-
-  int Scriptable::getLastMethodIndexByPointer(LuaScript* luaScript)
-  {
-    if( luaScript )
-    {
-      Script* script = (getScriptByPointer(luaScript));
-      if(script)
-      {
-        return (script->lastMethodIndex);
-      }
-    }
-
-    return -1;
-  }
-
-
-  /**
-   * @brief Gets the functionMap Associated with a LuaScript
-   * @param the LuaScript
-   *
-   * @return A pointer to the functionMap, NULL on failure
-   *
-   *
-   */
-
-  std::map<int, std::string>* Scriptable::getFunctionMapByPointer(LuaScript* scriptPointer)
-  {
-    bool notFound = true;
-    if(scriptPointer)
-    {
-      std::list<Script>::iterator it = scriptList.begin();
-
-
-      while(notFound && it !=scriptList.end() )
-      {
-        if((*it).script == scriptPointer)
-        {
-          notFound = false;
-          return &(it->functionMap);
-        }
-        it++;
-      }
-    }
-
-    if(notFound)
-      return NULL;
-
-  }
-
-
-  /**
-   * @brief Gets the internal representation of a LuaScript by its pointer.
-   * @param script the LuaScript
-   *
-   * @return returns the script if it was found, NULL else.
-   *
-   *
-   */
-
-  Script* Scriptable::getScriptByPointer(LuaScript* script)
-  {
-    bool notFound = true;
-
-    if(script)
-    {
-      std::list<Script>::iterator it = scriptList.begin();
-
-      while(notFound && it != scriptList.end() )
-      {
-        if((*it).script == script)
-        {
-          notFound = false;
-          return &(*it);
-        }
-        it++;
-      }
-
-    }
-    if(notFound)
-      return NULL;
-
-  }
-
-
-  /**
-   * @brief Extracts the Script out of the virtual machine
-   * @param virtualMachine the virtualMachine to search for the script
-   *
-   * @return The Script. If there was an error it returns NULL
-   *
-   *
-   */
-  Script* Scriptable::getScriptByVirtualMachine(LuaVirtualMachine& virtualMachine)
-  {
-
-    if(virtualMachine.isOk())
-    {
-      lua_State * luaState = (lua_State* ) virtualMachine;
-      lua_getglobal (luaState, "this");
-
-      if (lua_istable (luaState, 1))
-      {
-        // Found the "this" table. The object pointer is at the index 0
-        lua_rawgeti (luaState, 1, 0);
-
-        if (lua_islightuserdata (luaState, -1))
-        {
-          // Found the pointer, need to cast it
-          LuaScript* thisPointer = (LuaScript *) lua_touserdata (luaState, -1);
-          Script* script = getScriptByPointer(thisPointer);
-
-          if(script)
-            return script;
-          else
-            return NULL;
-        }
-      }
-    }
-
-
-  }
-
-
-  /**
-   * @brief Checks if "this" Scriptable is already registred with a LuaScript
-   * @param script The LuaScript
-   *
-   * @return true when the Scriptable is alreads registered with that script, flase else.
-   *
-   *
-   */
-  bool Scriptable::scriptIsInScriptList(LuaScript* script)
-  {
-    bool notFound = true;
-
-    if(script)
-    {
-      std::list<Script>::iterator it = scriptList.begin();
-
-
-      while( notFound && it !=scriptList.end() )
-      {
-        if((*it).script == script)
-        {
-          notFound = false;
-          break;
-        }
-        it++;
-      }
-
-    }
-    return !notFound;
-
-  }
-
-
-  /**
-   * @brief Removes a LuaScript from the scriptList
-   * @param deleted LuaScript that is about to be deleted
-   *
-   * This function has to be called int the destructor of the LuaScript.
-   *
-   *
-   */
-
-  void Scriptable::scriptDeleted(LuaScript* deleted)
-  {
-    if(deleted)
-    {
-      Script* script = getScriptByPointer(deleted);
-      if(script)
-      {
-        std::list<Script>::iterator it = scriptList.begin();
-
-
-        while((*it).script != deleted && it != scriptList.end() )
-        {
-          it++;
-        }
-
-        if(it != scriptList.end())
-        {
-          scriptList.erase(it);
-        }
-
-
-      }
-    }
-
-  }
-
-
-
-  char Scriptable::whatIsThis()
-  {
-    char result = 's';
-    return result;
-  }
-}
Index: anches/script_engine/src/lib/script_engine/scriptable.h
===================================================================
--- /branches/script_engine/src/lib/script_engine/scriptable.h	(revision 7687)
+++ 	(revision )
@@ -1,72 +1,0 @@
-#ifndef __SCRIPTABLE_H__
-#define __SCRIPTABLE_H__
-
-#include <string>
-#include <map>
-#include <list>
-
-#include "VirtualMachine.h"
-
-namespace OrxScript
-{
-  class LuaScript;
-
-  //internal representation of a LuaScript
-  struct Script
-  {
-    int lastMethodIndex;
-    int methodBase;
-    int thisReference;
-    LuaScript* script;
-    int scriptReference; // reference to the script in its own lua_State
-    std::map<int, std::string> functionMap;
-  };
-
-  class Scriptable
-  {
-    friend class LuaScript;
-
-  public:
-    Scriptable (void);
-    virtual ~Scriptable (void);
-
-    // Method indexing check
-    int methods (LuaVirtualMachine& virtualMachine);
-    //int methods(){;return 1;} //BAD BAD HACK HACK HACK !!!!!!!!!!!!!!
-
-    char whatIsThis();
-
-    // When the script calls a class method, this is called
-    virtual int scriptCalling (LuaVirtualMachine& vm, std::string functionName) = 0;
-
-    // When the script function has returns
-    virtual void handleReturns (LuaVirtualMachine& vm, const std::string& strFunc) = 0;
-
-    std::string getFunctionAtIndex(int index, LuaVirtualMachine& virtualMachine);
-
-  protected:
-    void registerFunction(std::string functionName);//Adds a function to the internal function list
-  private:
-    bool scriptableAdded(LuaScript* script, int scriptRef, int reference);
-    //void scriptableFunctionAdded(LuaScript* script, int reference);
-
-
-    Script* getScriptByPointer(LuaScript* script);
-    Script* getScriptByVirtualMachine(LuaVirtualMachine& virtualMachine);
-    std::map<int, std::string>* getFunctionMapByPointer(LuaScript* scriptPointer);
-    int getLastMethodIndexByPointer(LuaScript* script);
-
-
-    bool scriptIsInScriptList(LuaScript* script);
-
-    void scriptDeleted(LuaScript* deleted);
-
-
-
-    std::list<std::string> functionList;
-    std::list<Script> scriptList;
-  };
-
-}
-
-#endif // __SCRIPTABLE_H__
