Created
March 10, 2010 23:33
-
-
Save torus/328590 to your computer and use it in GitHub Desktop.
SWIG interface file for LibXML2 tree API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use SWIG version >= 1.3.40 | |
%module libxml2 | |
%{ | |
#include <libxml2/libxml/tree.h> | |
#include <stdio.h> | |
%} | |
%native(nullNs) int getNullNs (lua_State *L); | |
%{ | |
int getNullNs (lua_State *L) | |
{ | |
lua_pushlightuserdata (L, NULL); | |
return 1; | |
} | |
%} | |
%typemap(in) xmlChar* { | |
$1 = (xmlChar*) (lua_tostring (L, $input)); | |
} | |
%typemap(in) xmlNs* { | |
$1 = (xmlNs*) (lua_topointer (L, $input)); | |
} | |
%typemap(out) xmlChar* { | |
lua_pushstring (L, (const char*)$1); | |
SWIG_arg ++; | |
} | |
%typemap(in, numinputs=0) (xmlChar ** mem, int * size) (xmlChar *temp, int templen) { | |
$1 = &temp; | |
$2 = &templen; | |
} | |
%typemap(argout) (xmlChar ** mem, int * size) { | |
// Append output value $1 to $result | |
lua_pushlstring (L, *$1, *$2); | |
SWIG_arg ++; | |
} | |
%include </usr/include/libxml2/libxml/xmlexports.h> | |
%include </usr/include/libxml2/libxml/xmlversion.h> | |
%include </usr/include/libxml2/libxml/tree.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "xml" | |
local doc = xml.NewDoc "1.0" | |
local root = xml.NewNode (xml.nullNs, "root") | |
local child = xml.NewNode (xml.nullNs, "child") | |
xml.AddChild (root, child) | |
xml.DocSetRootElement (doc, root) | |
xml.NodeAddContent (child, "text content") | |
xml.SetProp (child, "attr", "value") | |
local str = xml.DocDumpMemory (doc) | |
print (str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
libxml2.so: libxml2_wrap.c | |
gcc -g -shared -fPIC -I/usr/include/libxml2 -o $@ $< -L/usr/lib/libxml2 -lxml2 | |
libxml2_wrap.c: libxml2.i | |
swig -lua -o $@ $< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "libxml2" | |
xml = {} | |
setmetatable (xml, {__index = function (tbl, key) return libxml2["xml" .. key] end}) | |
xml.nullNs = libxml2.nullNs () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment