THRIFT-2882 Lua Generator: using string.len funtion to get struct(map,list,set) size
diff --git a/compiler/cpp/src/generate/t_lua_generator.cc b/compiler/cpp/src/generate/t_lua_generator.cc
index 5703ecb..46a9a90 100644
--- a/compiler/cpp/src/generate/t_lua_generator.cc
+++ b/compiler/cpp/src/generate/t_lua_generator.cc
@@ -963,14 +963,14 @@
   if (ttype->is_map()) {
     indent(out) << "oprot:writeMapBegin(" << type_to_enum(((t_map*)ttype)->get_key_type()) << ", "
                 << type_to_enum(((t_map*)ttype)->get_val_type()) << ", "
-                << "string.len(" << prefix << "))" << endl;
+                << "ttable_size(" << prefix << "))" << endl;
   } else if (ttype->is_set()) {
     indent(out) << "oprot:writeSetBegin(" << type_to_enum(((t_set*)ttype)->get_elem_type()) << ", "
-                << "string.len(" << prefix << "))" << endl;
+                << "ttable_size(" << prefix << "))" << endl;
   } else if (ttype->is_list()) {
     indent(out) << "oprot:writeListBegin(" << type_to_enum(((t_list*)ttype)->get_elem_type())
                 << ", "
-                << "string.len(" << prefix << "))" << endl;
+                << "#" << prefix << ")" << endl;
   }
 
   // Serialize
diff --git a/lib/lua/Thrift.lua b/lib/lua/Thrift.lua
index da5bb63..a9a9078 100644
--- a/lib/lua/Thrift.lua
+++ b/lib/lua/Thrift.lua
@@ -40,6 +40,14 @@
   error(e)
 end
 
+function ttable_size(t)
+  local count = 0
+  for k, v in pairs(t) do
+    count = count + 1
+  end
+  return count
+end
+
 version = 1.0
 
 TType = {