lua-users home
lua-l archive

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


Hello Greg,

The reason for this is that SWIG treats "char*" as a string and "unsigned char*" as a pointer. Thats why you get it as a userdata.

Adding a 
%apply char*  {xmlChar*};
at the start of the module file should tell SWIG to treat xmChar* as char*

Hope this helps,
Regards,
Mark

> Hi,
> 
> I'm a swig novice trying to use to wrap libxml2 for lua.  It was
> fairly easy to get to the point where I can read and crawl an XML
> file, but I can't see how to get at string data.  Example:
> 
> require("libxml");  --my swig module name
> doc = libxml.xmlReadFile("./test.xml", 0, 0)
> ch=doc.children
> print(ch.type)
> => 3  -- ok, means ELEMENT node
> print(ch.name)
> => userdata: 0x835...
> 
> But ch.name should be "test", the element name.  In libxml2 it's a
> "const xmlChar*", and xmlChar is typedefed to unsigned char.  (See
> http://xmlsoft.org/html/libxml-tree.html#xmlNode)
> 
> Anybody know how to get the userdata dereferenced properly, so normal
> lua syntax will work for such fields?
> 
> btw, I first tried tolua, but it seems to be outdated and I'm on 5.1.1.
> 
> Thanks,
> 
> gregg
>