Index: branches/script_engine/src/lib/script_engine/Script.cc
===================================================================
--- branches/script_engine/src/lib/script_engine/Script.cc	(revision 8043)
+++ branches/script_engine/src/lib/script_engine/Script.cc	(revision 8044)
@@ -4,4 +4,6 @@
 Script::Script()
 {
+
+  returnCount = argumentCount = 0;
 
   luaState = lua_open();
@@ -13,4 +15,5 @@
   luaopen_math(luaState);
   luaopen_debug(luaState);
+
 
 }
@@ -26,29 +29,44 @@
 bool Script::loadFile(std::string& filename)
  {
+
    int error = luaL_loadfile (luaState, filename.c_str());
 
    if(error == 0)
    {
-     return true;
+     error = lua_pcall(luaState, 0, 0, 0);
+
+     if(error == 0)
+      return true;
+     else
+     {
+      reportError(error);
+      return false;
+     }
    }
    else
    {
-     switch(error)
-     {
-     case LUA_ERRSYNTAX :
-       printf("Syntax error in file %s \n",filename.c_str() );
+     reportError(error);
+   }
 
-     case LUA_ERRMEM :
-       printf("Memory allocation error in file %s", filename.c_str() );
-     }
+   return false;
+ }
+
+ bool Script::executeFile()
+ {
+   int error = lua_pcall(luaState, 0, LUA_MULTRET, 0);
+   if( error== 0)
+     return true;
+   else
+   {
+     reportError(error);
+     return false;
    }
 
  }
 
-
-
  void Script::selectFunction(std::string& functionName, int retCount)
  {
    returnCount = retCount;
+   argumentCount = 0;
    currentFunction = functionName;
    lua_pushlstring(luaState, currentFunction.c_str(), currentFunction.size() );
@@ -57,7 +75,7 @@
 
  //return number of returned values
- int  Script::executeFunction()
+ void Script::executeFunction()
  {
-    lua_call(luaState, argumentCount, returnCount);
+    lua_pcall(luaState, argumentCount, returnCount,0);
  }
 
@@ -66,13 +84,14 @@
  bool Script::pushParam(int param, std::string& toFunction)
  {
-   if(currentFunction.compare(toFunction) != 0)
+   if(currentFunction.compare(toFunction) == 0)
    {
-    lua_pushnumber(luaState,  param);
+     lua_pushnumber(luaState, (lua_Number) param);
+     argumentCount++;
     return true;
    }
    else
    {
-     printf("Couldn't add parameter because the wrong function is selected: %s instead of %s", currentFunction.c_str(), toFunction.c_str());
-     return false;
+    printf("Couldn't add parameter because the wrong function is selected: %s instead of %s\n", currentFunction.c_str(), toFunction.c_str());
+    return false;
    }
 
@@ -82,14 +101,25 @@
  bool Script::pushParam(float param, std::string& toFunction)
  {
-   if(currentFunction.compare(toFunction) != 0)
+   if(currentFunction.compare(toFunction) == 0)
    {
-     lua_pushnumber(luaState, param);
+     lua_pushnumber(luaState,(lua_Number) param);
+     argumentCount++;
      return true;
    }
    else
    {
-     printf("Couldn't add parameter because the wrong function is selected: %s instead of %s", currentFunction.c_str(), toFunction.c_str());
+     printf("Couldn't add parameter because the wrong function is selected: %s instead of %s\n", currentFunction.c_str(), toFunction.c_str());
      return false;
    }
 
  }
+
+ int Script::reportError(int error)
+ {
+ const char *msg = lua_tostring(luaState, -1);
+ if (msg == NULL) msg = "(error with no message)";
+ fprintf(stderr, "ERROR: %s\n", msg);
+ lua_pop(luaState, 1);
+ return error;
+ }
+
Index: branches/script_engine/src/lib/script_engine/Script.h
===================================================================
--- branches/script_engine/src/lib/script_engine/Script.h	(revision 8043)
+++ branches/script_engine/src/lib/script_engine/Script.h	(revision 8044)
@@ -16,9 +16,10 @@
 
     bool loadFile(std::string& filename);
+    bool executeFile();
 
     lua_State* getLuaState() const{return luaState;}
 
     void selectFunction(std::string& functionName, int retCount);
-    int  executeFunction(); //return number of returned values
+    void  executeFunction(); //return number of returned values
     bool pushParam(int param, std::string& toFunction);//overload this function to add different types
     bool pushParam(float param, std::string& toFunction);
@@ -26,5 +27,8 @@
 
 
+
   private:
+
+    int reportError(int error);
 
     lua_State*         luaState;         //!< The lua_State that the Script works on
Index: branches/script_engine/src/lib/script_engine/account.cc
===================================================================
--- branches/script_engine/src/lib/script_engine/account.cc	(revision 8043)
+++ branches/script_engine/src/lib/script_engine/account.cc	(revision 8044)
@@ -1,6 +1,8 @@
-    #include "luaincl.h"
-    #include <iostream>
 
-    #include "lunar.h"
+#include <iostream>
+
+#include "luaincl.h"
+#include "lunar.h"
+#include "Script.h"
 
     class Account {
@@ -11,4 +13,5 @@
 
       Account(lua_State *L)      { m_balance = luaL_checknumber(L, 1); }
+      Account(double balance=0)    : m_balance(balance) { }
       int deposit (lua_State *L) { m_balance += luaL_checknumber(L, 1); return 0; }
       int withdraw(lua_State *L) { m_balance -= luaL_checknumber(L, 1); return 0; }
@@ -36,10 +39,12 @@
 
         Object(lua_State* L) {callCount = 0; }
+        Object(){callCount = 0;};
         ~Object() { printf("deleted Object (%p)\n", this); }
+
 
         int printName(lua_State* L)
         {
+          callCount ++;
           printf("Hi i'm object %p ! This is the %i. call.\n",this,callCount);
-          callCount ++;
           return 0;
         }
@@ -60,24 +65,31 @@
     int main(int argc, char *argv[])
     {
-      lua_State *L = lua_open();
+      Script script;
+      Lunar<Account>::Register(&script);
+      Lunar<Object>::Register(&script);
 
-      luaopen_base(L);
-      luaopen_table(L);
-      luaopen_io(L);
-      luaopen_string(L);
-      luaopen_math(L);
-      luaopen_debug(L);
+      Object* obj= new Object();
+      Account a;
+      Account *b = new Account(30);
 
-      Lunar<Account>::Register(L);
-      Lunar<Object>::Register(L);
+      Lunar<Object>::insertObject(&script,obj,"Obj",true);
+      Lunar<Account>::insertObject(&script,&a,"a",false);
+      Lunar<Account>::insertObject(&script,b,"b",true);
 
-      Object* obj= new Object(L);
-      Lunar<Object>::insertObject(L,obj,"Obj",false);
-      //delete obj;
 
-      if(argc>1) lua_dofile(L, argv[1]);
+      std::string file(argv[1]);
 
-      lua_setgcthreshold(L, 0);  // collected garbage
-      lua_close(L);
+      if(script.loadFile(file))
+        printf("file %s succefully loaded\n", file.c_str());
+
+      //script.executeFile();
+
+      std::string main("main");
+      script.selectFunction(main,1);
+      script.pushParam(3,main);
+      script.executeFunction();
+
+      //if(argc>1) lua_dofile(script.getLuaState(), argv[1]);
+
       return 0;
     }
Index: branches/script_engine/src/lib/script_engine/lunar.h
===================================================================
--- branches/script_engine/src/lib/script_engine/lunar.h	(revision 8043)
+++ branches/script_engine/src/lib/script_engine/lunar.h	(revision 8044)
@@ -136,4 +136,13 @@
       }
 
+
+      static int insertObject(Script* script, T* obj, const std::string& name, bool gc=false)
+      {
+        if(script != NULL)
+          return insertObject(script->getLuaState(), obj, name, gc);
+
+
+      }
+
       // get userdata from Lua stack and return pointer to T object
       static T *check(lua_State *L, int narg) {
Index: branches/script_engine/src/lib/script_engine/lunartest.lua
===================================================================
--- branches/script_engine/src/lib/script_engine/lunartest.lua	(revision 8043)
+++ branches/script_engine/src/lib/script_engine/lunartest.lua	(revision 8044)
@@ -4,4 +4,5 @@
   printf("Account balance = $%0.02f\n", self:balance())
 end
+
 
 o = Object()
@@ -21,7 +22,8 @@
 a:show() a:deposit(50.30) a:show() a:withdraw(25.10) a:show()
 
+
+
 parent = {}
-
-function parent:rob(amount)
+ function parent:rob(amount)
   amount = amount or self:balance()
   self:withdraw(amount)
