object serialization

Szymon Gatner <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
Hi,

what would be the simple and elegant way to do serialization /
persistance of a specific luabind::object?

I only need to save numeric and string values and tables of them. I
was thinking about recursive visitation like so:

void visit(const luabind::object& obj)
{
  using namespace luabind;

  if (type(obj) == LUA_TTABLE)
  {
    cout << "{" << endl;

    for (luabind::iterator it(obj); it != luabind::iterator(); ++it)
    {
      if (type(it.key()) == LUA_TSTRING)
      {
        if (type(*it) != LUA_TTABLE)
        {
          cout << it.key() << " = " << *it << endl;
        }
        else
        {
          visit(*it);
        }
      }
    }

    cout << "}" << endl;
  }
}

cout is used here to print name/value pairs but in real case actual
persistance code would be used.

Am I going the right way?

Cheers,
Szymon

------------------------------------------------------------------------------
Fulfilling the Lean Software Promise
Lean software platforms are now widely adopted and the benefits have been 
demonstrated beyond question. Learn why your peers are replacing JEE 
containers with lightweight application servers - and what you can gain 
from the move. http://p.sf.net/sfu/vmware-sfemails
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.