]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-10427: move mod_lua to use swig3.0 so we can reswig on debian9
authorMike Jerris <mike@jerris.com>
Tue, 27 Jun 2017 17:18:21 +0000 (12:18 -0500)
committerMike Jerris <mike@jerris.com>
Tue, 27 Jun 2017 17:18:21 +0000 (12:18 -0500)
src/mod/languages/mod_lua/Makefile.am
src/mod/languages/mod_lua/mod_lua_wrap.cpp

index c9be2f36dd2de8d890728098f22bf780918e337f..86065a5bc50a407c3606f6d1346698061ff3cc39 100644 (file)
@@ -19,7 +19,7 @@ swigclean: clean
        rm -f mod_lua_wrap.*
 
 mod_lua_wrap.cpp: mod_lua_extra.c
-       swig2.0 -lua -c++ -I../../../../src/include -oh mod_lua_wrap.h -o mod_lua_wrap.cpp freeswitch.i
+       swig3.0 -lua -c++ -I../../../../src/include -oh mod_lua_wrap.h -o mod_lua_wrap.cpp freeswitch.i
        echo "#include \"mod_lua_extra.c\"" >> mod_lua_wrap.cpp
        patch -s -p0 -i hack.diff
 
index 5dd9efdf3d986496d2922d277f0edc71928a74fd..ed046632c65bbc1a33641f41695952e44806e0eb 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.12
+ * Version 3.0.2
  *
  * This file is not intended to be easily readable and contains a number of
  * coding conventions designed to improve portability and efficiency. Do not make
@@ -551,14 +551,14 @@ SWIG_MangledTypeQueryModule(swig_module_info *start,
   swig_module_info *iter = start;
   do {
     if (iter->size) {
-      register size_t l = 0;
-      register size_t r = iter->size - 1;
+      size_t l = 0;
+      size_t r = iter->size - 1;
       do {
        /* since l+r >= 0, we can (>> 1) instead (/ 2) */
-       register size_t i = (l + r) >> 1;
+       size_t i = (l + r) >> 1;
        const char *iname = iter->types[i]->name;
        if (iname) {
-         register int compare = strcmp(name, iname);
+         int compare = strcmp(name, iname);
          if (compare == 0) {
            return iter->types[i];
          } else if (compare < 0) {
@@ -602,7 +602,7 @@ SWIG_TypeQueryModule(swig_module_info *start,
        of the str field (the human readable name) */
     swig_module_info *iter = start;
     do {
-      register size_t i = 0;
+      size_t i = 0;
       for (; i < iter->size; ++i) {
        if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name)))
          return iter->types[i];
@@ -621,10 +621,10 @@ SWIG_TypeQueryModule(swig_module_info *start,
 SWIGRUNTIME char *
 SWIG_PackData(char *c, void *ptr, size_t sz) {
   static const char hex[17] = "0123456789abcdef";
-  register const unsigned char *u = (unsigned char *) ptr;
-  register const unsigned char *eu =  u + sz;
+  const unsigned char *u = (unsigned char *) ptr;
+  const unsigned char *eu =  u + sz;
   for (; u != eu; ++u) {
-    register unsigned char uu = *u;
+    unsigned char uu = *u;
     *(c++) = hex[(uu & 0xf0) >> 4];
     *(c++) = hex[uu & 0xf];
   }
@@ -636,11 +636,11 @@ SWIG_PackData(char *c, void *ptr, size_t sz) {
 */
 SWIGRUNTIME const char *
 SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
-  register unsigned char *u = (unsigned char *) ptr;
-  register const unsigned char *eu = u + sz;
+  unsigned char *u = (unsigned char *) ptr;
+  const unsigned char *eu = u + sz;
   for (; u != eu; ++u) {
-    register char d = *(c++);
-    register unsigned char uu;
+    char d = *(c++);
+    unsigned char uu;
     if ((d >= '0') && (d <= '9'))
       uu = ((d - '0') << 4);
     else if ((d >= 'a') && (d <= 'f'))
@@ -747,23 +747,110 @@ extern "C" {
 # error SWIG_LUA_TARGET not defined
 #endif
 
+#if defined(SWIG_LUA_ELUA_EMULATE)
+
+struct swig_elua_entry;
+
+typedef struct swig_elua_key {
+  int type;
+  union {
+    const char* strkey;
+    lua_Number numkey;
+  } key;
+} swig_elua_key;
+
+typedef struct swig_elua_val {
+  int type;
+  union {
+    lua_Number number;
+    const struct swig_elua_entry *table;
+    const char *string;
+    lua_CFunction function;
+    struct {
+      char member;
+      long lvalue;
+      void *pvalue;
+      swig_type_info **ptype;
+    } userdata;
+  } value;
+} swig_elua_val;
+
+typedef struct swig_elua_entry {
+  swig_elua_key key;
+  swig_elua_val value;
+} swig_elua_entry;
+
+#define LSTRKEY(x) {LUA_TSTRING, {.strkey = x} }
+#define LNUMKEY(x) {LUA_TNUMBER, {.numkey = x} }
+#define LNILKEY {LUA_TNIL, {.strkey = 0} }
+
+#define LNUMVAL(x) {LUA_TNUMBER, {.number = x} }
+#define LFUNCVAL(x) {LUA_TFUNCTION, {.function = x} }
+#define LROVAL(x) {LUA_TTABLE, {.table = x} }
+#define LNILVAL {LUA_TNIL, {.string = 0} }
+#define LSTRVAL(x) {LUA_TSTRING, {.string = x} }
+
+#define LUA_REG_TYPE swig_elua_entry
+
+#define SWIG_LUA_ELUA_EMUL_METATABLE_KEY "__metatable"
+
+#define lua_pushrotable(L,p)\
+  lua_newtable(L);\
+  assert(p);\
+  SWIG_Lua_elua_emulate_register(L,(swig_elua_entry*)(p));
+
+#define SWIG_LUA_CONSTTAB_POINTER(B,C,D)\
+  LSTRKEY(B), {LUA_TUSERDATA, { .userdata={0,0,(void*)(C),&D} } }
+
+#define SWIG_LUA_CONSTTAB_BINARY(B,S,C,D)\
+  LSTRKEY(B), {LUA_TUSERDATA, { .userdata={1,S,(void*)(C),&D} } }
+#endif
+
 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
 #  define SWIG_LUA_CONSTTAB_INT(B, C) LSTRKEY(B), LNUMVAL(C)
 #  define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C)
 #  define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C)
 #  define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C)
+    /* Those two types of constants are not supported in elua */
+
+#ifndef SWIG_LUA_CONSTTAB_POINTER
+#warning eLua does not support pointers as constants. By default, nil will be used as value
+#define SWIG_LUA_CONSTTAB_POINTER(B,C,D) LSTRKEY(B), LNILVAL
+#endif
+
+#ifndef SWIG_LUA_CONSTTAB_BINARY
+#warning eLua does not support pointers to member as constants. By default, nil will be used as value
+#define SWIG_LUA_CONSTTAB_BINARY(B, S, C, D) LSTRKEY(B), LNILVAL
+#endif
 #else /* SWIG_LUA_FLAVOR_LUA */
 #  define SWIG_LUA_CONSTTAB_INT(B, C) SWIG_LUA_INT, (char *)B, (long)C, 0, 0, 0
 #  define SWIG_LUA_CONSTTAB_FLOAT(B, C) SWIG_LUA_FLOAT, (char *)B, 0, (double)C, 0, 0
 #  define SWIG_LUA_CONSTTAB_STRING(B, C) SWIG_LUA_STRING, (char *)B, 0, 0, (void *)C, 0
 #  define SWIG_LUA_CONSTTAB_CHAR(B, C) SWIG_LUA_CHAR, (char *)B, (long)C, 0, 0, 0
+#  define SWIG_LUA_CONSTTAB_POINTER(B,C,D)\
+       SWIG_LUA_POINTER, (char *)B, 0, 0, (void *)C, &D
+#  define SWIG_LUA_CONSTTAB_BINARY(B, S, C, D)\
+       SWIG_LUA_BINARY,  (char *)B, S, 0, (void *)C, &D
 #endif
 
+#ifndef SWIG_LUA_ELUA_EMULATE
 #if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
 #  define LRO_STRVAL(v) {{.p = (char *) v}, LUA_TSTRING}
 #  define LSTRVAL LRO_STRVAL
 #endif
+#endif /* SWIG_LUA_ELUA_EMULATE*/
 
+#ifndef SWIG_LUA_ELUA_EMULATE
+#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
+
+#ifndef MIN_OPT_LEVEL
+#define MIN_OPT_LEVEL 2
+#endif
+
+#include "lrodefs.h"
+#include "lrotable.h"
+#endif
+#endif /* SWIG_LUA_ELUA_EMULATE*/
 /* -----------------------------------------------------------------------------
  * compatibility defines
  * ----------------------------------------------------------------------------- */
@@ -790,6 +877,23 @@ extern "C" {
 # define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
 #endif
 
+/* lua_absindex was introduced in Lua 5.2 */
+#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
+# define lua_absindex(L,i) ((i)>0 || (i) <= LUA_REGISTRYINDEX ? (i) : lua_gettop(L) + (i) + 1)
+#endif
+
+/* lua_rawsetp was introduced in Lua 5.2 */
+#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
+#define lua_rawsetp(L,index,ptr)\
+  lua_pushlightuserdata(L,(void*)(ptr));\
+  lua_insert(L,-2);\
+  lua_rawset(L,index);
+
+#define lua_rawgetp(L,index,ptr)\
+  lua_pushlightuserdata(L,(void*)(ptr));\
+  lua_rawget(L,index);
+
+#endif
 
 /* --------------------------------------------------------------------------
  * Helper functions for error handling
@@ -839,6 +943,12 @@ typedef struct {
   lua_CFunction set;
 } swig_lua_var_info;
 
+#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
+typedef const LUA_REG_TYPE swig_lua_method;
+typedef const LUA_REG_TYPE swig_lua_const_info;
+#else /* Normal lua */
+typedef luaL_Reg swig_lua_method;
+
 /* Constant information structure */
 typedef struct {
     int type;
@@ -849,10 +959,7 @@ typedef struct {
     swig_type_info **ptype;
 } swig_lua_const_info;
 
-typedef struct {
-  const char     *name;
-  lua_CFunction   method;
-} swig_lua_method;
+#endif
 
 typedef struct {
   const char     *name;
@@ -860,23 +967,28 @@ typedef struct {
   lua_CFunction   setmethod;
 } swig_lua_attribute;
 
-// Can be used to create namespaces. Currently used to
-// wrap class static methods/variables/constants
-typedef struct {
+
+struct swig_lua_class;
+/* Can be used to create namespaces. Currently used to wrap class static methods/variables/constants */
+typedef struct swig_lua_namespace {
   const char            *name;
   swig_lua_method       *ns_methods;
   swig_lua_attribute    *ns_attributes;
   swig_lua_const_info   *ns_constants;
+  struct swig_lua_class        **ns_classes;
+  struct swig_lua_namespace    **ns_namespaces;
 } swig_lua_namespace;
 
 typedef struct swig_lua_class {
-  const char    *name;
+  const char    *name; /* Name that this class has in Lua */
+  const char    *fqname; /* Fully qualified name - Scope + class name */
   swig_type_info   **type;
   lua_CFunction  constructor;
   void    (*destructor)(void *);
   swig_lua_method   *methods;
   swig_lua_attribute     *attributes;
-  swig_lua_namespace    cls_static;
+  swig_lua_namespace    *cls_static;
+  swig_lua_method   *metatable; /* 0 for -eluac */
   struct swig_lua_class **bases;
   const char **base_names;
 } swig_lua_class;
@@ -940,18 +1052,23 @@ typedef struct {
       lua_pushcfunction(L, f), \
       lua_rawset(L,-3))
 
+#define SWIG_Lua_add_boolean(L,n,b) \
+  (lua_pushstring(L, n), \
+      lua_pushboolean(L, b), \
+      lua_rawset(L,-3))
+
 /* special helper for allowing 'nil' for usertypes */
 #define SWIG_isptrtype(L,I) (lua_isuserdata(L,I) || lua_isnil(L,I))
 
 #ifdef __cplusplus
 /* Special helper for member function pointers 
 it gets the address, casts it, then dereferences it */
-//#define SWIG_mem_fn_as_voidptr(a)  (*((char**)&(a)))
+/*#define SWIG_mem_fn_as_voidptr(a)  (*((char**)&(a))) */
 #endif
 
 /* storing/access of swig_module_info */
 SWIGRUNTIME swig_module_info *
-SWIG_Lua_GetModule(lua_StateL) {
+SWIG_Lua_GetModule(lua_State *L) {
   swig_module_info *ret = 0;
   lua_pushstring(L,"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
   lua_rawget(L,LUA_REGISTRYINDEX);
@@ -962,7 +1079,7 @@ SWIG_Lua_GetModule(lua_State* L) {
 }
 
 SWIGRUNTIME void
-SWIG_Lua_SetModule(lua_StateL, swig_module_info *module) {
+SWIG_Lua_SetModule(lua_State *L, swig_module_info *module) {
   /* add this all into the Lua registry: */
   lua_pushstring(L,"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
   lua_pushlightuserdata(L,(void*)module);
@@ -976,7 +1093,7 @@ SWIG_Lua_SetModule(lua_State* L, swig_module_info *module) {
 /* this function is called when trying to set an immutable.
 default action is to print an error.
 This can removed with a compile flag SWIGLUA_IGNORE_SET_IMMUTABLE */
-SWIGINTERN int SWIG_Lua_set_immutable(lua_StateL)
+SWIGINTERN int SWIG_Lua_set_immutable(lua_State *L)
 {
 /*  there should be 1 param passed in: the new value */
 #ifndef SWIGLUA_IGNORE_SET_IMMUTABLE
@@ -986,170 +1103,153 @@ SWIGINTERN int SWIG_Lua_set_immutable(lua_State* L)
     return 0;   /* should not return anything */
 }
 
-/* the module.get method used for getting linked data */
-SWIGINTERN int SWIG_Lua_module_get(lua_State* L)
-{
-/*  there should be 2 params passed in
-  (1) table (not the meta table)
-  (2) string name of the attribute
-  printf("SWIG_Lua_module_get %p(%s) '%s'\n",
-   lua_topointer(L,1),lua_typename(L,lua_type(L,1)),
-   lua_tostring(L,2));
-*/
-  /* get the metatable */
-#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
-  assert(lua_isrotable(L,1)); /* just in case */
-#else
-  assert(lua_istable(L,1)); /* default Lua action */
-#endif
-  lua_getmetatable(L,1);  /* get the metatable */
-#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
-  assert(lua_isrotable(L,-1));  /* just in case */
-#else
-  assert(lua_istable(L,-1));
-#endif
-  SWIG_Lua_get_table(L,".get");  /* get the .get table */
-  lua_remove(L,3);  /* remove metatable */
-#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
-  if (lua_isrotable(L,-1))
-#else
-  if (lua_istable(L,-1))
-#endif
-  {
-    /* look for the key in the .get table */
-    lua_pushvalue(L,2);  /* key */
-    lua_rawget(L,-2);
-    lua_remove(L,3);  /* remove .get */
-    if (lua_iscfunction(L,-1))
-    {  /* found it so call the fn & return its value */
-      lua_call(L,0,1);
-      return 1;
-    }
-    lua_pop(L,1);  /* remove the top */
-  }
-  lua_pop(L,1);  /* remove the .get */
-  lua_pushnil(L);  /* return a nil */
-  return 1;
-}
+#ifdef SWIG_LUA_ELUA_EMULATE
+
+SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *type, int own);
+SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_type_info *type);
+static int swig_lua_elua_emulate_unique_key;
 
-/* the module.set method used for setting linked data */
-SWIGINTERN int SWIG_Lua_module_set(lua_State* L)
+/* This function emulates eLua rotables behaviour. It loads a rotable definition into the usual lua table. */
+SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_entry *table)
 {
-/*  there should be 3 params passed in
-  (1) table (not the meta table)
-  (2) string name of the attribute
-  (3) any for the new value
-*/
-  /* get the metatable */
-#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
-  assert(lua_isrotable(L,1));  /* just in case */
-#else
-  assert(lua_istable(L,1)); /* default Lua action */
-#endif
-  lua_getmetatable(L,1);  /* get the metatable */
-#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
-  assert(lua_isrotable(L,-1));  /* just in case */
-#else
+  int i, table_parsed, parsed_tables_array, target_table;
   assert(lua_istable(L,-1));
-#endif
-  SWIG_Lua_get_table(L,".set");  /* get the .set table */
-  lua_remove(L,4);  /* remove metatable */
-#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
-  if (lua_isrotable(L,-1))
-#else
-  if (lua_istable(L,-1))
-#endif
+  target_table = lua_gettop(L);
+  /* Get the registry where we put all parsed tables to avoid loops */
+  lua_rawgetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key);
+  if(lua_isnil(L,-1)) {
+    lua_pop(L,1);
+    lua_newtable(L);
+    lua_pushvalue(L,-1);
+    lua_rawsetp(L,LUA_REGISTRYINDEX,(void*)(&swig_lua_elua_emulate_unique_key));
+  }
+  parsed_tables_array = lua_gettop(L);
+  lua_pushvalue(L,target_table);
+  lua_rawsetp(L, parsed_tables_array, table);
+  table_parsed = 0;
+  const int SWIGUNUSED pairs_start = lua_gettop(L);
+  for(i = 0;table[i].key.type != LUA_TNIL || table[i].value.type != LUA_TNIL;i++)
   {
-    /* look for the key in the .set table */
-    lua_pushvalue(L,2);  /* key */
-    lua_rawget(L,-2);
-    lua_remove(L,4);  /* remove .set */
-    if (lua_iscfunction(L,-1))
-    {  /* found it so call the fn & return its value */
-      lua_pushvalue(L,3);  /* value */
-      lua_call(L,1,0);
-      return 0;
+    const swig_elua_entry *entry = table + i;
+    int is_metatable = 0;
+    switch(entry->key.type) {
+      case LUA_TSTRING:
+        lua_pushstring(L,entry->key.key.strkey);
+        if(strcmp(entry->key.key.strkey, SWIG_LUA_ELUA_EMUL_METATABLE_KEY) == 0)
+          is_metatable = 1;
+        break;
+      case  LUA_TNUMBER:
+        lua_pushnumber(L,entry->key.key.numkey);
+        break;
+      case LUA_TNIL:
+        lua_pushnil(L);
+        break;
+      default:
+        assert(0);
     }
-#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) 
-    else {
-      return 0; // Exits stoically if an invalid key is initialized.
+    switch(entry->value.type) {
+      case LUA_TSTRING:
+        lua_pushstring(L,entry->value.value.string);
+        break;
+      case  LUA_TNUMBER:
+        lua_pushnumber(L,entry->value.value.number);
+        break;
+      case LUA_TFUNCTION:
+        lua_pushcfunction(L,entry->value.value.function);
+        break;
+      case LUA_TTABLE:
+        lua_rawgetp(L,parsed_tables_array, entry->value.value.table);
+        table_parsed = !lua_isnil(L,-1);
+        if(!table_parsed) {
+          lua_pop(L,1); /*remove nil */
+          lua_newtable(L);
+          SWIG_Lua_elua_emulate_register(L,entry->value.value.table);
+        } 
+        if(is_metatable) {
+          assert(lua_istable(L,-1));
+          lua_pushvalue(L,-1);
+          lua_setmetatable(L,target_table);
+        }
+
+        break;
+      case LUA_TUSERDATA:
+        if(entry->value.value.userdata.member) 
+          SWIG_NewMemberObj(L,entry->value.value.userdata.pvalue,
+              entry->value.value.userdata.lvalue,
+              *(entry->value.value.userdata.ptype));
+        else 
+          SWIG_NewPointerObj(L,entry->value.value.userdata.pvalue,
+              *(entry->value.value.userdata.ptype),0);
+        break;
+      case LUA_TNIL:
+        lua_pushnil(L);
+        break;
+      default:
+        assert(0);
     }
-#endif
+    assert(lua_gettop(L) == pairs_start + 2);
+    lua_rawset(L,target_table);
   }
-  lua_settop(L,3);  /* reset back to start */
-  /* we now have the table, key & new value, so just set directly */
-  lua_rawset(L,1);  /* add direct */
-  return 0;
+  lua_pop(L,1); /* Removing parsed tables storage */
+  assert(lua_gettop(L) == target_table);
 }
 
-#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
-/* registering a module in lua. Pushes the module table on the stack. */
-SWIGINTERN void  SWIG_Lua_module_begin(lua_State* L,const char* name)
+SWIGINTERN void SWIG_Lua_elua_emulate_register_clear(lua_State *L)
 {
-  assert(lua_istable(L,-1));  /* just in case */
-  lua_pushstring(L,name);
-  lua_newtable(L);   /* the table */
-  /* add meta table */
-  lua_newtable(L);    /* the meta table */
-  SWIG_Lua_add_function(L,"__index",SWIG_Lua_module_get);
-  SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_module_set);
-  lua_pushstring(L,".get");
-  lua_newtable(L);    /* the .get table */
-  lua_rawset(L,-3);  /* add .get into metatable */
-  lua_pushstring(L,".set");
-  lua_newtable(L);    /* the .set table */
-  lua_rawset(L,-3);  /* add .set into metatable */
-  lua_setmetatable(L,-2);  /* sets meta table in module */
-#ifdef SWIG_LUA_MODULE_GLOBAL
-  /* If requested, install the module directly into the global namespace. */
-  lua_rawset(L,-3);        /* add module into parent */
-  SWIG_Lua_get_table(L,name);   /* get the table back out */
-#else
-  /* Do not install the module table as global name. The stack top has
-     the module table with the name below. We pop the top and replace
-     the name with it. */
-  lua_replace(L,-2);
-#endif
+  lua_pushnil(L);
+  lua_rawsetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key);
 }
 
-/* ending the register */
-SWIGINTERN void  SWIG_Lua_module_end(lua_State* L)
-{
-  lua_pop(L,1);       /* tidy stack (remove module) */
-}
+SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L);
 
-/* adding a linked variable to the module */
-SWIGINTERN void SWIG_Lua_module_add_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn)
+SWIGINTERN int SWIG_Lua_emulate_elua_getmetatable(lua_State *L)
 {
-  assert(lua_istable(L,-1));  /* just in case */
-  lua_getmetatable(L,-1);  /* get the metatable */
-  assert(lua_istable(L,-1));  /* just in case */
-  SWIG_Lua_get_table(L,".get"); /* find the .get table */
-  assert(lua_istable(L,-1));  /* should be a table: */
-  SWIG_Lua_add_function(L,name,getFn);
-  lua_pop(L,1);       /* tidy stack (remove table) */
-  if (setFn)  /* if there is a set fn */
-  {
-    SWIG_Lua_get_table(L,".set"); /* find the .set table */
-    assert(lua_istable(L,-1));  /* should be a table: */
-    SWIG_Lua_add_function(L,name,setFn);
-    lua_pop(L,1);       /* tidy stack (remove table) */
+  SWIG_check_num_args("getmetatable(SWIG eLua emulation)", 1, 1);
+  SWIG_Lua_get_class_registry(L);
+  lua_getfield(L,-1,"lua_getmetatable");
+  lua_remove(L,-2); /* remove the registry*/
+  assert(!lua_isnil(L,-1));
+  lua_pushvalue(L,1);
+  assert(lua_gettop(L) == 3); /* object | function | object again */
+  lua_call(L,1,1);
+  if(!lua_isnil(L,-1)) /*There is an ordinary metatable */
+    return 1;
+  /*if it is a table, then emulate elua behaviour - check for __metatable attribute of a table*/
+  assert(lua_gettop(L) == 2);
+  if(lua_istable(L,-2)) {
+    lua_pop(L,1); /*remove the nil*/
+    lua_getfield(L,-1, SWIG_LUA_ELUA_EMUL_METATABLE_KEY);
   }
-  lua_pop(L,1);       /* tidy stack (remove meta) */
+  assert(lua_gettop(L) == 2);
+  return 1;
+  
+fail:
+  lua_error(L);
+  return 0;
 }
-#endif
 
-/* adding a function module */
-SWIGINTERN void  SWIG_Lua_module_add_function(lua_State* L,const char* name,lua_CFunction fn)
+SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L)
 {
-  SWIG_Lua_add_function(L,name,fn);
+  SWIG_Lua_get_class_registry(L);
+  lua_pushglobaltable(L);
+  lua_pushstring(L,"lua_getmetatable");
+  lua_getfield(L,-2,"getmetatable");
+  assert(!lua_isnil(L,-1));
+  lua_rawset(L,-4);
+  lua_pushstring(L, "getmetatable");
+  lua_pushcfunction(L, SWIG_Lua_emulate_elua_getmetatable);
+  lua_rawset(L,-3);
+  lua_pop(L,2);
+      
 }
+/* END OF REMOVE */
 
+#endif
 /* -----------------------------------------------------------------------------
- * global variable support code: namespaces
+ * global variable support code: namespaces and modules (which are the same thing)
  * ----------------------------------------------------------------------------- */
 
-SWIGINTERN int SWIG_Lua_namespace_get(lua_StateL)
+SWIGINTERN int SWIG_Lua_namespace_get(lua_State *L)
 {
 /*  there should be 2 params passed in
   (1) table (not the meta table)
@@ -1186,7 +1286,7 @@ SWIGINTERN int SWIG_Lua_namespace_get(lua_State* L)
   return 0;
 }
 
-SWIGINTERN int SWIG_Lua_namespace_set(lua_StateL)
+SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L)
 {
 /*  there should be 3 params passed in
   (1) table (not the meta table)
@@ -1213,46 +1313,70 @@ SWIGINTERN int SWIG_Lua_namespace_set(lua_State* L)
     lua_pop(L,1);  /* remove the value */
   }
   lua_pop(L,1);  /* remove the value .set table */
+  lua_pop(L,1); /* remote metatable */
+  lua_rawset(L,-3);
   return 0;
 }
 
-SWIGINTERN void SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]); // forward declaration
-SWIGINTERN void  SWIG_Lua_add_class_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn); // forward declaration
+#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* In elua this is useless */
+SWIGINTERN void SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]); /* forward declaration */
+SWIGINTERN void  SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn); /* forward declaration */
+SWIGINTERN void  SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss);
 
 /* helper function - register namespace methods and attributes into namespace */
-SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State* L, swig_lua_namespace* ns)
+SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace *ns)
 {
-  int i = 0;
+  int i;
+  /* There must be namespace table (not metatable) at the top of the stack */
   assert(lua_istable(L,-1));
-  /* There must be table at the top of the stack */
   SWIG_Lua_InstallConstants(L, ns->ns_constants);
 
+  /* add methods to the namespace/module table */
+  for(i=0;ns->ns_methods[i].name;i++){
+    SWIG_Lua_add_function(L,ns->ns_methods[i].name,ns->ns_methods[i].func);
+  }
   lua_getmetatable(L,-1);
 
   /* add fns */
   for(i=0;ns->ns_attributes[i].name;i++){
-    SWIG_Lua_add_class_variable(L,ns->ns_attributes[i].name,ns->ns_attributes[i].getmethod,ns->ns_attributes[i].setmethod);
-  }
-
-  /* add methods to the metatable */
-  SWIG_Lua_get_table(L,".fn"); /* find the .fn table */
-  assert(lua_istable(L,-1));  /* just in case */
-  for(i=0;ns->ns_methods[i].name;i++){
-    SWIG_Lua_add_function(L,ns->ns_methods[i].name,ns->ns_methods[i].method);
+    SWIG_Lua_add_variable(L,ns->ns_attributes[i].name,ns->ns_attributes[i].getmethod,ns->ns_attributes[i].setmethod);
   }
-  lua_pop(L,1);
 
   /* clear stack - remove metatble */
   lua_pop(L,1);
   return 0;
 }
 
-/* helper function. creates namespace table and add it to module table */
-SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns)
+/* Register all classes in the namespace */
+SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace *ns)
+{
+  swig_lua_class **classes;
+
+  /* There must be a module/namespace table at the top of the stack */
+  assert(lua_istable(L,-1));
+
+  classes = ns->ns_classes;
+
+  if( classes != 0 ) {
+    while(*classes != 0) {
+      SWIG_Lua_class_register(L, *classes);
+      classes++;
+    }
+  }
+}
+
+/* Helper function. Creates namespace table and adds it to module table
+   if 'reg' is true, then will register namespace table to parent one (must be on top of the stack
+   when function is called).
+   Function always returns newly registered table on top of the stack.
+*/
+SWIGINTERN void SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, int reg)
 {
-  assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table */
+  swig_lua_namespace **sub_namespace;
+  /* 1 argument - table on the top of the stack */
+  const int SWIGUNUSED begin = lua_gettop(L);
+  assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table or parent namespace table */
   lua_checkstack(L,5);
-  lua_pushstring(L, ns->name);
   lua_newtable(L); /* namespace itself */
   lua_newtable(L); /* metatable for namespace */
 
@@ -1274,47 +1398,179 @@ SWIGINTERN int SWIG_Lua_namespace_register(lua_State* L, swig_lua_namespace* ns)
   SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_namespace_set);
 
   lua_setmetatable(L,-2); /* set metatable */
-  lua_rawset(L,-3); /* add namespace to module table */
-  return 0;
+
+  /* Register all functions, variables etc */
+  SWIG_Lua_add_namespace_details(L,ns);
+  /* Register classes */
+  SWIG_Lua_add_namespace_classes(L,ns);
+
+  sub_namespace = ns->ns_namespaces;
+  if( sub_namespace != 0) {
+    while(*sub_namespace != 0) {
+      SWIG_Lua_namespace_register(L, *sub_namespace, 1);
+      lua_pop(L,1); /* removing sub-namespace table */
+      sub_namespace++;
+    }
+  }
+
+  if (reg) {
+    lua_pushstring(L,ns->name);
+    lua_pushvalue(L,-2);
+    lua_rawset(L,-4); /* add namespace to module table */
+  }
+  assert(lua_gettop(L) == begin+1);
 }
+#endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */
+
 /* -----------------------------------------------------------------------------
  * global variable support code: classes
  * ----------------------------------------------------------------------------- */
 
-/* the class.get method, performs the lookup of class attributes */
-SWIGINTERN int  SWIG_Lua_class_get(lua_State* L)
+SWIGINTERN void  SWIG_Lua_get_class_metatable(lua_State *L,const char *cname);
+
+typedef int (*swig_lua_base_iterator_func)(lua_State*,swig_type_info*, int, int *ret);
+
+SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info * SWIGUNUSED swig_type,
+  int first_arg, swig_lua_base_iterator_func func, int  *const ret)
+{
+    /* first_arg - position of the object in stack. Everything that is above are arguments
+     * and is passed to every evocation of the func */
+    int last_arg = lua_gettop(L);/* position of last argument */
+    int original_metatable = last_arg + 1;
+    size_t bases_count;
+    int result = SWIG_ERROR;
+    int bases_table;
+    (void)swig_type;
+    lua_getmetatable(L,first_arg);
+
+    /* initialise base search */
+#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
+    SWIG_Lua_get_table(L,".bases");
+    assert(lua_istable(L,-1));
+    bases_count = lua_rawlen(L,-1);
+    bases_table = lua_gettop(L);
+#else
+    /* In elua .bases table doesn't exist. Use table from swig_lua_class */
+    (void)bases_table;
+    assert(swig_type!=0);
+    swig_module_info *module=SWIG_GetModule(L);
+    swig_lua_class **bases= ((swig_lua_class*)(swig_type->clientdata))->bases;
+    const char **base_names= ((swig_lua_class*)(swig_type->clientdata))->base_names;
+    bases_count = 0;
+    for(;base_names[bases_count];
+      bases_count++);/* get length of bases */
+#endif
+
+    if(ret)
+      *ret = 0;
+    if(bases_count>0)
+    {
+      int to_remove;
+      size_t i;
+      int j;
+      int subcall_last_arg;
+      int subcall_first_arg = lua_gettop(L) + 1;/* Here a copy of first_arg and arguments begin */
+      int valid = 1;
+      swig_type_info *base_swig_type = 0;
+      for(j=first_arg;j<=last_arg;j++)
+        lua_pushvalue(L,j);
+      subcall_last_arg = lua_gettop(L);
+
+      /* Trick: temporarily replacing original metatable with metatable for base class and call getter */
+      for(i=0;i<bases_count;i++) {
+        /* Iteration through class bases */
+#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
+        lua_rawgeti(L,bases_table,i+1);
+        base_swig_type = 0;
+        if(lua_isnil(L,-1)) {
+          valid = 0;
+          lua_pop(L,1);
+        } else {
+          valid = 1;
+        }
+#else /* In elua .bases table doesn't exist. Use table from swig_lua_class */
+        swig_lua_class *base_class = bases[i];
+        if(!base_class) {
+          valid = 0;
+        } else {
+          valid = 1;
+          SWIG_Lua_get_class_metatable(L,base_class->fqname);
+          base_swig_type = SWIG_TypeQueryModule(module,module,base_names[i]);
+          assert(base_swig_type != 0);
+        }
+#endif
+
+        if(!valid)
+          continue;
+        assert(lua_isuserdata(L, subcall_first_arg));
+        assert(lua_istable(L,-1));
+        lua_setmetatable(L,subcall_first_arg); /* Set new metatable */
+        assert(lua_gettop(L) == subcall_last_arg);
+        result = func(L, base_swig_type,subcall_first_arg, ret); /* Forward call */
+        if(result != SWIG_ERROR) {
+          break;
+        }
+      }
+      /* Restore original metatable */
+      lua_pushvalue(L,original_metatable);
+      lua_setmetatable(L,first_arg);
+      /* Clear - remove everything between last_arg and subcall_last_arg including */
+      to_remove = subcall_last_arg - last_arg;
+      for(j=0;j<to_remove;j++)
+        lua_remove(L,last_arg+1);
+    } else {
+      /* Remove everything after last_arg */
+      lua_pop(L, lua_gettop(L) - last_arg);
+    }
+    if(ret) assert(lua_gettop(L) == last_arg + *ret);
+    return result;
+}
+
+/* The class.get method helper, performs the lookup of class attributes.
+ * It returns an error code. Number of function return values is passed inside 'ret'.
+ * first_arg is not used in this function because function always has 2 arguments.
+ */
+SWIGINTERN int  SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SWIGUNUSED first_arg, int *ret)
 {
 /*  there should be 2 params passed in
   (1) userdata (not the meta table)
   (2) string name of the attribute
 */
+  int bases_search_result;
+  int substack_start = lua_gettop(L)-2;
+  assert(first_arg == substack_start+1);
+  lua_checkstack(L,5);
   assert(lua_isuserdata(L,-2));  /* just in case */
   lua_getmetatable(L,-2);    /* get the meta table */
   assert(lua_istable(L,-1));  /* just in case */
   SWIG_Lua_get_table(L,".get"); /* find the .get table */
   assert(lua_istable(L,-1));  /* just in case */
   /* look for the key in the .get table */
-  lua_pushvalue(L,2);  /* key */
+  lua_pushvalue(L,substack_start+2);  /* key */
   lua_rawget(L,-2);
   lua_remove(L,-2); /* stack tidy, remove .get table */
   if (lua_iscfunction(L,-1))
   {  /* found it so call the fn & return its value */
-    lua_pushvalue(L,1);  /* the userdata */
+    lua_pushvalue(L,substack_start+1);  /* the userdata */
     lua_call(L,1,1);  /* 1 value in (userdata),1 out (result) */
     lua_remove(L,-2); /* stack tidy, remove metatable */
-    return 1;
+    if(ret)
+      *ret = 1;
+    return SWIG_OK;
   }
   lua_pop(L,1);  /* remove whatever was there */
   /* ok, so try the .fn table */
-  SWIG_Lua_get_table(L,".fn"); /* find the .get table */
+  SWIG_Lua_get_table(L,".fn"); /* find the .fn table */
   assert(lua_istable(L,-1));  /* just in case */
-  lua_pushvalue(L,2);  /* key */
+  lua_pushvalue(L,substack_start+2);  /* key */
   lua_rawget(L,-2);  /* look for the fn */
   lua_remove(L,-2); /* stack tidy, remove .fn table */
   if (lua_isfunction(L,-1)) /* note: if its a C function or lua function */
   {  /* found it so return the fn & let lua call it */
     lua_remove(L,-2); /* stack tidy, remove metatable */
-    return 1;
+    if(ret)
+      *ret = 1;
+    return SWIG_OK;
   }
   lua_pop(L,1);  /* remove whatever was there */
   /* NEW: looks for the __getitem() fn
@@ -1322,69 +1578,139 @@ SWIGINTERN int  SWIG_Lua_class_get(lua_State* L)
   SWIG_Lua_get_table(L,"__getitem"); /* find the __getitem fn */
   if (lua_iscfunction(L,-1))  /* if its there */
   {  /* found it so call the fn & return its value */
-    lua_pushvalue(L,1);  /* the userdata */
-    lua_pushvalue(L,2);  /* the parameter */
+    lua_pushvalue(L,substack_start+1);  /* the userdata */
+    lua_pushvalue(L,substack_start+2);  /* the parameter */
     lua_call(L,2,1);  /* 2 value in (userdata),1 out (result) */
     lua_remove(L,-2); /* stack tidy, remove metatable */
-    return 1;
+    if(ret) *ret = 1;
+    return SWIG_OK;
   }
-  return 0;  /* sorry not known */
+  lua_pop(L,1);
+  /* Remove the metatable */
+  lua_pop(L,1);
+  /* Search in base classes */
+  bases_search_result = SWIG_Lua_iterate_bases(L,type,substack_start+1,SWIG_Lua_class_do_get,ret);
+  return bases_search_result;  /* sorry not known */
+}
+
+/* the class.get method, performs the lookup of class attributes
+ */
+SWIGINTERN int  SWIG_Lua_class_get(lua_State *L)
+{
+/*  there should be 2 params passed in
+  (1) userdata (not the meta table)
+  (2) string name of the attribute
+*/
+  int result;
+  swig_lua_userdata *usr;
+  swig_type_info *type;
+  int ret = 0;
+  assert(lua_isuserdata(L,1));
+  usr=(swig_lua_userdata*)lua_touserdata(L,1);  /* get data */
+  type = usr->type;
+  result = SWIG_Lua_class_do_get(L,type,1,&ret);
+  if(result == SWIG_OK)
+    return ret;
+
+  return 0;
 }
 
-/* the class.set method, performs the lookup of class attributes */
-SWIGINTERN int  SWIG_Lua_class_set(lua_State* L)
+/* helper for the class.set method, performs the lookup of class attributes
+ * It returns error code. Number of function return values is passed inside 'ret'
+ */
+SWIGINTERN int  SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int first_arg, int *ret)
 {
 /*  there should be 3 params passed in
   (1) table (not the meta table)
   (2) string name of the attribute
   (3) any for the new value
-printf("SWIG_Lua_class_set %p(%s) '%s' %p(%s)\n",
-      lua_topointer(L,1),lua_typename(L,lua_type(L,1)),
-      lua_tostring(L,2),
-      lua_topointer(L,3),lua_typename(L,lua_type(L,3)));*/
+  */
 
-  assert(lua_isuserdata(L,1));  /* just in case */
-  lua_getmetatable(L,1);    /* get the meta table */
+  int bases_search_result;
+  int substack_start = lua_gettop(L) - 3;
+  lua_checkstack(L,5);
+  assert(lua_isuserdata(L,substack_start+1));  /* just in case */
+  lua_getmetatable(L,substack_start+1);    /* get the meta table */
   assert(lua_istable(L,-1));  /* just in case */
+  if(ret)
+    *ret = 0; /* it is setter - number of return values is always 0 */
 
   SWIG_Lua_get_table(L,".set"); /* find the .set table */
   if (lua_istable(L,-1))
   {
     /* look for the key in the .set table */
-    lua_pushvalue(L,2);  /* key */
+    lua_pushvalue(L,substack_start+2);  /* key */
     lua_rawget(L,-2);
+    lua_remove(L,-2); /* tidy stack, remove .set table */
     if (lua_iscfunction(L,-1))
     {  /* found it so call the fn & return its value */
-      lua_pushvalue(L,1);  /* userdata */
-      lua_pushvalue(L,3);  /* value */
+      lua_pushvalue(L,substack_start+1);  /* userdata */
+      lua_pushvalue(L,substack_start+3);  /* value */
       lua_call(L,2,0);
-      return 0;
+      lua_remove(L,substack_start+4); /*remove metatable*/
+      return SWIG_OK;
     }
     lua_pop(L,1);  /* remove the value */
+  } else {
+    lua_pop(L,1);  /* remove the answer for .set table request*/
   }
-  lua_pop(L,1);  /* remove the value .set table */
   /* NEW: looks for the __setitem() fn
   this is a user provided set fn */
   SWIG_Lua_get_table(L,"__setitem"); /* find the fn */
   if (lua_iscfunction(L,-1))  /* if its there */
   {  /* found it so call the fn & return its value */
-    lua_pushvalue(L,1);  /* the userdata */
-    lua_pushvalue(L,2);  /* the parameter */
-    lua_pushvalue(L,3);  /* the value */
+    lua_pushvalue(L,substack_start+1);  /* the userdata */
+    lua_pushvalue(L,substack_start+2);  /* the parameter */
+    lua_pushvalue(L,substack_start+3);  /* the value */
     lua_call(L,3,0);  /* 3 values in ,0 out */
     lua_remove(L,-2); /* stack tidy, remove metatable */
-    return 1;
+    return SWIG_OK;
+  }
+  lua_pop(L,1); /* remove value */
+
+  lua_pop(L,1); /* remove metatable */
+  /* Search among bases */
+  bases_search_result = SWIG_Lua_iterate_bases(L,type,first_arg,SWIG_Lua_class_do_set,ret);
+  if(ret)
+    assert(*ret == 0);
+  assert(lua_gettop(L) == substack_start + 3);
+  return bases_search_result;
+}
+
+/* This is the actual method exported to Lua. It calls SWIG_Lua_class_do_set and correctly
+ * handles return values.
+ */
+SWIGINTERN int  SWIG_Lua_class_set(lua_State *L)
+{
+/*  There should be 3 params passed in
+  (1) table (not the meta table)
+  (2) string name of the attribute
+  (3) any for the new value
+  */
+  int ret = 0;
+  int result;
+  swig_lua_userdata *usr;
+  swig_type_info *type;
+  assert(lua_isuserdata(L,1));
+  usr=(swig_lua_userdata*)lua_touserdata(L,1);  /* get data */
+  type = usr->type;
+  result = SWIG_Lua_class_do_set(L,type,1,&ret);
+  if(result != SWIG_OK) {
+   SWIG_Lua_pushferrstring(L,"Assignment not possible. No setter/member with this name. For custom assignments implement __setitem method.");
+   lua_error(L);
+  } else {
+    assert(ret==0);
   }
   return 0;
 }
 
 /* the class.destruct method called by the interpreter */
-SWIGINTERN int  SWIG_Lua_class_destruct(lua_StateL)
+SWIGINTERN int  SWIG_Lua_class_destruct(lua_State *L)
 {
 /*  there should be 1 params passed in
   (1) userdata (not the meta table) */
-  swig_lua_userdatausr;
-  swig_lua_classclss;
+  swig_lua_userdata *usr;
+  swig_lua_class *clss;
   assert(lua_isuserdata(L,-1));  /* just in case */
   usr=(swig_lua_userdata*)lua_touserdata(L,-1);  /* get it */
   /* if must be destroyed & has a destructor */
@@ -1400,31 +1726,30 @@ SWIGINTERN int  SWIG_Lua_class_destruct(lua_State* L)
 }
 
 /* the class.__tostring method called by the interpreter and print */
-SWIGINTERN int  SWIG_Lua_class_tostring(lua_StateL)
+SWIGINTERN int  SWIG_Lua_class_tostring(lua_State *L)
 {
 /*  there should be 1 param passed in
   (1) userdata (not the metatable) */
+  const char *className;
+  void* userData;
   assert(lua_isuserdata(L,1));  /* just in case */
-  unsigned long userData = (unsigned long)lua_touserdata(L,1); /* get the userdata address for later */
+  userData = lua_touserdata(L,1); /* get the userdata address for later */
   lua_getmetatable(L,1);    /* get the meta table */
   assert(lua_istable(L,-1));  /* just in case */
-  
+
   lua_getfield(L, -1, ".type");
-  const char* className = lua_tostring(L, -1);
-  
-  char output[256];
-  sprintf(output, "<%s userdata: %lX>", className, userData);
-  
-  lua_pushstring(L, (const char*)output);
+  className = lua_tostring(L, -1);
+
+  lua_pushfstring(L, "<%s userdata: %p>", className, userData);
   return 1;
 }
 
 /* to manually disown some userdata */
-SWIGINTERN int  SWIG_Lua_class_disown(lua_StateL)
+SWIGINTERN int  SWIG_Lua_class_disown(lua_State *L)
 {
 /*  there should be 1 params passed in
   (1) userdata (not the meta table) */
-  swig_lua_userdatausr;
+  swig_lua_userdata *usr;
   assert(lua_isuserdata(L,-1));  /* just in case */
   usr=(swig_lua_userdata*)lua_touserdata(L,-1);  /* get it */
   
@@ -1432,25 +1757,69 @@ SWIGINTERN int  SWIG_Lua_class_disown(lua_State* L)
   return 0;
 }
 
-/* Constructor proxy. Used when class name entry in module is not class constructor,
-but special table instead. */
-SWIGINTERN int SWIG_Lua_constructor_proxy(lua_State* L)
+/* lua callable function to compare userdata's value
+the issue is that two userdata may point to the same thing
+but to lua, they are different objects */
+SWIGRUNTIME int SWIG_Lua_class_equal(lua_State *L)
+{
+  int result;
+  swig_lua_userdata *usr1,*usr2;
+  if (!lua_isuserdata(L,1) || !lua_isuserdata(L,2))  /* just in case */
+    return 0;  /* nil reply */
+  usr1=(swig_lua_userdata*)lua_touserdata(L,1);  /* get data */
+  usr2=(swig_lua_userdata*)lua_touserdata(L,2);  /* get data */
+  /*result=(usr1->ptr==usr2->ptr && usr1->type==usr2->type); only works if type is the same*/
+  result=(usr1->ptr==usr2->ptr);
+   lua_pushboolean(L,result);
+  return 1;
+}
+
+/* populate table at the top of the stack with metamethods that ought to be inherited */
+SWIGINTERN void SWIG_Lua_populate_inheritable_metamethods(lua_State *L)
 {
-  /* unlimited number of parameters
-     First one is our proxy table and we should remove it
-     Other we should pass to real constructor
-   */
-   assert(lua_istable(L,1));
-   lua_pushstring(L,".constructor");
-   lua_rawget(L,1);
-   assert(!lua_isnil(L,-1));
-   lua_replace(L,1); /* replace our table with real constructor */
-   lua_call(L,lua_gettop(L)-1,1);
-   return 1;
+  SWIG_Lua_add_boolean(L, "__add", 1);
+  SWIG_Lua_add_boolean(L, "__sub", 1);
+  SWIG_Lua_add_boolean(L, "__mul", 1);
+  SWIG_Lua_add_boolean(L, "__div", 1);
+  SWIG_Lua_add_boolean(L, "__mod", 1);
+  SWIG_Lua_add_boolean(L, "__pow", 1);
+  SWIG_Lua_add_boolean(L, "__unm", 1);
+  SWIG_Lua_add_boolean(L, "__len", 1 );
+  SWIG_Lua_add_boolean(L, "__concat", 1 );
+  SWIG_Lua_add_boolean(L, "__eq", 1);
+  SWIG_Lua_add_boolean(L, "__lt", 1);
+  SWIG_Lua_add_boolean(L, "__le", 1);
+  SWIG_Lua_add_boolean(L, "__call", 1);
+  SWIG_Lua_add_boolean(L, "__tostring", 1);
+  SWIG_Lua_add_boolean(L, "__gc", 0);
+}
+
+/* creates the swig registry */
+SWIGINTERN void SWIG_Lua_create_class_registry(lua_State *L)
+{
+  /* create main SWIG registry table */
+  lua_pushstring(L,"SWIG");
+  lua_newtable(L);
+  /* populate it with some predefined data */
+
+  /* .library table. Placeholder */
+  lua_pushstring(L,".library");
+  lua_newtable(L);
+  {
+    /* list of metamethods that class inherits from its bases */
+    lua_pushstring(L,"inheritable_metamethods");
+    lua_newtable(L);
+    /* populate with list of metamethods */
+    SWIG_Lua_populate_inheritable_metamethods(L);
+    lua_rawset(L,-3);
+  }
+  lua_rawset(L,-3);
+
+  lua_rawset(L,LUA_REGISTRYINDEX);
 }
 
-/* gets the swig class registry (or creates it) */
-SWIGINTERN void  SWIG_Lua_get_class_registry(lua_StateL)
+/* gets the swig registry (or creates it) */
+SWIGINTERN void  SWIG_Lua_get_class_registry(lua_State *L)
 {
   /* add this all into the swig registry: */
   lua_pushstring(L,"SWIG");
@@ -1458,17 +1827,29 @@ SWIGINTERN void  SWIG_Lua_get_class_registry(lua_State* L)
   if (!lua_istable(L,-1))  /* not there */
   {  /* must be first time, so add it */
     lua_pop(L,1);  /* remove the result */
-    lua_pushstring(L,"SWIG");
-    lua_newtable(L);
-    lua_rawset(L,LUA_REGISTRYINDEX);
+    SWIG_Lua_create_class_registry(L);
     /* then get it */
     lua_pushstring(L,"SWIG");
     lua_rawget(L,LUA_REGISTRYINDEX);
   }
 }
 
-/* helper fn to get the classes metatable from the register */
-SWIGINTERN void  SWIG_Lua_get_class_metatable(lua_State* L,const char* cname)
+SWIGINTERN void SWIG_Lua_get_inheritable_metamethods(lua_State *L)
+{
+  SWIG_Lua_get_class_registry(L);
+  lua_pushstring(L, ".library");
+  lua_rawget(L,-2);
+  assert( !lua_isnil(L,-1) );
+  lua_pushstring(L, "inheritable_metamethods");
+  lua_rawget(L,-2);
+
+  /* Remove class registry and library table */
+  lua_remove(L,-2);
+  lua_remove(L,-2);
+}
+
+/* Helper function to get the classes metatable from the register */
+SWIGINTERN void  SWIG_Lua_get_class_metatable(lua_State *L,const char *cname)
 {
   SWIG_Lua_get_class_registry(L);  /* get the registry */
   lua_pushstring(L,cname);  /* get the name */
@@ -1476,8 +1857,96 @@ SWIGINTERN void  SWIG_Lua_get_class_metatable(lua_State* L,const char* cname)
   lua_remove(L,-2);    /* tidy up (remove registry) */
 }
 
+/* Set up the base classes pointers.
+Each class structure has a list of pointers to the base class structures.
+This function fills them.
+It cannot be done at compile time, as this will not work with hireachies
+spread over more than one swig file. 
+Therefore it must be done at runtime, querying the SWIG type system.
+*/
+SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L,swig_lua_class *clss)
+{
+  int i=0;
+  swig_module_info *module=SWIG_GetModule(L);
+  for(i=0;clss->base_names[i];i++)
+  {
+    if (clss->bases[i]==0) /* not found yet */
+    {
+      /* lookup and cache the base class */
+      swig_type_info *info = SWIG_TypeQueryModule(module,module,clss->base_names[i]);
+      if (info) clss->bases[i] = (swig_lua_class *) info->clientdata;
+    }
+  }
+}
+
+#if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
+/* Merges two tables  */
+SWIGINTERN int SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int source)
+{
+  /* iterating */
+  lua_pushnil(L);
+  while (lua_next(L,source) != 0) {
+    /* -1 - value, -2 - index */
+    /* have to copy to assign */
+    lua_pushvalue(L,-2); /* copy of index */
+    lua_pushvalue(L,-2); /* copy of value */
+    lua_rawset(L, target);
+    lua_pop(L,1);
+    /* only key is left */
+  }
+}
+
+/* Merges two tables with given name. original - index of target metatable, base - index of source metatable */
+SWIGINTERN int SWIG_Lua_merge_tables(lua_State *L, const char* name, int original, int base)
+{
+  /* push original[name], then base[name] */
+  lua_pushstring(L,name);
+  lua_rawget(L,original);
+  int original_table = lua_gettop(L);
+  lua_pushstring(L,name);
+  lua_rawget(L,base);
+  int base_table = lua_gettop(L);
+  SWIG_Lua_merge_tables_by_index(L, original_table, base_table);
+  /* clearing stack */
+  lua_pop(L,2);
+}
+
+/* Function takes all symbols from base and adds it to derived class. It's just a helper. */
+SWIGINTERN int SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls)
+{
+  /* There is one parameter - original, i.e. 'derived' class metatable */
+  assert(lua_istable(L,-1));
+  int original = lua_gettop(L);
+  SWIG_Lua_get_class_metatable(L,base_cls->fqname);
+  int base = lua_gettop(L);
+  SWIG_Lua_merge_tables(L, ".fn", original, base );
+  SWIG_Lua_merge_tables(L, ".set", original, base );
+  SWIG_Lua_merge_tables(L, ".get", original, base );
+  lua_pop(L,1);
+}
+
+/* Function squashes all symbols from 'clss' bases into itself */
+SWIGINTERN int  SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss)
+{
+  int i;
+  SWIG_Lua_get_class_metatable(L,clss->fqname);
+  for(i=0;clss->base_names[i];i++)
+  {
+    if (clss->bases[i]==0) /* Somehow it's not found. Skip it */
+      continue;
+    /* Thing is: all bases are already registered. Thus they have already executed
+     * this function. So we just need to squash them into us, because their bases
+     * are already squashed into them. No need for recursion here!
+     */
+    SWIG_Lua_class_squash_base(L, clss->bases[i]);
+  }
+  lua_pop(L,1); /*tidy stack*/
+}
+#endif
+
+#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* In elua this is useless */
 /* helper add a variable to a registered class */
-SWIGINTERN void  SWIG_Lua_add_class_variable(lua_State* L,const char* name,lua_CFunction getFn,lua_CFunction setFn)
+SWIGINTERN void  SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn)
 {
   assert(lua_istable(L,-1));  /* just in case */
   SWIG_Lua_get_table(L,".get"); /* find the .get table */
@@ -1494,7 +1963,7 @@ SWIGINTERN void  SWIG_Lua_add_class_variable(lua_State* L,const char* name,lua_C
 }
 
 /* helper to recursively add class static details (static attributes, operations and constants) */
-SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State* L, swig_lua_class* clss)
+SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State *L, swig_lua_class *clss)
 {
   int i = 0;
   /* The class namespace table must be on the top of the stack */
@@ -1505,72 +1974,269 @@ SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State* L, swig_lua_class*
     SWIG_Lua_add_class_static_details(L,clss->bases[i]);
   }
 
-  SWIG_Lua_add_namespace_details(L, &clss->cls_static);
+  SWIG_Lua_add_namespace_details(L, clss->cls_static);
 }
 
+SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss); /* forward declaration */
+
 /* helper to recursively add class details (attributes & operations) */
-SWIGINTERN void  SWIG_Lua_add_class_details(lua_State* L,swig_lua_class* clss)
+SWIGINTERN void  SWIG_Lua_add_class_instance_details(lua_State *L, swig_lua_class *clss)
 {
   int i;
-  /* call all the base classes first: we can then override these later: */
+  size_t bases_count = 0;
+  /* Add bases to .bases table */
+  SWIG_Lua_get_table(L,".bases");
+  assert(lua_istable(L,-1));  /* just in case */
   for(i=0;clss->bases[i];i++)
   {
-    SWIG_Lua_add_class_details(L,clss->bases[i]);
-  }
-  /* add fns */
+    SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname);
+    /* Base class must be already registered */
+    assert(lua_istable(L,-1));
+    lua_rawseti(L,-2,i+1); /* In lua indexing starts from 1 */
+    bases_count++;
+  }
+  assert(lua_rawlen(L,-1) == bases_count);
+  lua_pop(L,1); /* remove .bases table */
+  /* add attributes */
   for(i=0;clss->attributes[i].name;i++){
-    SWIG_Lua_add_class_variable(L,clss->attributes[i].name,clss->attributes[i].getmethod,clss->attributes[i].setmethod);
+    SWIG_Lua_add_variable(L,clss->attributes[i].name,clss->attributes[i].getmethod,clss->attributes[i].setmethod);
   }
   /* add methods to the metatable */
   SWIG_Lua_get_table(L,".fn"); /* find the .fn table */
   assert(lua_istable(L,-1));  /* just in case */
   for(i=0;clss->methods[i].name;i++){
-    SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].method);
+    SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].func);
   }
   lua_pop(L,1);       /* tidy stack (remove table) */
-  /*   add operator overloads
-    these look ANY method which start with "__" and assume they
-    are operator overloads & add them to the metatable
-    (this might mess up is someone defines a method __gc (the destructor)*/
-  for(i=0;clss->methods[i].name;i++){
-    if (clss->methods[i].name[0]=='_' && clss->methods[i].name[1]=='_'){
-      SWIG_Lua_add_function(L,clss->methods[i].name,clss->methods[i].method);
+  /* add operator overloads
+    This adds methods from metatable array to metatable. Can mess up garbage
+    collectind if someone defines __gc method
+    */
+  if(clss->metatable) {
+    for(i=0;clss->metatable[i].name;i++) {
+      SWIG_Lua_add_function(L,clss->metatable[i].name,clss->metatable[i].func);
+    }
+  }
+
+#if !defined(SWIG_LUA_SQUASH_BASES)
+  /* Adding metamethods that are defined in base classes. If bases were squashed
+   * then it is obviously unnecessary
+   */
+  SWIG_Lua_add_class_user_metamethods(L, clss);
+#endif
+}
+
+/* Helpers to add user defined class metamedhods - __add, __sub etc. The helpers are needed
+   for the following issue: Lua runtime checks for metamethod existence with rawget function
+   ignoring our SWIG-provided __index and __newindex functions. Thus our inheritance-aware method
+   search algorithm doesn't work in such case. (Not to say that Lua runtime queries metamethod directly
+   in metatable and not in object).
+   Current solution is this: if somewhere in hierarchy metamethod __x is defined, then all descendants
+   are automatically given a special proxy __x that calls the real __x method.
+   Obvious idea - to copy __x instead of creating __x-proxy is wrong because if someone changes __x in runtime,
+   those changes must be reflected in all descendants.
+*/
+
+SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L); /*forward declaration*/
+
+/* The real function that resolves a metamethod.
+ * Function searches given class and all it's bases(recursively) for first instance of something that is
+ * not equal to SWIG_Lua_resolve_metatmethod. (Almost always this 'something' is actual metamethod implementation
+ * and it is a SWIG-generated C function.). It returns value on the top of the L and there is no garbage below the
+ * answer.
+ * Returns 1 if found, 0 otherwise.
+ * clss is class which metatable we will search for method
+ * metamethod_name_idx is index in L where metamethod name (as string) lies
+ * skip_check allows to skip searching metamethod in givel clss and immideatelly go to searching in bases. skip_check
+ * is not caried to subsequent recursive calls - false is always passed. It is set to true only at first call from
+ * SWIG_Lua_resolve_metamethod
+ * */
+SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class *clss, int metamethod_name_idx,
+    int skip_check)
+{
+  /* This function is called recursively */
+  int result = 0;
+  int i = 0;
+
+  if (!skip_check) {
+    SWIG_Lua_get_class_metatable(L, clss->fqname);
+    lua_pushvalue(L, metamethod_name_idx);
+    lua_rawget(L,-2);
+    /* If this is cfunction and it is equal to SWIG_Lua_resolve_metamethod then
+     * this isn't the function we are looking for :)
+     * lua_tocfunction will return NULL if not cfunction
+     */
+    if (!lua_isnil(L,-1) && lua_tocfunction(L,-1) != SWIG_Lua_resolve_metamethod ) {
+      lua_remove(L,-2); /* removing class metatable */
+      return 1;
+    }
+    lua_pop(L,2); /* remove class metatable and query result */
+  }
+
+  /* Forwarding calls to bases */
+  for(i=0;clss->bases[i];i++)
+  {
+    result = SWIG_Lua_do_resolve_metamethod(L, clss->bases[i], metamethod_name_idx, 0);
+    if (result)
+      break;
+  }
+
+  return result;
+}
+
+/* The proxy function for metamethod. All parameters are passed as cclosure. Searches for actual method
+ * and calls it */
+SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L)
+{
+  int numargs;
+  int metamethod_name_idx;
+  const swig_lua_class* clss;
+  int result;
+
+  lua_checkstack(L,5);
+  numargs = lua_gettop(L); /* number of arguments to pass to actual metamethod */
+  
+  /* Get upvalues from closure */
+  lua_pushvalue(L, lua_upvalueindex(1)); /*Get function name*/
+  metamethod_name_idx = lua_gettop(L);
+  
+  lua_pushvalue(L, lua_upvalueindex(2));
+  clss = (const swig_lua_class*)(lua_touserdata(L,-1));
+  lua_pop(L,1); /* remove lightuserdata with clss from stack */
+
+  /* Actual work */
+  result = SWIG_Lua_do_resolve_metamethod(L, clss, metamethod_name_idx, 1);
+  if (!result) {
+   SWIG_Lua_pushferrstring(L,"The metamethod proxy is set, but it failed to find actual metamethod. Memory corruption is most likely explanation.");
+   lua_error(L);
+   return 0;
+  }
+
+  lua_remove(L,-2); /* remove metamethod key */
+  lua_insert(L,1); /* move function to correct position */
+  lua_call(L, numargs, LUA_MULTRET);
+  return lua_gettop(L); /* return all results */
+}
+
+
+/* If given metamethod must be present in given class, then creates appropriate proxy
+ * Returns 1 if successfully added, 0 if not added because no base class has it, -1
+ * if method is defined in the class metatable itself
+ */
+SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *clss, const int metatable_index)
+{
+  int key_index;
+  int success = 0;
+  int i = 0;
+
+  /* metamethod name - on the top of the stack */
+  assert(lua_isstring(L,-1));
+  
+  key_index = lua_gettop(L);
+
+  /* Check whether method is already defined in metatable */
+  lua_pushvalue(L,key_index); /* copy of the key */
+  lua_gettable(L,metatable_index);
+  if( !lua_isnil(L,-1) ) {
+    lua_pop(L,1);
+    return -1;
+  }
+  lua_pop(L,1); 
+
+  /* Iterating over immediate bases */
+  for(i=0;clss->bases[i];i++)
+  {
+    const swig_lua_class *base = clss->bases[i];
+    SWIG_Lua_get_class_metatable(L, base->fqname);
+    lua_pushvalue(L, key_index);
+    lua_rawget(L, -2);
+    if( !lua_isnil(L,-1) ) {
+      lua_pushvalue(L, key_index); 
+
+      /* Add proxy function */
+      lua_pushvalue(L, key_index); /* first closure value is function name */
+      lua_pushlightuserdata(L, clss); /* second closure value is swig_lua_class structure */
+      lua_pushcclosure(L, SWIG_Lua_resolve_metamethod, 2);
+      
+      lua_rawset(L, metatable_index);
+      success = 1;
     }
+    lua_pop(L,1); /* remove function or nil */
+    lua_pop(L,1); /* remove base class metatable */
+
+    if( success )
+      break;
   }
+
+  return success; 
 }
 
-/* set up the base classes pointers.
-Each class structure has a list of pointers to the base class structures.
-This function fills them.
-It cannot be done at compile time, as this will not work with hireachies
-spread over more than one swig file. 
-Therefore it must be done at runtime, querying the SWIG type system.
-*/
-SWIGINTERN void SWIG_Lua_init_base_class(lua_State* L,swig_lua_class* clss)
+SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss)
 {
-  int i=0;
-  swig_module_info* module=SWIG_GetModule(L);
-  for(i=0;clss->base_names[i];i++)
-  {
-    if (clss->bases[i]==0) /* not found yet */
-    {
-      /* lookup and cache the base class */
-      swig_type_info *info = SWIG_TypeQueryModule(module,module,clss->base_names[i]);
-      if (info) clss->bases[i] = (swig_lua_class *) info->clientdata;
+  int metatable_index;
+  int metamethods_info_index;
+  int tostring_undefined;
+  int eq_undefined = 0;
+
+  SWIG_Lua_get_class_metatable(L, clss->fqname);
+  metatable_index = lua_gettop(L);
+  SWIG_Lua_get_inheritable_metamethods(L);
+  assert(lua_istable(L,-1));
+  metamethods_info_index = lua_gettop(L);
+  lua_pushnil(L); /* first key */
+  while(lua_next(L, metamethods_info_index) != 0 ) {
+    /* key at index -2, value at index -1 */
+    const int is_inheritable = lua_toboolean(L,-2);
+    lua_pop(L,1); /* remove value - we don't need it anymore */
+
+    if(is_inheritable) { /* if metamethod is inheritable */
+      SWIG_Lua_add_class_user_metamethod(L,clss,metatable_index);
     }
   }
+
+  lua_pop(L,1); /* remove inheritable metatmethods table */
+
+  /* Special handling for __tostring method */
+  lua_pushstring(L, "__tostring");
+  lua_pushvalue(L,-1);
+  lua_rawget(L,metatable_index);
+  tostring_undefined = lua_isnil(L,-1);
+  lua_pop(L,1);
+  if( tostring_undefined ) {
+    lua_pushcfunction(L, SWIG_Lua_class_tostring);
+    lua_rawset(L, metatable_index);
+  } else {
+    lua_pop(L,1); /* remove copy of the key */
+  }
+
+  /* Special handling for __eq method */
+  lua_pushstring(L, "__eq");
+  lua_pushvalue(L,-1);
+  lua_rawget(L,metatable_index);
+  eq_undefined = lua_isnil(L,-1);
+  lua_pop(L,1);
+  if( eq_undefined ) {
+    lua_pushcfunction(L, SWIG_Lua_class_equal);
+    lua_rawset(L, metatable_index);
+  } else {
+    lua_pop(L,1); /* remove copy of the key */
+  }
+  /* Warning: __index and __newindex are SWIG-defined. For user-defined operator[]
+   * a __getitem/__setitem method should be defined
+   */
+  lua_pop(L,1); /* pop class metatable */
 }
 
 /* Register class static methods,attributes etc as well as constructor proxy */
-SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* clss)
+SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *clss)
 {
+  const int SWIGUNUSED begin = lua_gettop(L);
   lua_checkstack(L,5); /* just in case */
   assert(lua_istable(L,-1));  /* just in case */
-  assert(strcmp(clss->name, clss->cls_static.name) == 0); /* in class those 2 must be equal */
+  assert(strcmp(clss->name, clss->cls_static->name) == 0); /* in class those 2 must be equal */
 
-  SWIG_Lua_namespace_register(L,&clss->cls_static);
+  SWIG_Lua_namespace_register(L,clss->cls_static, 1);
 
-  SWIG_Lua_get_table(L,clss->name); // Get namespace table back
   assert(lua_istable(L,-1)); /* just in case */
 
   /*  add its constructor to module with the name of the class
@@ -1579,10 +2245,9 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* cls
   (this overcomes the problem of pure virtual classes without constructors)*/
   if (clss->constructor)
   {
-    SWIG_Lua_add_function(L,".constructor", clss->constructor);
     lua_getmetatable(L,-1);
     assert(lua_istable(L,-1)); /* just in case */
-    SWIG_Lua_add_function(L,"__call", SWIG_Lua_constructor_proxy);
+    SWIG_Lua_add_function(L,"__call", clss->constructor);
     lua_pop(L,1);
   }
 
@@ -1591,19 +2256,60 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State* L, swig_lua_class* cls
 
   /* clear stack */
   lua_pop(L,1);
+  assert( lua_gettop(L) == begin );
 }
 
-/* performs the entire class registration process */
-SWIGINTERN void  SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss)
+/* Performs the instance (non-static) class registration process. Metatable for class is created
+ * and added to the class registry.
+ */
+SWIGINTERN void  SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *clss)
 {
-  SWIG_Lua_class_register_static(L,clss);
-
+  const int SWIGUNUSED begin = lua_gettop(L);
+  int i;
+  /* if name already there (class is already registered) then do nothing */
+  SWIG_Lua_get_class_registry(L);  /* get the registry */
+  lua_pushstring(L,clss->fqname);  /* get the name */
+  lua_rawget(L,-2);
+  if(!lua_isnil(L,-1)) {
+    lua_pop(L,2);
+    assert(lua_gettop(L)==begin);
+    return;
+  }
+  lua_pop(L,2); /* tidy stack */
+  /* Recursively initialize all bases */
+  for(i=0;clss->bases[i];i++)
+  {
+    SWIG_Lua_class_register_instance(L,clss->bases[i]);
+  }
+  /* Again, get registry and push name */
   SWIG_Lua_get_class_registry(L);  /* get the registry */
-  lua_pushstring(L,clss->name);  /* get the name */
+  lua_pushstring(L,clss->fqname);  /* get the name */
   lua_newtable(L);    /* create the metatable */
+#if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
+  /* If squashing is requested, then merges all bases metatable into this one.
+   * It would get us all special methods: __getitem, __add etc.
+   * This would set .fn, .type, and other .xxx incorrectly, but we will overwrite it right away
+   */
+  {
+    int new_metatable_index = lua_absindex(L,-1);
+    for(i=0;clss->bases[i];i++)
+    {
+      int base_metatable;
+      SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname);
+      base_metatable = lua_absindex(L,-1);
+      SWIG_Lua_merge_tables_by_index(L,new_metatable_index, base_metatable);
+      lua_pop(L,1);
+    }
+  }
+  /* And now we will overwrite all incorrectly set data */
+#endif
   /* add string of class name called ".type" */
   lua_pushstring(L,".type");
-  lua_pushstring(L,clss->name);
+  lua_pushstring(L,clss->fqname);
+  lua_rawset(L,-3);
+  /* add a table called bases */
+  lua_pushstring(L,".bases");
+  lua_newtable(L);
   lua_rawset(L,-3);
   /* add a table called ".get" */
   lua_pushstring(L,".get");
@@ -1623,27 +2329,99 @@ SWIGINTERN void  SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss)
   SWIG_Lua_add_function(L,"__index",SWIG_Lua_class_get);
   SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_class_set);
   SWIG_Lua_add_function(L,"__gc",SWIG_Lua_class_destruct);
-  /* add tostring method for better output */
-  SWIG_Lua_add_function(L,"__tostring",SWIG_Lua_class_tostring);
   /* add it */
   lua_rawset(L,-3);  /* metatable into registry */
   lua_pop(L,1);      /* tidy stack (remove registry) */
+  assert(lua_gettop(L) == begin);
 
-  SWIG_Lua_get_class_metatable(L,clss->name);
-  SWIG_Lua_add_class_details(L,clss);  /* recursive adding of details (atts & ops) */
+#if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
+  /* Now merge all symbols from .fn, .set, .get etc from bases to our tables */
+  SWIG_Lua_class_squash_bases(L,clss);
+#endif
+  SWIG_Lua_get_class_metatable(L,clss->fqname);
+  SWIG_Lua_add_class_instance_details(L,clss);  /* recursive adding of details (atts & ops) */
   lua_pop(L,1);      /* tidy stack (remove class metatable) */
+  assert( lua_gettop(L) == begin );
+}
+
+SWIGINTERN void  SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss)
+{
+  int SWIGUNUSED begin;
+  assert(lua_istable(L,-1)); /* This is a table (module or namespace) where classes will be added */
+  SWIG_Lua_class_register_instance(L,clss);
+  SWIG_Lua_class_register_static(L,clss);
+
+  /* Add links from static part to instance part and vice versa */
+  /* [SWIG registry]                                   [Module]
+   *    "MyClass" ----> [MyClass metatable] <=====     "MyClass" -+> [static part]
+   *                     ".get" ----> ...        |                |     getmetatable()----|
+   *                     ".set" ----> ...        |                |                       |
+   *                     ".static" --------------)----------------/           [static part metatable]
+   *                                             |                                ".get" --> ...
+   *                                             |                                ".set" --> ....
+   *                                             |=============================== ".instance"
+   */
+  begin = lua_gettop(L);
+  lua_pushstring(L,clss->cls_static->name);
+  lua_rawget(L,-2); /* get class static table */
+  assert(lua_istable(L,-1));
+  lua_getmetatable(L,-1);
+  assert(lua_istable(L,-1)); /* get class static metatable */
+  lua_pushstring(L,".instance"); /* prepare key */
+
+  SWIG_Lua_get_class_metatable(L,clss->fqname); /* get class metatable */
+  assert(lua_istable(L,-1));
+  lua_pushstring(L,".static"); /* prepare key */
+  lua_pushvalue(L, -4); /* push static class TABLE */
+  assert(lua_istable(L,-1));
+  lua_rawset(L,-3); /* assign static class table(!NOT metatable) as ".static" member of class metatable */
+  lua_rawset(L,-3); /* assign class metatable as ".instance" member of class static METATABLE */
+  lua_pop(L,2);
+  assert(lua_gettop(L) == begin);
+}
+#endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */
+
+#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
+SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_class *clss)
+{
+  const int SWIGUNUSED begin = lua_gettop(L);
+  int i;
+  /* if name already there (class is already registered) then do nothing */
+  SWIG_Lua_get_class_registry(L);  /* get the registry */
+  lua_pushstring(L,clss->fqname);  /* get the name */
+  lua_rawget(L,-2);
+  if(!lua_isnil(L,-1)) {
+    lua_pop(L,2);
+    assert(lua_gettop(L)==begin);
+    return;
+  }
+  lua_pop(L,2); /* tidy stack */
+  /* Recursively initialize all bases */
+  for(i=0;clss->bases[i];i++)
+  {
+    SWIG_Lua_elua_class_register_instance(L,clss->bases[i]);
+  }
+  /* Again, get registry and push name */
+  SWIG_Lua_get_class_registry(L);  /* get the registry */
+  lua_pushstring(L,clss->fqname);  /* get the name */
+  assert(clss->metatable);
+  lua_pushrotable(L, (void*)(clss->metatable));    /* create the metatable */
+  lua_rawset(L,-3);
+  lua_pop(L,1);
+  assert(lua_gettop(L) == begin);
 }
+#endif /* elua && eluac */
 
 /* -----------------------------------------------------------------------------
  * Class/structure conversion fns
  * ----------------------------------------------------------------------------- */
 
 /* helper to add metatable to new lua object */
-SWIGINTERN void _SWIG_Lua_AddMetatable(lua_State* L,swig_type_info *type)
+SWIGINTERN void SWIG_Lua_AddMetatable(lua_State *L,swig_type_info *type)
 {
   if (type->clientdata)  /* there is clientdata: so add the metatable */
   {
-    SWIG_Lua_get_class_metatable(L,((swig_lua_class*)(type->clientdata))->name);
+    SWIG_Lua_get_class_metatable(L,((swig_lua_class*)(type->clientdata))->fqname);
     if (lua_istable(L,-1))
     {
       lua_setmetatable(L,-2);
@@ -1656,9 +2434,9 @@ SWIGINTERN void _SWIG_Lua_AddMetatable(lua_State* L,swig_type_info *type)
 }
 
 /* pushes a new object into the lua stack */
-SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State* L,void* ptr,swig_type_info *type, int own)
+SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *type, int own)
 {
-  swig_lua_userdatausr;
+  swig_lua_userdata *usr;
   if (!ptr){
     lua_pushnil(L);
     return;
@@ -1668,15 +2446,15 @@ SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State* L,void* ptr,swig_type_info *t
   usr->type=type;
   usr->own=own;
 #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
-  _SWIG_Lua_AddMetatable(L,type); /* add metatable */
+  SWIG_Lua_AddMetatable(L,type); /* add metatable */
 #endif
 }
 
 /* takes a object from the lua stack & converts it into an object of the correct type
  (if possible) */
-SWIGRUNTIME int  SWIG_Lua_ConvertPtr(lua_State* L,int index,void** ptr,swig_type_info *type,int flags)
+SWIGRUNTIME int  SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type_info *type,int flags)
 {
-  swig_lua_userdatausr;
+  swig_lua_userdata *usr;
   swig_cast_info *cast;
   if (lua_isnil(L,index)){*ptr=0; return SWIG_OK;}    /* special case: lua nil => NULL pointer */
   usr=(swig_lua_userdata*)lua_touserdata(L,index);  /* get data */
@@ -1703,9 +2481,9 @@ SWIGRUNTIME int  SWIG_Lua_ConvertPtr(lua_State* L,int index,void** ptr,swig_type
   return SWIG_ERROR;  /* error */
 }
 
-SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_StateL,int index,swig_type_info *type,int flags,
-       int argnum,const charfunc_name){
-  voidresult;
+SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State *L,int index,swig_type_info *type,int flags,
+       int argnum,const char *func_name){
+  void *result;
   if (!SWIG_IsOK(SWIG_ConvertPtr(L,index,&result,type,flags))){
     luaL_error (L,"Error in %s, expected a %s at argument number %d\n",
                func_name,(type && type->str)?type->str:"void*",argnum);
@@ -1714,21 +2492,21 @@ SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State* L,int index,swig_type_info *typ
 }
 
 /* pushes a packed userdata. user for member fn pointers only */
-SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State* L,void* ptr,size_t size,swig_type_info *type)
+SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_type_info *type)
 {
-  swig_lua_rawdataraw;
+  swig_lua_rawdata *raw;
   assert(ptr); /* not acceptable to pass in a NULL value */
   raw=(swig_lua_rawdata*)lua_newuserdata(L,sizeof(swig_lua_rawdata)-1+size);  /* alloc data */
   raw->type=type;
   raw->own=0;
   memcpy(raw->data,ptr,size); /* copy the data */
-  _SWIG_Lua_AddMetatable(L,type); /* add metatable */
+  SWIG_Lua_AddMetatable(L,type); /* add metatable */
 }
     
 /* converts a packed userdata. user for member fn pointers only */
-SWIGRUNTIME int  SWIG_Lua_ConvertPacked(lua_State* L,int index,void* ptr,size_t size,swig_type_info *type)
+SWIGRUNTIME int  SWIG_Lua_ConvertPacked(lua_State *L,int index,void *ptr,size_t size,swig_type_info *type)
 {
-  swig_lua_rawdataraw;
+  swig_lua_rawdata *raw;
   raw=(swig_lua_rawdata*)lua_touserdata(L,index);  /* get data */
   if (!raw) return SWIG_ERROR;  /* error */
   if (type==0 || type==raw->type) /* void* or identical type */
@@ -1742,7 +2520,7 @@ SWIGRUNTIME int  SWIG_Lua_ConvertPacked(lua_State* L,int index,void* ptr,size_t
 /* a function to get the typestring of a piece of data */
 SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp)
 {
-  swig_lua_userdatausr;
+  swig_lua_userdata *usr;
   if (lua_isuserdata(L,tp))
   {
     usr=(swig_lua_userdata*)lua_touserdata(L,tp);  /* get data */
@@ -1754,29 +2532,12 @@ SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp)
 }
 
 /* lua callable function to get the userdata's type */
-SWIGRUNTIME int SWIG_Lua_type(lua_StateL)
+SWIGRUNTIME int SWIG_Lua_type(lua_State *L)
 {
   lua_pushstring(L,SWIG_Lua_typename(L,1));
   return 1;
 }
 
-/* lua callable function to compare userdata's value
-the issue is that two userdata may point to the same thing
-but to lua, they are different objects */
-SWIGRUNTIME int SWIG_Lua_equal(lua_State* L)
-{
-  int result;
-  swig_lua_userdata *usr1,*usr2;
-  if (!lua_isuserdata(L,1) || !lua_isuserdata(L,2))  /* just in case */
-    return 0;  /* nil reply */
-  usr1=(swig_lua_userdata*)lua_touserdata(L,1);  /* get data */
-  usr2=(swig_lua_userdata*)lua_touserdata(L,2);  /* get data */
-  /*result=(usr1->ptr==usr2->ptr && usr1->type==usr2->type); only works if type is the same*/
-  result=(usr1->ptr==usr2->ptr);
-   lua_pushboolean(L,result);
-  return 1;
-}
-
 /* -----------------------------------------------------------------------------
  * global variable support code: class/struct typemap functions
  * ----------------------------------------------------------------------------- */
@@ -1784,7 +2545,7 @@ SWIGRUNTIME int SWIG_Lua_equal(lua_State* L)
 #if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
 /* Install Constants */
 SWIGINTERN void
-SWIG_Lua_InstallConstants(lua_StateL, swig_lua_const_info constants[]) {
+SWIG_Lua_InstallConstants(lua_State *L, swig_lua_const_info constants[]) {
   int i;
   for (i = 0; constants[i].type; i++) {
     switch(constants[i].type) {
@@ -1834,11 +2595,11 @@ SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) {
 #endif
 /* Executes a C string in Lua which is a really simple way of calling lua from C
 Unfortunately lua keeps changing its APIs, so we need a conditional compile
-In lua 5.0.X its lua_dostring()
-In lua 5.1.X its luaL_dostring()
+In lua 5.0.X it's lua_dostring()
+In lua 5.1.X it's luaL_dostring()
 */
 SWIGINTERN int 
-SWIG_Lua_dostring(lua_State *L, const charstr) {
+SWIG_Lua_dostring(lua_State *L, const char *str) {
   int ok,top;
   if (str==0 || str[0]==0) return 0; /* nothing to do */
   top=lua_gettop(L); /* save stack */
@@ -2007,16 +2768,16 @@ SWIGINTERN int SWIG_table_size(lua_State* L, int index)
                }\
        }
 
-SWIG_DECLARE_TYPEMAP_ARR_FN(schar,signed char);
-SWIG_DECLARE_TYPEMAP_ARR_FN(uchar,unsigned char);
-SWIG_DECLARE_TYPEMAP_ARR_FN(int,int);
-SWIG_DECLARE_TYPEMAP_ARR_FN(uint,unsigned int);
-SWIG_DECLARE_TYPEMAP_ARR_FN(short,short);
-SWIG_DECLARE_TYPEMAP_ARR_FN(ushort,unsigned short);
-SWIG_DECLARE_TYPEMAP_ARR_FN(long,long);
-SWIG_DECLARE_TYPEMAP_ARR_FN(ulong,unsigned long);
-SWIG_DECLARE_TYPEMAP_ARR_FN(float,float);
-SWIG_DECLARE_TYPEMAP_ARR_FN(double,double);
+SWIG_DECLARE_TYPEMAP_ARR_FN(schar,signed char)
+SWIG_DECLARE_TYPEMAP_ARR_FN(uchar,unsigned char)
+SWIG_DECLARE_TYPEMAP_ARR_FN(int,int)
+SWIG_DECLARE_TYPEMAP_ARR_FN(uint,unsigned int)
+SWIG_DECLARE_TYPEMAP_ARR_FN(short,short)
+SWIG_DECLARE_TYPEMAP_ARR_FN(ushort,unsigned short)
+SWIG_DECLARE_TYPEMAP_ARR_FN(long,long)
+SWIG_DECLARE_TYPEMAP_ARR_FN(ulong,unsigned long)
+SWIG_DECLARE_TYPEMAP_ARR_FN(float,float)
+SWIG_DECLARE_TYPEMAP_ARR_FN(double,double)
 
 SWIGINTERN int SWIG_read_ptr_array(lua_State* L,int index,void **array,int size,swig_type_info *type){
        int i;
@@ -2404,26 +3165,50 @@ static void swig_delete_IVRMenu(void *obj) {
 IVRMenu *arg1 = (IVRMenu *) obj;
 delete arg1;
 }
-static swig_lua_method swig_IVRMenu_methods[] = {
-    {"bindAction", _wrap_IVRMenu_bindAction}, 
-    {"execute", _wrap_IVRMenu_execute}, 
-    {0,0}
-};
+static int _proxy__wrap_new_IVRMenu(lua_State *L) {
+    assert(lua_istable(L,1));
+    lua_pushcfunction(L,_wrap_new_IVRMenu);
+    assert(!lua_isnil(L,-1));
+    lua_replace(L,1); /* replace our table with real constructor */
+    lua_call(L,lua_gettop(L)-1,1);
+    return 1;
+}
 static swig_lua_attribute swig_IVRMenu_attributes[] = {
     {0,0,0}
 };
-static swig_lua_attribute swig_IVRMenu_cls_attributes[] = {
-    {0,0,0}
+static swig_lua_method swig_IVRMenu_methods[]= {
+    { "bindAction", _wrap_IVRMenu_bindAction},
+    { "execute", _wrap_IVRMenu_execute},
+    {0,0}
 };
-static swig_lua_method swig_IVRMenu_cls_methods[] = {
+static swig_lua_method swig_IVRMenu_meta[] = {
     {0,0}
 };
-static swig_lua_const_info swig_IVRMenu_cls_constants[] = {
+
+static swig_lua_attribute swig_IVRMenu_Sf_SwigStatic_attributes[] = {
+    {0,0,0}
+};
+static swig_lua_const_info swig_IVRMenu_Sf_SwigStatic_constants[]= {
     {0,0,0,0,0,0}
 };
+static swig_lua_method swig_IVRMenu_Sf_SwigStatic_methods[]= {
+    {0,0}
+};
+static swig_lua_class* swig_IVRMenu_Sf_SwigStatic_classes[]= {
+    0
+};
+
+static swig_lua_namespace swig_IVRMenu_Sf_SwigStatic = {
+    "IVRMenu",
+    swig_IVRMenu_Sf_SwigStatic_methods,
+    swig_IVRMenu_Sf_SwigStatic_attributes,
+    swig_IVRMenu_Sf_SwigStatic_constants,
+    swig_IVRMenu_Sf_SwigStatic_classes,
+    0
+};
 static swig_lua_class *swig_IVRMenu_bases[] = {0};
 static const char *swig_IVRMenu_base_names[] = {0};
-static swig_lua_class _wrap_class_IVRMenu = { "IVRMenu", &SWIGTYPE_p_IVRMenu,_wrap_new_IVRMenu, swig_delete_IVRMenu, swig_IVRMenu_methods, swig_IVRMenu_attributes, { "IVRMenu", swig_IVRMenu_cls_methods, swig_IVRMenu_cls_attributes, swig_IVRMenu_cls_constants }, swig_IVRMenu_bases, swig_IVRMenu_base_names };
+static swig_lua_class _wrap_class_IVRMenu = { "IVRMenu", "IVRMenu", &SWIGTYPE_p_IVRMenu,_proxy__wrap_new_IVRMenu, swig_delete_IVRMenu, swig_IVRMenu_methods, swig_IVRMenu_attributes, &swig_IVRMenu_Sf_SwigStatic, swig_IVRMenu_meta, swig_IVRMenu_bases, swig_IVRMenu_base_names };
 
 static int _wrap_new_API(lua_State* L) {
   int SWIG_arg = 0;
@@ -2538,29 +3323,53 @@ static void swig_delete_API(void *obj) {
 API *arg1 = (API *) obj;
 delete arg1;
 }
-static swig_lua_method swig_API_methods[] = {
-    {"execute", _wrap_API_execute}, 
-    {"executeString", _wrap_API_executeString}, 
-    {"getTime", _wrap_API_getTime}, 
-    {0,0}
-};
+static int _proxy__wrap_new_API(lua_State *L) {
+    assert(lua_istable(L,1));
+    lua_pushcfunction(L,_wrap_new_API);
+    assert(!lua_isnil(L,-1));
+    lua_replace(L,1); /* replace our table with real constructor */
+    lua_call(L,lua_gettop(L)-1,1);
+    return 1;
+}
 static swig_lua_attribute swig_API_attributes[] = {
     {0,0,0}
 };
-static swig_lua_attribute swig_API_cls_attributes[] = {
-    {0,0,0}
+static swig_lua_method swig_API_methods[]= {
+    { "execute", _wrap_API_execute},
+    { "executeString", _wrap_API_executeString},
+    { "getTime", _wrap_API_getTime},
+    {0,0}
 };
-static swig_lua_method swig_API_cls_methods[] = {
+static swig_lua_method swig_API_meta[] = {
     {0,0}
 };
-static swig_lua_const_info swig_API_cls_constants[] = {
+
+static swig_lua_attribute swig_API_Sf_SwigStatic_attributes[] = {
+    {0,0,0}
+};
+static swig_lua_const_info swig_API_Sf_SwigStatic_constants[]= {
     {0,0,0,0,0,0}
 };
+static swig_lua_method swig_API_Sf_SwigStatic_methods[]= {
+    {0,0}
+};
+static swig_lua_class* swig_API_Sf_SwigStatic_classes[]= {
+    0
+};
+
+static swig_lua_namespace swig_API_Sf_SwigStatic = {
+    "API",
+    swig_API_Sf_SwigStatic_methods,
+    swig_API_Sf_SwigStatic_attributes,
+    swig_API_Sf_SwigStatic_constants,
+    swig_API_Sf_SwigStatic_classes,
+    0
+};
 static swig_lua_class *swig_API_bases[] = {0};
 static const char *swig_API_base_names[] = {0};
-static swig_lua_class _wrap_class_API = { "API", &SWIGTYPE_p_API,_wrap_new_API, swig_delete_API, swig_API_methods, swig_API_attributes, { "API", swig_API_cls_methods, swig_API_cls_attributes, swig_API_cls_constants }, swig_API_bases, swig_API_base_names };
+static swig_lua_class _wrap_class_API = { "API", "API", &SWIGTYPE_p_API,_proxy__wrap_new_API, swig_delete_API, swig_API_methods, swig_API_attributes, &swig_API_Sf_SwigStatic, swig_API_meta, swig_API_bases, swig_API_base_names };
 
-static int _wrap_input_callback_state_t_function_set(lua_State* L) {
+static int _wrap_input_callback_state_t_c_function_set(lua_State* L) {
   int SWIG_arg = 0;
   input_callback_state *arg1 = (input_callback_state *) 0 ;
   void *arg2 = (void *) 0 ;
@@ -2570,10 +3379,10 @@ static int _wrap_input_callback_state_t_function_set(lua_State* L) {
   if(!SWIG_isptrtype(L,2)) SWIG_fail_arg("input_callback_state::function",2,"void *");
   
   if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_input_callback_state,0))){
-    SWIG_fail_ptr("input_callback_state_t_function_set",1,SWIGTYPE_p_input_callback_state);
+    SWIG_fail_ptr("input_callback_state_t_c_function_set",1,SWIGTYPE_p_input_callback_state);
   }
   
-  arg2=(void *)SWIG_MustGetPtr(L,2,0,0,2,"input_callback_state_t_function_set");
+  arg2=(void *)SWIG_MustGetPtr(L,2,0,0,2,"input_callback_state_t_c_function_set");
   if (arg1) (arg1)->function = arg2;
   
   return SWIG_arg;
@@ -2586,7 +3395,7 @@ fail:
 }
 
 
-static int _wrap_input_callback_state_t_function_get(lua_State* L) {
+static int _wrap_input_callback_state_t_c_function_get(lua_State* L) {
   int SWIG_arg = 0;
   input_callback_state *arg1 = (input_callback_state *) 0 ;
   void *result = 0 ;
@@ -2595,7 +3404,7 @@ static int _wrap_input_callback_state_t_function_get(lua_State* L) {
   if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("input_callback_state::function",1,"input_callback_state *");
   
   if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_input_callback_state,0))){
-    SWIG_fail_ptr("input_callback_state_t_function_get",1,SWIGTYPE_p_input_callback_state);
+    SWIG_fail_ptr("input_callback_state_t_c_function_get",1,SWIGTYPE_p_input_callback_state);
   }
   
   result = (void *) ((arg1)->function);
@@ -2789,28 +3598,52 @@ static void swig_delete_input_callback_state_t(void *obj) {
 input_callback_state *arg1 = (input_callback_state *) obj;
 delete arg1;
 }
-static swig_lua_method swig_input_callback_state_methods[] = {
+static int _proxy__wrap_new_input_callback_state_t(lua_State *L) {
+    assert(lua_istable(L,1));
+    lua_pushcfunction(L,_wrap_new_input_callback_state_t);
+    assert(!lua_isnil(L,-1));
+    lua_replace(L,1); /* replace our table with real constructor */
+    lua_call(L,lua_gettop(L)-1,1);
+    return 1;
+}
+static swig_lua_attribute swig_input_callback_state_t_attributes[] = {
+    { "c_function", _wrap_input_callback_state_t_c_function_get, _wrap_input_callback_state_t_c_function_set },
+    { "threadState", _wrap_input_callback_state_t_threadState_get, _wrap_input_callback_state_t_threadState_set },
+    { "extra", _wrap_input_callback_state_t_extra_get, _wrap_input_callback_state_t_extra_set },
+    { "funcargs", _wrap_input_callback_state_t_funcargs_get, _wrap_input_callback_state_t_funcargs_set },
+    {0,0,0}
+};
+static swig_lua_method swig_input_callback_state_t_methods[]= {
     {0,0}
 };
-static swig_lua_attribute swig_input_callback_state_attributes[] = {
-    { "function", _wrap_input_callback_state_t_function_get, _wrap_input_callback_state_t_function_set},
-    { "threadState", _wrap_input_callback_state_t_threadState_get, _wrap_input_callback_state_t_threadState_set},
-    { "extra", _wrap_input_callback_state_t_extra_get, _wrap_input_callback_state_t_extra_set},
-    { "funcargs", _wrap_input_callback_state_t_funcargs_get, _wrap_input_callback_state_t_funcargs_set},
-    {0,0,0}
+static swig_lua_method swig_input_callback_state_t_meta[] = {
+    {0,0}
 };
-static swig_lua_attribute swig_input_callback_state_cls_attributes[] = {
+
+static swig_lua_attribute swig_input_callback_state_t_Sf_SwigStatic_attributes[] = {
     {0,0,0}
 };
-static swig_lua_method swig_input_callback_state_cls_methods[] = {
+static swig_lua_const_info swig_input_callback_state_t_Sf_SwigStatic_constants[]= {
+    {0,0,0,0,0,0}
+};
+static swig_lua_method swig_input_callback_state_t_Sf_SwigStatic_methods[]= {
     {0,0}
 };
-static swig_lua_const_info swig_input_callback_state_cls_constants[] = {
-    {0,0,0,0,0,0}
+static swig_lua_class* swig_input_callback_state_t_Sf_SwigStatic_classes[]= {
+    0
 };
-static swig_lua_class *swig_input_callback_state_bases[] = {0};
-static const char *swig_input_callback_state_base_names[] = {0};
-static swig_lua_class _wrap_class_input_callback_state = { "input_callback_state_t", &SWIGTYPE_p_input_callback_state,_wrap_new_input_callback_state_t, swig_delete_input_callback_state_t, swig_input_callback_state_methods, swig_input_callback_state_attributes, { "input_callback_state_t", swig_input_callback_state_cls_methods, swig_input_callback_state_cls_attributes, swig_input_callback_state_cls_constants }, swig_input_callback_state_bases, swig_input_callback_state_base_names };
+
+static swig_lua_namespace swig_input_callback_state_t_Sf_SwigStatic = {
+    "input_callback_state_t",
+    swig_input_callback_state_t_Sf_SwigStatic_methods,
+    swig_input_callback_state_t_Sf_SwigStatic_attributes,
+    swig_input_callback_state_t_Sf_SwigStatic_constants,
+    swig_input_callback_state_t_Sf_SwigStatic_classes,
+    0
+};
+static swig_lua_class *swig_input_callback_state_t_bases[] = {0};
+static const char *swig_input_callback_state_t_base_names[] = {0};
+static swig_lua_class _wrap_class_input_callback_state_t = { "input_callback_state_t", "input_callback_state_t", &SWIGTYPE_p_input_callback_state,_proxy__wrap_new_input_callback_state_t, swig_delete_input_callback_state_t, swig_input_callback_state_t_methods, swig_input_callback_state_t_attributes, &swig_input_callback_state_t_Sf_SwigStatic, swig_input_callback_state_t_meta, swig_input_callback_state_t_bases, swig_input_callback_state_t_base_names };
 
 static int _wrap_DTMF_digit_set(lua_State* L) {
   int SWIG_arg = 0;
@@ -2954,26 +3787,50 @@ static void swig_delete_DTMF(void *obj) {
 DTMF *arg1 = (DTMF *) obj;
 delete arg1;
 }
-static swig_lua_method swig_DTMF_methods[] = {
-    {0,0}
-};
+static int _proxy__wrap_new_DTMF(lua_State *L) {
+    assert(lua_istable(L,1));
+    lua_pushcfunction(L,_wrap_new_DTMF);
+    assert(!lua_isnil(L,-1));
+    lua_replace(L,1); /* replace our table with real constructor */
+    lua_call(L,lua_gettop(L)-1,1);
+    return 1;
+}
 static swig_lua_attribute swig_DTMF_attributes[] = {
-    { "digit", _wrap_DTMF_digit_get, _wrap_DTMF_digit_set},
-    { "duration", _wrap_DTMF_duration_get, _wrap_DTMF_duration_set},
+    { "digit", _wrap_DTMF_digit_get, _wrap_DTMF_digit_set },
+    { "duration", _wrap_DTMF_duration_get, _wrap_DTMF_duration_set },
     {0,0,0}
 };
-static swig_lua_attribute swig_DTMF_cls_attributes[] = {
-    {0,0,0}
+static swig_lua_method swig_DTMF_methods[]= {
+    {0,0}
 };
-static swig_lua_method swig_DTMF_cls_methods[] = {
+static swig_lua_method swig_DTMF_meta[] = {
     {0,0}
 };
-static swig_lua_const_info swig_DTMF_cls_constants[] = {
+
+static swig_lua_attribute swig_DTMF_Sf_SwigStatic_attributes[] = {
+    {0,0,0}
+};
+static swig_lua_const_info swig_DTMF_Sf_SwigStatic_constants[]= {
     {0,0,0,0,0,0}
 };
+static swig_lua_method swig_DTMF_Sf_SwigStatic_methods[]= {
+    {0,0}
+};
+static swig_lua_class* swig_DTMF_Sf_SwigStatic_classes[]= {
+    0
+};
+
+static swig_lua_namespace swig_DTMF_Sf_SwigStatic = {
+    "DTMF",
+    swig_DTMF_Sf_SwigStatic_methods,
+    swig_DTMF_Sf_SwigStatic_attributes,
+    swig_DTMF_Sf_SwigStatic_constants,
+    swig_DTMF_Sf_SwigStatic_classes,
+    0
+};
 static swig_lua_class *swig_DTMF_bases[] = {0};
 static const char *swig_DTMF_base_names[] = {0};
-static swig_lua_class _wrap_class_DTMF = { "DTMF", &SWIGTYPE_p_DTMF,_wrap_new_DTMF, swig_delete_DTMF, swig_DTMF_methods, swig_DTMF_attributes, { "DTMF", swig_DTMF_cls_methods, swig_DTMF_cls_attributes, swig_DTMF_cls_constants }, swig_DTMF_bases, swig_DTMF_base_names };
+static swig_lua_class _wrap_class_DTMF = { "DTMF", "DTMF", &SWIGTYPE_p_DTMF,_proxy__wrap_new_DTMF, swig_delete_DTMF, swig_DTMF_methods, swig_DTMF_attributes, &swig_DTMF_Sf_SwigStatic, swig_DTMF_meta, swig_DTMF_bases, swig_DTMF_base_names };
 
 static int _wrap_new_Stream__SWIG_0(lua_State* L) {
   int SWIG_arg = 0;
@@ -3160,28 +4017,52 @@ static void swig_delete_Stream(void *obj) {
 Stream *arg1 = (Stream *) obj;
 delete arg1;
 }
-static swig_lua_method swig_Stream_methods[] = {
-    {"read", _wrap_Stream_read}, 
-    {"write", _wrap_Stream_write}, 
-    {"raw_write", _wrap_Stream_raw_write}, 
-    {"get_data", _wrap_Stream_get_data}, 
-    {0,0}
-};
+static int _proxy__wrap_new_Stream(lua_State *L) {
+    assert(lua_istable(L,1));
+    lua_pushcfunction(L,_wrap_new_Stream);
+    assert(!lua_isnil(L,-1));
+    lua_replace(L,1); /* replace our table with real constructor */
+    lua_call(L,lua_gettop(L)-1,1);
+    return 1;
+}
 static swig_lua_attribute swig_Stream_attributes[] = {
     {0,0,0}
 };
-static swig_lua_attribute swig_Stream_cls_attributes[] = {
-    {0,0,0}
+static swig_lua_method swig_Stream_methods[]= {
+    { "read", _wrap_Stream_read},
+    { "write", _wrap_Stream_write},
+    { "raw_write", _wrap_Stream_raw_write},
+    { "get_data", _wrap_Stream_get_data},
+    {0,0}
 };
-static swig_lua_method swig_Stream_cls_methods[] = {
+static swig_lua_method swig_Stream_meta[] = {
     {0,0}
 };
-static swig_lua_const_info swig_Stream_cls_constants[] = {
+
+static swig_lua_attribute swig_Stream_Sf_SwigStatic_attributes[] = {
+    {0,0,0}
+};
+static swig_lua_const_info swig_Stream_Sf_SwigStatic_constants[]= {
     {0,0,0,0,0,0}
 };
+static swig_lua_method swig_Stream_Sf_SwigStatic_methods[]= {
+    {0,0}
+};
+static swig_lua_class* swig_Stream_Sf_SwigStatic_classes[]= {
+    0
+};
+
+static swig_lua_namespace swig_Stream_Sf_SwigStatic = {
+    "Stream",
+    swig_Stream_Sf_SwigStatic_methods,
+    swig_Stream_Sf_SwigStatic_attributes,
+    swig_Stream_Sf_SwigStatic_constants,
+    swig_Stream_Sf_SwigStatic_classes,
+    0
+};
 static swig_lua_class *swig_Stream_bases[] = {0};
 static const char *swig_Stream_base_names[] = {0};
-static swig_lua_class _wrap_class_Stream = { "Stream", &SWIGTYPE_p_Stream,_wrap_new_Stream, swig_delete_Stream, swig_Stream_methods, swig_Stream_attributes, { "Stream", swig_Stream_cls_methods, swig_Stream_cls_attributes, swig_Stream_cls_constants }, swig_Stream_bases, swig_Stream_base_names };
+static swig_lua_class _wrap_class_Stream = { "Stream", "Stream", &SWIGTYPE_p_Stream,_proxy__wrap_new_Stream, swig_delete_Stream, swig_Stream_methods, swig_Stream_attributes, &swig_Stream_Sf_SwigStatic, swig_Stream_meta, swig_Stream_bases, swig_Stream_base_names };
 
 static int _wrap_Event_event_set(lua_State* L) {
   int SWIG_arg = 0;
@@ -3764,38 +4645,62 @@ static void swig_delete_Event(void *obj) {
 Event *arg1 = (Event *) obj;
 delete arg1;
 }
-static swig_lua_method swig_Event_methods[] = {
-    {"chat_execute", _wrap_Event_chat_execute}, 
-    {"chat_send", _wrap_Event_chat_send}, 
-    {"serialize", _wrap_Event_serialize}, 
-    {"setPriority", _wrap_Event_setPriority}, 
-    {"getHeader", _wrap_Event_getHeader}, 
-    {"getBody", _wrap_Event_getBody}, 
-    {"getType", _wrap_Event_getType}, 
-    {"addBody", _wrap_Event_addBody}, 
-    {"addHeader", _wrap_Event_addHeader}, 
-    {"delHeader", _wrap_Event_delHeader}, 
-    {"fire", _wrap_Event_fire}, 
-    {0,0}
-};
+static int _proxy__wrap_new_Event(lua_State *L) {
+    assert(lua_istable(L,1));
+    lua_pushcfunction(L,_wrap_new_Event);
+    assert(!lua_isnil(L,-1));
+    lua_replace(L,1); /* replace our table with real constructor */
+    lua_call(L,lua_gettop(L)-1,1);
+    return 1;
+}
 static swig_lua_attribute swig_Event_attributes[] = {
-    { "event", _wrap_Event_event_get, _wrap_Event_event_set},
-    { "serialized_string", _wrap_Event_serialized_string_get, _wrap_Event_serialized_string_set},
-    { "mine", _wrap_Event_mine_get, _wrap_Event_mine_set},
+    { "event", _wrap_Event_event_get, _wrap_Event_event_set },
+    { "serialized_string", _wrap_Event_serialized_string_get, _wrap_Event_serialized_string_set },
+    { "mine", _wrap_Event_mine_get, _wrap_Event_mine_set },
     {0,0,0}
 };
-static swig_lua_attribute swig_Event_cls_attributes[] = {
-    {0,0,0}
+static swig_lua_method swig_Event_methods[]= {
+    { "chat_execute", _wrap_Event_chat_execute},
+    { "chat_send", _wrap_Event_chat_send},
+    { "serialize", _wrap_Event_serialize},
+    { "setPriority", _wrap_Event_setPriority},
+    { "getHeader", _wrap_Event_getHeader},
+    { "getBody", _wrap_Event_getBody},
+    { "getType", _wrap_Event_getType},
+    { "addBody", _wrap_Event_addBody},
+    { "addHeader", _wrap_Event_addHeader},
+    { "delHeader", _wrap_Event_delHeader},
+    { "fire", _wrap_Event_fire},
+    {0,0}
 };
-static swig_lua_method swig_Event_cls_methods[] = {
+static swig_lua_method swig_Event_meta[] = {
     {0,0}
 };
-static swig_lua_const_info swig_Event_cls_constants[] = {
+
+static swig_lua_attribute swig_Event_Sf_SwigStatic_attributes[] = {
+    {0,0,0}
+};
+static swig_lua_const_info swig_Event_Sf_SwigStatic_constants[]= {
     {0,0,0,0,0,0}
 };
+static swig_lua_method swig_Event_Sf_SwigStatic_methods[]= {
+    {0,0}
+};
+static swig_lua_class* swig_Event_Sf_SwigStatic_classes[]= {
+    0
+};
+
+static swig_lua_namespace swig_Event_Sf_SwigStatic = {
+    "Event",
+    swig_Event_Sf_SwigStatic_methods,
+    swig_Event_Sf_SwigStatic_attributes,
+    swig_Event_Sf_SwigStatic_constants,
+    swig_Event_Sf_SwigStatic_classes,
+    0
+};
 static swig_lua_class *swig_Event_bases[] = {0};
 static const char *swig_Event_base_names[] = {0};
-static swig_lua_class _wrap_class_Event = { "Event", &SWIGTYPE_p_Event,_wrap_new_Event, swig_delete_Event, swig_Event_methods, swig_Event_attributes, { "Event", swig_Event_cls_methods, swig_Event_cls_attributes, swig_Event_cls_constants }, swig_Event_bases, swig_Event_base_names };
+static swig_lua_class _wrap_class_Event = { "Event", "Event", &SWIGTYPE_p_Event,_proxy__wrap_new_Event, swig_delete_Event, swig_Event_methods, swig_Event_attributes, &swig_Event_Sf_SwigStatic, swig_Event_meta, swig_Event_bases, swig_Event_base_names };
 
 static int _wrap_EventConsumer_events_set(lua_State* L) {
   int SWIG_arg = 0;
@@ -4326,34 +5231,58 @@ static void swig_delete_EventConsumer(void *obj) {
 EventConsumer *arg1 = (EventConsumer *) obj;
 delete arg1;
 }
-static swig_lua_method swig_EventConsumer_methods[] = {
-    {"bind", _wrap_EventConsumer_bind}, 
-    {"pop", _wrap_EventConsumer_pop}, 
-    {"cleanup", _wrap_EventConsumer_cleanup}, 
-    {0,0}
-};
+static int _proxy__wrap_new_EventConsumer(lua_State *L) {
+    assert(lua_istable(L,1));
+    lua_pushcfunction(L,_wrap_new_EventConsumer);
+    assert(!lua_isnil(L,-1));
+    lua_replace(L,1); /* replace our table with real constructor */
+    lua_call(L,lua_gettop(L)-1,1);
+    return 1;
+}
 static swig_lua_attribute swig_EventConsumer_attributes[] = {
-    { "events", _wrap_EventConsumer_events_get, _wrap_EventConsumer_events_set},
-    { "e_event_id", _wrap_EventConsumer_e_event_id_get, _wrap_EventConsumer_e_event_id_set},
-    { "e_callback", _wrap_EventConsumer_e_callback_get, _wrap_EventConsumer_e_callback_set},
-    { "e_subclass_name", _wrap_EventConsumer_e_subclass_name_get, _wrap_EventConsumer_e_subclass_name_set},
-    { "e_cb_arg", _wrap_EventConsumer_e_cb_arg_get, _wrap_EventConsumer_e_cb_arg_set},
-    { "enodes", _wrap_EventConsumer_enodes_get, _wrap_EventConsumer_enodes_set},
-    { "node_index", _wrap_EventConsumer_node_index_get, _wrap_EventConsumer_node_index_set},
+    { "events", _wrap_EventConsumer_events_get, _wrap_EventConsumer_events_set },
+    { "e_event_id", _wrap_EventConsumer_e_event_id_get, _wrap_EventConsumer_e_event_id_set },
+    { "e_callback", _wrap_EventConsumer_e_callback_get, _wrap_EventConsumer_e_callback_set },
+    { "e_subclass_name", _wrap_EventConsumer_e_subclass_name_get, _wrap_EventConsumer_e_subclass_name_set },
+    { "e_cb_arg", _wrap_EventConsumer_e_cb_arg_get, _wrap_EventConsumer_e_cb_arg_set },
+    { "enodes", _wrap_EventConsumer_enodes_get, _wrap_EventConsumer_enodes_set },
+    { "node_index", _wrap_EventConsumer_node_index_get, _wrap_EventConsumer_node_index_set },
     {0,0,0}
 };
-static swig_lua_attribute swig_EventConsumer_cls_attributes[] = {
-    {0,0,0}
+static swig_lua_method swig_EventConsumer_methods[]= {
+    { "bind", _wrap_EventConsumer_bind},
+    { "pop", _wrap_EventConsumer_pop},
+    { "cleanup", _wrap_EventConsumer_cleanup},
+    {0,0}
 };
-static swig_lua_method swig_EventConsumer_cls_methods[] = {
+static swig_lua_method swig_EventConsumer_meta[] = {
     {0,0}
 };
-static swig_lua_const_info swig_EventConsumer_cls_constants[] = {
+
+static swig_lua_attribute swig_EventConsumer_Sf_SwigStatic_attributes[] = {
+    {0,0,0}
+};
+static swig_lua_const_info swig_EventConsumer_Sf_SwigStatic_constants[]= {
     {0,0,0,0,0,0}
 };
+static swig_lua_method swig_EventConsumer_Sf_SwigStatic_methods[]= {
+    {0,0}
+};
+static swig_lua_class* swig_EventConsumer_Sf_SwigStatic_classes[]= {
+    0
+};
+
+static swig_lua_namespace swig_EventConsumer_Sf_SwigStatic = {
+    "EventConsumer",
+    swig_EventConsumer_Sf_SwigStatic_methods,
+    swig_EventConsumer_Sf_SwigStatic_attributes,
+    swig_EventConsumer_Sf_SwigStatic_constants,
+    swig_EventConsumer_Sf_SwigStatic_classes,
+    0
+};
 static swig_lua_class *swig_EventConsumer_bases[] = {0};
 static const char *swig_EventConsumer_base_names[] = {0};
-static swig_lua_class _wrap_class_EventConsumer = { "EventConsumer", &SWIGTYPE_p_EventConsumer,_wrap_new_EventConsumer, swig_delete_EventConsumer, swig_EventConsumer_methods, swig_EventConsumer_attributes, { "EventConsumer", swig_EventConsumer_cls_methods, swig_EventConsumer_cls_attributes, swig_EventConsumer_cls_constants }, swig_EventConsumer_bases, swig_EventConsumer_base_names };
+static swig_lua_class _wrap_class_EventConsumer = { "EventConsumer", "EventConsumer", &SWIGTYPE_p_EventConsumer,_proxy__wrap_new_EventConsumer, swig_delete_EventConsumer, swig_EventConsumer_methods, swig_EventConsumer_attributes, &swig_EventConsumer_Sf_SwigStatic, swig_EventConsumer_meta, swig_EventConsumer_bases, swig_EventConsumer_base_names };
 
 static int _wrap_CoreSession_session_set(lua_State* L) {
   int SWIG_arg = 0;
@@ -6682,84 +7611,100 @@ static void swig_delete_CoreSession(void *obj) {
 CoreSession *arg1 = (CoreSession *) obj;
 delete arg1;
 }
-static swig_lua_method swig_CoreSession_methods[] = {
-    {"insertFile", _wrap_CoreSession_insertFile}, 
-    {"answer", _wrap_CoreSession_answer}, 
-    {"print", _wrap_CoreSession_print}, 
-    {"preAnswer", _wrap_CoreSession_preAnswer}, 
-    {"hangup", _wrap_CoreSession_hangup}, 
-    {"hangupState", _wrap_CoreSession_hangupState}, 
-    {"setVariable", _wrap_CoreSession_setVariable}, 
-    {"setPrivate", _wrap_CoreSession_setPrivate}, 
-    {"getPrivate", _wrap_CoreSession_getPrivate}, 
-    {"getVariable", _wrap_CoreSession_getVariable}, 
-    {"process_callback_result", _wrap_CoreSession_process_callback_result}, 
-    {"say", _wrap_CoreSession_say}, 
-    {"sayPhrase", _wrap_CoreSession_sayPhrase}, 
-    {"hangupCause", _wrap_CoreSession_hangupCause}, 
-    {"getState", _wrap_CoreSession_getState}, 
-    {"recordFile", _wrap_CoreSession_recordFile}, 
-    {"originate", _wrap_CoreSession_originate}, 
-    {"destroy", _wrap_CoreSession_destroy}, 
-    {"setDTMFCallback", _wrap_CoreSession_setDTMFCallback}, 
-    {"speak", _wrap_CoreSession_speak}, 
-    {"set_tts_parms", _wrap_CoreSession_set_tts_parms}, 
-    {"set_tts_params", _wrap_CoreSession_set_tts_params}, 
-    {"collectDigits", _wrap_CoreSession_collectDigits}, 
-    {"getDigits", _wrap_CoreSession_getDigits}, 
-    {"transfer", _wrap_CoreSession_transfer}, 
-    {"read", _wrap_CoreSession_read}, 
-    {"playAndGetDigits", _wrap_CoreSession_playAndGetDigits}, 
-    {"streamFile", _wrap_CoreSession_streamFile}, 
-    {"sleep", _wrap_CoreSession_sleep}, 
-    {"flushEvents", _wrap_CoreSession_flushEvents}, 
-    {"flushDigits", _wrap_CoreSession_flushDigits}, 
-    {"setAutoHangup", _wrap_CoreSession_setAutoHangup}, 
-    {"setHangupHook", _wrap_CoreSession_setHangupHook}, 
-    {"ready", _wrap_CoreSession_ready}, 
-    {"bridged", _wrap_CoreSession_bridged}, 
-    {"answered", _wrap_CoreSession_answered}, 
-    {"mediaReady", _wrap_CoreSession_mediaReady}, 
-    {"waitForAnswer", _wrap_CoreSession_waitForAnswer}, 
-    {"execute", _wrap_CoreSession_execute}, 
-    {"sendEvent", _wrap_CoreSession_sendEvent}, 
-    {"setEventData", _wrap_CoreSession_setEventData}, 
-    {"getXMLCDR", _wrap_CoreSession_getXMLCDR}, 
-    {"begin_allow_threads", _wrap_CoreSession_begin_allow_threads}, 
-    {"end_allow_threads", _wrap_CoreSession_end_allow_threads}, 
-    {"get_uuid", _wrap_CoreSession_get_uuid}, 
-    {"get_cb_args", _wrap_CoreSession_get_cb_args}, 
-    {"check_hangup_hook", _wrap_CoreSession_check_hangup_hook}, 
-    {"run_dtmf_callback", _wrap_CoreSession_run_dtmf_callback}, 
-    {"consoleLog", _wrap_CoreSession_consoleLog}, 
-    {"consoleLog2", _wrap_CoreSession_consoleLog2}, 
-    {0,0}
-};
 static swig_lua_attribute swig_CoreSession_attributes[] = {
-    { "session", _wrap_CoreSession_session_get, _wrap_CoreSession_session_set},
-    { "channel", _wrap_CoreSession_channel_get, _wrap_CoreSession_channel_set},
-    { "flags", _wrap_CoreSession_flags_get, _wrap_CoreSession_flags_set},
-    { "allocated", _wrap_CoreSession_allocated_get, _wrap_CoreSession_allocated_set},
-    { "cb_state", _wrap_CoreSession_cb_state_get, _wrap_CoreSession_cb_state_set},
-    { "hook_state", _wrap_CoreSession_hook_state_get, _wrap_CoreSession_hook_state_set},
-    { "cause", _wrap_CoreSession_cause_get, _wrap_CoreSession_cause_set},
-    { "uuid", _wrap_CoreSession_uuid_get, _wrap_CoreSession_uuid_set},
-    { "tts_name", _wrap_CoreSession_tts_name_get, _wrap_CoreSession_tts_name_set},
-    { "voice_name", _wrap_CoreSession_voice_name_get, _wrap_CoreSession_voice_name_set},
+    { "session", _wrap_CoreSession_session_get, _wrap_CoreSession_session_set },
+    { "channel", _wrap_CoreSession_channel_get, _wrap_CoreSession_channel_set },
+    { "flags", _wrap_CoreSession_flags_get, _wrap_CoreSession_flags_set },
+    { "allocated", _wrap_CoreSession_allocated_get, _wrap_CoreSession_allocated_set },
+    { "cb_state", _wrap_CoreSession_cb_state_get, _wrap_CoreSession_cb_state_set },
+    { "hook_state", _wrap_CoreSession_hook_state_get, _wrap_CoreSession_hook_state_set },
+    { "cause", _wrap_CoreSession_cause_get, _wrap_CoreSession_cause_set },
+    { "uuid", _wrap_CoreSession_uuid_get, _wrap_CoreSession_uuid_set },
+    { "tts_name", _wrap_CoreSession_tts_name_get, _wrap_CoreSession_tts_name_set },
+    { "voice_name", _wrap_CoreSession_voice_name_get, _wrap_CoreSession_voice_name_set },
     {0,0,0}
 };
-static swig_lua_attribute swig_CoreSession_cls_attributes[] = {
-    {0,0,0}
+static swig_lua_method swig_CoreSession_methods[]= {
+    { "insertFile", _wrap_CoreSession_insertFile},
+    { "answer", _wrap_CoreSession_answer},
+    { "print", _wrap_CoreSession_print},
+    { "preAnswer", _wrap_CoreSession_preAnswer},
+    { "hangup", _wrap_CoreSession_hangup},
+    { "hangupState", _wrap_CoreSession_hangupState},
+    { "setVariable", _wrap_CoreSession_setVariable},
+    { "setPrivate", _wrap_CoreSession_setPrivate},
+    { "getPrivate", _wrap_CoreSession_getPrivate},
+    { "getVariable", _wrap_CoreSession_getVariable},
+    { "process_callback_result", _wrap_CoreSession_process_callback_result},
+    { "say", _wrap_CoreSession_say},
+    { "sayPhrase", _wrap_CoreSession_sayPhrase},
+    { "hangupCause", _wrap_CoreSession_hangupCause},
+    { "getState", _wrap_CoreSession_getState},
+    { "recordFile", _wrap_CoreSession_recordFile},
+    { "originate", _wrap_CoreSession_originate},
+    { "destroy", _wrap_CoreSession_destroy},
+    { "setDTMFCallback", _wrap_CoreSession_setDTMFCallback},
+    { "speak", _wrap_CoreSession_speak},
+    { "set_tts_parms", _wrap_CoreSession_set_tts_parms},
+    { "set_tts_params", _wrap_CoreSession_set_tts_params},
+    { "collectDigits", _wrap_CoreSession_collectDigits},
+    { "getDigits", _wrap_CoreSession_getDigits},
+    { "transfer", _wrap_CoreSession_transfer},
+    { "read", _wrap_CoreSession_read},
+    { "playAndGetDigits", _wrap_CoreSession_playAndGetDigits},
+    { "streamFile", _wrap_CoreSession_streamFile},
+    { "sleep", _wrap_CoreSession_sleep},
+    { "flushEvents", _wrap_CoreSession_flushEvents},
+    { "flushDigits", _wrap_CoreSession_flushDigits},
+    { "setAutoHangup", _wrap_CoreSession_setAutoHangup},
+    { "setHangupHook", _wrap_CoreSession_setHangupHook},
+    { "ready", _wrap_CoreSession_ready},
+    { "bridged", _wrap_CoreSession_bridged},
+    { "answered", _wrap_CoreSession_answered},
+    { "mediaReady", _wrap_CoreSession_mediaReady},
+    { "waitForAnswer", _wrap_CoreSession_waitForAnswer},
+    { "execute", _wrap_CoreSession_execute},
+    { "sendEvent", _wrap_CoreSession_sendEvent},
+    { "setEventData", _wrap_CoreSession_setEventData},
+    { "getXMLCDR", _wrap_CoreSession_getXMLCDR},
+    { "begin_allow_threads", _wrap_CoreSession_begin_allow_threads},
+    { "end_allow_threads", _wrap_CoreSession_end_allow_threads},
+    { "get_uuid", _wrap_CoreSession_get_uuid},
+    { "get_cb_args", _wrap_CoreSession_get_cb_args},
+    { "check_hangup_hook", _wrap_CoreSession_check_hangup_hook},
+    { "run_dtmf_callback", _wrap_CoreSession_run_dtmf_callback},
+    { "consoleLog", _wrap_CoreSession_consoleLog},
+    { "consoleLog2", _wrap_CoreSession_consoleLog2},
+    {0,0}
 };
-static swig_lua_method swig_CoreSession_cls_methods[] = {
+static swig_lua_method swig_CoreSession_meta[] = {
     {0,0}
 };
-static swig_lua_const_info swig_CoreSession_cls_constants[] = {
+
+static swig_lua_attribute swig_CoreSession_Sf_SwigStatic_attributes[] = {
+    {0,0,0}
+};
+static swig_lua_const_info swig_CoreSession_Sf_SwigStatic_constants[]= {
     {0,0,0,0,0,0}
 };
+static swig_lua_method swig_CoreSession_Sf_SwigStatic_methods[]= {
+    {0,0}
+};
+static swig_lua_class* swig_CoreSession_Sf_SwigStatic_classes[]= {
+    0
+};
+
+static swig_lua_namespace swig_CoreSession_Sf_SwigStatic = {
+    "CoreSession",
+    swig_CoreSession_Sf_SwigStatic_methods,
+    swig_CoreSession_Sf_SwigStatic_attributes,
+    swig_CoreSession_Sf_SwigStatic_constants,
+    swig_CoreSession_Sf_SwigStatic_classes,
+    0
+};
 static swig_lua_class *swig_CoreSession_bases[] = {0};
 static const char *swig_CoreSession_base_names[] = {0};
-static swig_lua_class _wrap_class_CoreSession = { "CoreSession", &SWIGTYPE_p_CoreSession,0, swig_delete_CoreSession, swig_CoreSession_methods, swig_CoreSession_attributes, { "CoreSession", swig_CoreSession_cls_methods, swig_CoreSession_cls_attributes, swig_CoreSession_cls_constants }, swig_CoreSession_bases, swig_CoreSession_base_names };
+static swig_lua_class _wrap_class_CoreSession = { "CoreSession", "CoreSession", &SWIGTYPE_p_CoreSession,0, swig_delete_CoreSession, swig_CoreSession_methods, swig_CoreSession_attributes, &swig_CoreSession_Sf_SwigStatic, swig_CoreSession_meta, swig_CoreSession_bases, swig_CoreSession_base_names };
 
 static int _wrap_console_log(lua_State* L) {
   int SWIG_arg = 0;
@@ -7888,39 +8833,63 @@ static void swig_delete_Session(void *obj) {
 LUA::Session *arg1 = (LUA::Session *) obj;
 delete arg1;
 }
-static swig_lua_method swig_LUA_Session_methods[] = {
-    {"destroy", _wrap_Session_destroy}, 
-    {"begin_allow_threads", _wrap_Session_begin_allow_threads}, 
-    {"end_allow_threads", _wrap_Session_end_allow_threads}, 
-    {"check_hangup_hook", _wrap_Session_check_hangup_hook}, 
-    {"run_dtmf_callback", _wrap_Session_run_dtmf_callback}, 
-    {"unsetInputCallback", _wrap_Session_unsetInputCallback}, 
-    {"setInputCallback", _wrap_Session_setInputCallback}, 
-    {"setHangupHook", _wrap_Session_setHangupHook}, 
-    {"ready", _wrap_Session_ready}, 
-    {"originate", _wrap_Session_originate}, 
-    {"setLUA", _wrap_Session_setLUA}, 
+static int _proxy__wrap_new_Session(lua_State *L) {
+    assert(lua_istable(L,1));
+    lua_pushcfunction(L,_wrap_new_Session);
+    assert(!lua_isnil(L,-1));
+    lua_replace(L,1); /* replace our table with real constructor */
+    lua_call(L,lua_gettop(L)-1,1);
+    return 1;
+}
+static swig_lua_attribute swig_Session_attributes[] = {
+    { "cb_function", _wrap_Session_cb_function_get, _wrap_Session_cb_function_set },
+    { "cb_arg", _wrap_Session_cb_arg_get, _wrap_Session_cb_arg_set },
+    { "hangup_func_str", _wrap_Session_hangup_func_str_get, _wrap_Session_hangup_func_str_set },
+    { "hangup_func_arg", _wrap_Session_hangup_func_arg_get, _wrap_Session_hangup_func_arg_set },
+    {0,0,0}
+};
+static swig_lua_method swig_Session_methods[]= {
+    { "destroy", _wrap_Session_destroy},
+    { "begin_allow_threads", _wrap_Session_begin_allow_threads},
+    { "end_allow_threads", _wrap_Session_end_allow_threads},
+    { "check_hangup_hook", _wrap_Session_check_hangup_hook},
+    { "run_dtmf_callback", _wrap_Session_run_dtmf_callback},
+    { "unsetInputCallback", _wrap_Session_unsetInputCallback},
+    { "setInputCallback", _wrap_Session_setInputCallback},
+    { "setHangupHook", _wrap_Session_setHangupHook},
+    { "ready", _wrap_Session_ready},
+    { "originate", _wrap_Session_originate},
+    { "setLUA", _wrap_Session_setLUA},
     {0,0}
 };
-static swig_lua_attribute swig_LUA_Session_attributes[] = {
-    { "cb_function", _wrap_Session_cb_function_get, _wrap_Session_cb_function_set},
-    { "cb_arg", _wrap_Session_cb_arg_get, _wrap_Session_cb_arg_set},
-    { "hangup_func_str", _wrap_Session_hangup_func_str_get, _wrap_Session_hangup_func_str_set},
-    { "hangup_func_arg", _wrap_Session_hangup_func_arg_get, _wrap_Session_hangup_func_arg_set},
-    {0,0,0}
+static swig_lua_method swig_Session_meta[] = {
+    {0,0}
 };
-static swig_lua_attribute swig_LUA_Session_cls_attributes[] = {
+
+static swig_lua_attribute swig_Session_Sf_SwigStatic_attributes[] = {
     {0,0,0}
 };
-static swig_lua_method swig_LUA_Session_cls_methods[] = {
+static swig_lua_const_info swig_Session_Sf_SwigStatic_constants[]= {
+    {0,0,0,0,0,0}
+};
+static swig_lua_method swig_Session_Sf_SwigStatic_methods[]= {
     {0,0}
 };
-static swig_lua_const_info swig_LUA_Session_cls_constants[] = {
-    {0,0,0,0,0,0}
+static swig_lua_class* swig_Session_Sf_SwigStatic_classes[]= {
+    0
 };
-static swig_lua_class *swig_LUA_Session_bases[] = {0,0};
-static const char *swig_LUA_Session_base_names[] = {"CoreSession *",0};
-static swig_lua_class _wrap_class_LUA_Session = { "Session", &SWIGTYPE_p_LUA__Session,_wrap_new_Session, swig_delete_Session, swig_LUA_Session_methods, swig_LUA_Session_attributes, { "Session", swig_LUA_Session_cls_methods, swig_LUA_Session_cls_attributes, swig_LUA_Session_cls_constants }, swig_LUA_Session_bases, swig_LUA_Session_base_names };
+
+static swig_lua_namespace swig_Session_Sf_SwigStatic = {
+    "Session",
+    swig_Session_Sf_SwigStatic_methods,
+    swig_Session_Sf_SwigStatic_attributes,
+    swig_Session_Sf_SwigStatic_constants,
+    swig_Session_Sf_SwigStatic_classes,
+    0
+};
+static swig_lua_class *swig_Session_bases[] = {0,0};
+static const char *swig_Session_base_names[] = {"CoreSession *",0};
+static swig_lua_class _wrap_class_Session = { "Session", "Session", &SWIGTYPE_p_LUA__Session,_proxy__wrap_new_Session, swig_delete_Session, swig_Session_methods, swig_Session_attributes, &swig_Session_Sf_SwigStatic, swig_Session_meta, swig_Session_bases, swig_Session_base_names };
 
 static int _wrap_new_Dbh__SWIG_0(lua_State* L) {
   int SWIG_arg = 0;
@@ -8420,38 +9389,67 @@ static void swig_delete_Dbh(void *obj) {
 LUA::Dbh *arg1 = (LUA::Dbh *) obj;
 delete arg1;
 }
-static swig_lua_method swig_LUA_Dbh_methods[] = {
-    {"release", _wrap_Dbh_release}, 
-    {"connected", _wrap_Dbh_connected}, 
-    {"test_reactive", _wrap_Dbh_test_reactive}, 
-    {"query", _wrap_Dbh_query}, 
-    {"affected_rows", _wrap_Dbh_affected_rows}, 
-    {"last_error", _wrap_Dbh_last_error}, 
-    {"clear_error", _wrap_Dbh_clear_error}, 
-    {"load_extension", _wrap_Dbh_load_extension}, 
+static int _proxy__wrap_new_Dbh(lua_State *L) {
+    assert(lua_istable(L,1));
+    lua_pushcfunction(L,_wrap_new_Dbh);
+    assert(!lua_isnil(L,-1));
+    lua_replace(L,1); /* replace our table with real constructor */
+    lua_call(L,lua_gettop(L)-1,1);
+    return 1;
+}
+static swig_lua_attribute swig_Dbh_attributes[] = {
+    {0,0,0}
+};
+static swig_lua_method swig_Dbh_methods[]= {
+    { "release", _wrap_Dbh_release},
+    { "connected", _wrap_Dbh_connected},
+    { "test_reactive", _wrap_Dbh_test_reactive},
+    { "query", _wrap_Dbh_query},
+    { "affected_rows", _wrap_Dbh_affected_rows},
+    { "last_error", _wrap_Dbh_last_error},
+    { "clear_error", _wrap_Dbh_clear_error},
+    { "load_extension", _wrap_Dbh_load_extension},
     {0,0}
 };
-static swig_lua_attribute swig_LUA_Dbh_attributes[] = {
-    {0,0,0}
+static swig_lua_method swig_Dbh_meta[] = {
+    {0,0}
 };
-static swig_lua_attribute swig_LUA_Dbh_cls_attributes[] = {
+
+static swig_lua_attribute swig_Dbh_Sf_SwigStatic_attributes[] = {
     {0,0,0}
 };
-static swig_lua_method swig_LUA_Dbh_cls_methods[] = {
+static swig_lua_const_info swig_Dbh_Sf_SwigStatic_constants[]= {
+    {0,0,0,0,0,0}
+};
+static swig_lua_method swig_Dbh_Sf_SwigStatic_methods[]= {
     {0,0}
 };
-static swig_lua_const_info swig_LUA_Dbh_cls_constants[] = {
-    {0,0,0,0,0,0}
+static swig_lua_class* swig_Dbh_Sf_SwigStatic_classes[]= {
+    0
 };
-static swig_lua_class *swig_LUA_Dbh_bases[] = {0};
-static const char *swig_LUA_Dbh_base_names[] = {0};
-static swig_lua_class _wrap_class_LUA_Dbh = { "Dbh", &SWIGTYPE_p_LUA__Dbh,_wrap_new_Dbh, swig_delete_Dbh, swig_LUA_Dbh_methods, swig_LUA_Dbh_attributes, { "Dbh", swig_LUA_Dbh_cls_methods, swig_LUA_Dbh_cls_attributes, swig_LUA_Dbh_cls_constants }, swig_LUA_Dbh_bases, swig_LUA_Dbh_base_names };
 
-#ifdef __cplusplus
-}
-#endif
+static swig_lua_namespace swig_Dbh_Sf_SwigStatic = {
+    "Dbh",
+    swig_Dbh_Sf_SwigStatic_methods,
+    swig_Dbh_Sf_SwigStatic_attributes,
+    swig_Dbh_Sf_SwigStatic_constants,
+    swig_Dbh_Sf_SwigStatic_classes,
+    0
+};
+static swig_lua_class *swig_Dbh_bases[] = {0};
+static const char *swig_Dbh_base_names[] = {0};
+static swig_lua_class _wrap_class_Dbh = { "Dbh", "Dbh", &SWIGTYPE_p_LUA__Dbh,_proxy__wrap_new_Dbh, swig_delete_Dbh, swig_Dbh_methods, swig_Dbh_attributes, &swig_Dbh_Sf_SwigStatic, swig_Dbh_meta, swig_Dbh_bases, swig_Dbh_base_names };
 
-static const struct luaL_Reg swig_commands[] = {
+static swig_lua_attribute swig_SwigModule_attributes[] = {
+    {0,0,0}
+};
+static swig_lua_const_info swig_SwigModule_constants[]= {
+    {SWIG_LUA_CONSTTAB_INT("S_HUP", S_HUP)},
+    {SWIG_LUA_CONSTTAB_INT("S_FREE", S_FREE)},
+    {SWIG_LUA_CONSTTAB_INT("S_RDLOCK", S_RDLOCK)},
+    {0,0,0,0,0,0}
+};
+static swig_lua_method swig_SwigModule_methods[]= {
     { "setGlobalVariable", _wrap_setGlobalVariable},
     { "getGlobalVariable", _wrap_getGlobalVariable},
     { "consoleLog", _wrap_consoleLog},
@@ -8468,17 +9466,34 @@ static const struct luaL_Reg swig_commands[] = {
     { "dtmf_callback", _wrap_dtmf_callback},
     {0,0}
 };
-
-static swig_lua_var_info swig_variables[] = {
-    {0,0,0}
+static swig_lua_class* swig_SwigModule_classes[]= {
+&_wrap_class_IVRMenu,
+&_wrap_class_API,
+&_wrap_class_input_callback_state_t,
+&_wrap_class_DTMF,
+&_wrap_class_Stream,
+&_wrap_class_Event,
+&_wrap_class_EventConsumer,
+&_wrap_class_CoreSession,
+&_wrap_class_Session,
+&_wrap_class_Dbh,
+    0
+};
+static swig_lua_namespace* swig_SwigModule_namespaces[] = {
+    0
 };
 
-static swig_lua_const_info swig_constants[] = {
-    {SWIG_LUA_CONSTTAB_INT("S_HUP", S_HUP)},
-    {SWIG_LUA_CONSTTAB_INT("S_FREE", S_FREE)},
-    {SWIG_LUA_CONSTTAB_INT("S_RDLOCK", S_RDLOCK)},
-    {0,0,0,0,0,0}
+static swig_lua_namespace swig_SwigModule = {
+    "freeswitch",
+    swig_SwigModule_methods,
+    swig_SwigModule_attributes,
+    swig_SwigModule_constants,
+    swig_SwigModule_classes,
+    swig_SwigModule_namespaces
 };
+#ifdef __cplusplus
+}
+#endif
 
 /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
 
@@ -8491,11 +9506,11 @@ static swig_type_info _swigt__p_DTMF = {"_p_DTMF", "DTMF *", 0, 0, (void*)&_wrap
 static swig_type_info _swigt__p_Event = {"_p_Event", "Event *", 0, 0, (void*)&_wrap_class_Event, 0};
 static swig_type_info _swigt__p_EventConsumer = {"_p_EventConsumer", "EventConsumer *", 0, 0, (void*)&_wrap_class_EventConsumer, 0};
 static swig_type_info _swigt__p_IVRMenu = {"_p_IVRMenu", "IVRMenu *", 0, 0, (void*)&_wrap_class_IVRMenu, 0};
-static swig_type_info _swigt__p_LUA__Dbh = {"_p_LUA__Dbh", "LUA::Dbh *", 0, 0, (void*)&_wrap_class_LUA_Dbh, 0};
-static swig_type_info _swigt__p_LUA__Session = {"_p_LUA__Session", "LUA::Session *", 0, 0, (void*)&_wrap_class_LUA_Session, 0};
+static swig_type_info _swigt__p_LUA__Dbh = {"_p_LUA__Dbh", "LUA::Dbh *", 0, 0, (void*)&_wrap_class_Dbh, 0};
+static swig_type_info _swigt__p_LUA__Session = {"_p_LUA__Session", "LUA::Session *", 0, 0, (void*)&_wrap_class_Session, 0};
 static swig_type_info _swigt__p_SWIGLUA_FN = {"_p_SWIGLUA_FN", "SWIGLUA_FN *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_Stream = {"_p_Stream", "Stream *", 0, 0, (void*)&_wrap_class_Stream, 0};
-static swig_type_info _swigt__p_input_callback_state = {"_p_input_callback_state", "input_callback_state_t *|input_callback_state *", 0, 0, (void*)&_wrap_class_input_callback_state, 0};
+static swig_type_info _swigt__p_input_callback_state = {"_p_input_callback_state", "input_callback_state_t *|input_callback_state *", 0, 0, (void*)&_wrap_class_input_callback_state_t, 0};
 static swig_type_info _swigt__p_int = {"_p_int", "int *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_lua_State = {"_p_lua_State", "lua_State *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_p_switch_event_node_t = {"_p_p_switch_event_node_t", "switch_event_node_t **", 0, 0, (void*)0, 0};
@@ -8629,7 +9644,7 @@ static swig_cast_info *swig_cast_initial[] = {
  * array with the correct data and linking the correct swig_cast_info
  * structures together.
  *
- * The generated swig_type_info structures are assigned staticly to an initial
+ * The generated swig_type_info structures are assigned statically to an initial
  * array. We just loop through that array, and handle each type individually.
  * First we lookup if this type has been already loaded, and if so, use the
  * loaded structure instead of the generated one. Then we have to fill in the
@@ -8871,27 +9886,18 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
 {
 #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) /* valid for both Lua and eLua */
   int i;
+  int globalRegister = 0;
   /* start with global table */
   lua_pushglobaltable (L);
-  /* SWIG's internal initalisation */
+  /* SWIG's internal initialisation */
   SWIG_InitializeModule((void*)L);
   SWIG_PropagateClientData();
 #endif
 
-#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
+#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)) || defined(SWIG_LUA_ELUA_EMULATE)
   /* add a global fn */
   SWIG_Lua_add_function(L,"swig_type",SWIG_Lua_type);
-  SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_equal);
-  /* begin the module (its a table with the same name as the module) */
-  SWIG_Lua_module_begin(L,SWIG_name);
-  /* add commands/functions */
-  for (i = 0; swig_commands[i].name; i++){
-    SWIG_Lua_module_add_function(L,swig_commands[i].name,swig_commands[i].func);
-  }
-  /* add variables */
-  for (i = 0; swig_variables[i].name; i++){
-    SWIG_Lua_module_add_variable(L,swig_variables[i].name,swig_variables[i].get,swig_variables[i].set);
-  }
+  SWIG_Lua_add_function(L,"swig_equals",SWIG_Lua_class_equal);
 #endif
 
 #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
@@ -8901,17 +9907,34 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
       SWIG_Lua_init_base_class(L,(swig_lua_class*)(swig_types[i]->clientdata));
     }
   }
-  /* additional registration structs & classes in lua */
+#ifdef SWIG_LUA_MODULE_GLOBAL
+  globalRegister = 1;
+#endif
+
+
+#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
+  SWIG_Lua_namespace_register(L,&swig_SwigModule, globalRegister);
+#endif
+
+#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
   for (i = 0; swig_types[i]; i++){
     if (swig_types[i]->clientdata){
-      SWIG_Lua_class_register(L,(swig_lua_class*)(swig_types[i]->clientdata));
+      SWIG_Lua_elua_class_register_instance(L,(swig_lua_class*)(swig_types[i]->clientdata));
     }
   }
 #endif
 
-#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
-  /* constants */
-  SWIG_Lua_InstallConstants(L,swig_constants);
+#if defined(SWIG_LUA_ELUA_EMULATE)
+  lua_newtable(L);
+  SWIG_Lua_elua_emulate_register(L,swig_SwigModule.ns_methods);
+  SWIG_Lua_elua_emulate_register_clear(L);
+  if(globalRegister) {
+    lua_pushstring(L,swig_SwigModule.name);
+    lua_pushvalue(L,-2);
+    lua_rawset(L,-4);
+  }
+#endif
+
 #endif
 
 #if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)