lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Oct 7, 2012 at 4:09 PM, mitch abaza <mitch.abaza@gmail.com> wrote:
> My Lua code is calling a third party C++ library that returns userdata.  I
> need to serialize said userdata into JSON, which seems like a tricky
> proposition. If I can transform the userdata object into a table, then I can
> leverage existing lua packages to get my data into JSON.  Can anyone provide
> generic code that can transform userdata into tables?

No. The whole point of userdata is that it is an opaque reference to
unknown data. Even though you could potentially extract the contents
of any full userdata as a Lua string, it is very likely to involve
memory pointers that are unsuitable for serialization. Unless the C++
library in question has other functions/methods that allow you to
extract all meaningful state information (into basic
string/number/boolean type values) for whatever this specific kind of
userdata represents, you may be out of luck.

-Duncan