Index: /branches/script_engine/src/lib/script_engine/luascript1.lua
===================================================================
--- /branches/script_engine/src/lib/script_engine/luascript1.lua	(revision 7656)
+++ /branches/script_engine/src/lib/script_engine/luascript1.lua	(revision 7656)
@@ -0,0 +1,45 @@
+
+-- Tests the parameter passing, using and returning
+function this.divideMe (this, count)
+   trace ("In divideMe...");
+   return count / 30
+end
+
+-- Tests lua calling lua functions
+function this.luaCallMe ()
+   trace( "luaCallMe" )
+end
+
+-- Tests lua calling lua functions
+function object.luaCallMe ()
+   trace( "luaCallMe" )
+end
+
+function this.luaCallMeToo (this)
+   this:hello1 ()
+end
+
+-- Main test routing
+function this.CountAndCall (this, i)
+   --this:luaCallMe ()
+   --this:luaCallMeToo ()
+   object:printNameTwo ()
+   object:printHello ()
+
+   --trace ("CountAndCall")
+
+   while  (i <= 4) do
+     -- this:hello1 ()
+      --this:hello2 (i,i*2)
+      i = i+1
+   end
+
+  -- trace ("Hello, debug world!")
+end
+
+-- Tests the C-Api returning values to lua
+function this.returnToMe (this, i)
+   trace ("returnToMe")
+   x = this:hello3 (i)
+   io.write ("returnToMe ", x)
+end
Index: /branches/script_engine/src/lib/script_engine/main.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/main.cc	(revision 7655)
+++ /branches/script_engine/src/lib/script_engine/main.cc	(revision 7656)
@@ -38,24 +38,24 @@
   //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;
-     }
+  {
+    /*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;
+  }
 
 }
@@ -76,174 +76,173 @@
 
 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 ())
+{
+  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.compare("printNameOne")==0)
     {
-     /* 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);
+      //case 0:
+      return printNameOne (vm);
     }
 
-    return iMethodIdx;
-  }
-
-class objectOne : public Scriptable
-{
-  public:
-    objectOne () : Scriptable ()
+    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.compare("printNameTwo")==0)
     {
-
+      //case 0:
+
+      return printNameTwo (vm);
     }
 
-    int scriptCalling (LuaVirtualMachine& vm, std::string functionName)
+    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)
     {
-      //switch (iFunctionNumber) //- methodBase) uncomment this when methodBase gets correclty set in the Scriptable class
-      if(functionName.compare("printNameOne")==0)
-      {
-        //case 0:
-          return printNameOne (vm);
-      }
-
-      return 0;
+      case 0:
+        return Hello1 (vm);
+      case 1:
+        return Hello2 (vm);
+      case 2:
+        return Hello3 (vm);
     }
 
-
-    int printNameOne(LuaVirtualMachine& 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)
     {
-    std::cout<<"Hi I'm Object 1 !"<<std::endl;
-    return 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);
     }
-
-    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.compare("printNameTwo")==0)
-      {
-        //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;
+  }
+
+protected:
+  int m_iMethodBase;
 };
 
@@ -252,5 +251,5 @@
 {
 
-  std::cout << "lua-testing environment\n" << std::endl;
+  std::cout << "== lua-testing environment ==\n" << std::endl;
 
 
@@ -264,5 +263,5 @@
   //addObjectToScript(&ob1, "obOne", ms, "printNameOne");
   int obTwoRef = ms.addScriptableToScript(&ob2, "object");
- // ms.addFunctionToScriptable("printNameTwo",obTwoRef,-1);
+  // ms.addFunctionToScriptable("printNameTwo",obTwoRef,-1);
 
   ms.compileFile ("luascript1.lua");
