Index: /branches/script_engine/src/lib/script_engine/Makefile.am
===================================================================
--- /branches/script_engine/src/lib/script_engine/Makefile.am	(revision 7701)
+++ /branches/script_engine/src/lib/script_engine/Makefile.am	(revision 7702)
@@ -4,29 +4,18 @@
 #noinst_LIBRARIES = libORXscript.a
 
-#libORXscript_a_SOURCES = \
-		LuaCallback.cc \
-		RestoreStack.cc \
-		Script.cc \
-		scriptable.cc\
-		This.cc \
-		VirtualMachine.cc
+#libORXscript_a_SOURCES = 
 
 AM_CPPFLAGS= @LUA_INCLUDES@
 
-#bin_PROGRAMS = main
-#main_SOURCES = \
-		main.cc
-#main_LDADD = libORXscript.a -L../../../extern_libs @LUA_LIBS@
+bin_PROGRAMS = account
+account_SOURCES = \
+		account.cc
+
+
+account_LDADD = libORXscript.a -L../../../extern_libs @LUA_LIBS@
 
 #main_LDFLAGS =
 
 
-#noinst_HEADERS = \
-		LuaCallback.h \
-		RestoreStack.h \
-		Script.h \
-		This.h \
-		VirtualMachine.h \
-		luaincl.h \
-		scriptable.h
-
+noinst_HEADERS = \
+		luna.h
Index: /branches/script_engine/src/lib/script_engine/account.cc
===================================================================
--- /branches/script_engine/src/lib/script_engine/account.cc	(revision 7702)
+++ /branches/script_engine/src/lib/script_engine/account.cc	(revision 7702)
@@ -0,0 +1,103 @@
+#include "luna.h"
+/*extern "C" {
+#include <lualib.h>
+}
+*/
+
+class Account
+{
+public:
+  static const char className[];
+  static const Luna<Account>::RegType Register[];
+
+  Account(lua_State* L)
+  {
+    /* constructor table at top of stack */
+    lua_pushstring(L, "balance");
+    lua_gettable(L, -2);
+    m_balance = lua_tonumber(L, -1);
+    lua_pop(L, 2); /* pop constructor table and balance */
+  }
+
+  int deposit(lua_State* L)
+  {
+    m_balance += lua_tonumber(L, -1);
+    lua_pop(L, 1);
+    return 0;
+  }
+  int withdraw(lua_State* L)
+  {
+    m_balance -= lua_tonumber(L, -1);
+    lua_pop(L, 1);
+    return 0;
+  }
+  int balance(lua_State* L)
+  {
+    lua_pushnumber(L, m_balance);
+    return 1;
+  }
+protected:
+  double m_balance;
+};
+
+const char Account::className[] = "Account";
+const Luna<Account>::RegType Account::Register[] =
+  {
+    {"deposit",  &Account::deposit},
+    {"withdraw", &Account::withdraw},
+    {"balance",  &Account::balance},
+    {0}
+  };
+
+class Euclid
+{
+public:
+  static const char className[];
+  static const Luna<Euclid>::RegType Register[];
+
+  Euclid(lua_State* L)
+  {}
+
+  int gcd(lua_State* L)
+  {
+    int m = static_cast<int>(lua_tonumber(L, -1));
+    int n = static_cast<int>(lua_tonumber(L, -2));
+    lua_pop(L, 2);
+
+    /* precondition: m>0 and n>0.  Let g=gcd(m,n). */
+    while( m > 0 )
+    {
+      /* invariant: gcd(m,n)=g */
+      if( n > m )
+      {
+        int t = m; m = n; n = t; /* swap */
+      }
+      /* m >= n > 0 */
+      m -= n;
+    }
+
+    lua_pushnumber(L, n);
+    return 1;
+  }
+};
+
+const char Euclid::className[] = "Euclid";
+const Luna<Euclid>::RegType Euclid::Register[] =
+  {
+    {"gcd", &Euclid::gcd},
+    {0}
+  };
+
+int main(int argc, char* argv[])
+{
+  lua_State* L = lua_open();
+  lua_baselibopen(L);
+
+  Luna<Account>::Register(L);
+  Luna<Euclid>::Register(L);
+
+  lua_dofile(L, argv[1]);
+
+  lua_close(L);
+  return 0;
+}
Index: /branches/script_engine/src/lib/script_engine/account.lua
===================================================================
--- /branches/script_engine/src/lib/script_engine/account.lua	(revision 7702)
+++ /branches/script_engine/src/lib/script_engine/account.lua	(revision 7702)
@@ -0,0 +1,10 @@
+--
+-- Luna Account example
+--
+local a = Account{balance=100}
+a:deposit(50.00)
+a:withdraw(25.00)
+print("Account balance = $"..a:balance())
+
+local e = Euclid()
+print("Euclid gcd = "..e:gcd(10000,2))
Index: anches/script_engine/src/lib/script_engine/luascript1.lua
===================================================================
--- /branches/script_engine/src/lib/script_engine/luascript1.lua	(revision 7701)
+++ 	(revision )
@@ -1,45 +1,0 @@
-
--- 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/luna.h
===================================================================
--- /branches/script_engine/src/lib/script_engine/luna.h	(revision 7702)
+++ /branches/script_engine/src/lib/script_engine/luna.h	(revision 7702)
@@ -0,0 +1,108 @@
+/*
+ * Lenny Palozzi - lenny.palozzi@home.com
+ */
+
+#include <string>
+
+#include "luaincl.h"
+
+/*extern "C" {
+#include <lua.h>
+}
+*/
+template <class T>
+class Luna
+{
+
+
+ public:
+   /* member function map */
+   struct RegType { 
+      const char* name; 
+      int(T::*mfunc)(lua_State*);
+   };      
+   /* register class T */
+   static void Register(lua_State* L) {
+      lua_pushcfunction(L, &Luna<T>::constructor);
+      lua_setglobal(L, T::className);
+
+     /* if (otag == 0) {
+	otag = lua_newtag(L);
+	lua_pushcfunction(L, &Luna<T>::gc_obj);
+	lua_settagmethod(L, otag, "gc"); /* tm to release objects 
+      }*/
+   }
+
+ private:
+   static int otag; /* object tag */
+   
+   /* member function dispatcher */
+   static int thunk(lua_State* L) {
+      /* stack = closure(-1), [args...], 'self' table(1) */
+      int i = static_cast<int>(lua_tonumber(L,-1));
+      lua_pushnumber(L, 0); /* userdata object at index 0 */
+      lua_gettable(L, 1);
+      T* obj = static_cast<T*>(lua_touserdata(L,-1));
+      lua_pop(L, 2); /* pop closure value and obj */
+      return (obj->*(T::Register[i].mfunc))(L);
+   }
+   
+
+    static int setScriptable(T* obj)
+     {
+     //return registerObject(obj);
+     }
+   
+   static int setScriptable(const std::string& objectName)
+    {
+   #warning 'implement do not use'
+  //   return registerObject(obj);
+    }
+
+   /* constructs T objects */
+   static int constructor(lua_State* L) {
+      T* obj= new T(L); /* new T */
+      return registerObject(obj, L);
+   }
+
+
+   /* releases objects */
+   static int gc_obj(lua_State* L) {
+      T* obj = static_cast<T*>(lua_touserdata(L, -1));
+      delete obj;
+      return 0;
+   }
+ protected: 
+   Luna(); /* hide default constructor */
+
+ private:
+   static int registerObject(T* obj, lua_State* L)
+    {
+      lua_newtable(L); /* new table object */
+      int  objRef = luaL_ref (L, LUA_REGISTRYINDEX);
+      if(lua_getmetatable(L, objRef) != 0)
+       {
+        lua_pushcfunction(L, &Luna<T>::gc_obj);
+//        lua_setfield(L, objRef, "__gc");
+       }
+      
+      lua_pushnumber(L, 0); /* userdata obj at index 0 */
+
+//      lua_pushusertag(L, obj, otag); /* have gc call tm */
+
+      lua_settable(L, -3);
+      
+      /* register the member functions */
+      for (int i=0; T::Register[i].name; i++) {
+	 lua_pushstring(L, T::Register[i].name);
+	 lua_pushnumber(L, i);
+	 lua_pushcclosure(L, &Luna<T>::thunk, 1);
+	 lua_settable(L, -3);
+      }
+      return 1; /* return the table object */
+}
+
+
+};
+template <class T>
+int Luna<T>::otag = 0;
