summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/LuaXML.cc43
1 files changed, 39 insertions, 4 deletions
diff --git a/lib/LuaXML.cc b/lib/LuaXML.cc
index 606870e..93a3fb7 100644
--- a/lib/LuaXML.cc
+++ b/lib/LuaXML.cc
@@ -1,8 +1,9 @@
#include "tinyxml.h"
+#include <Handle.h>
#include <BLua.h>
-void LuaXML_ParseNode (lua_State *L,TiXmlNode* pNode) { PROFILE
+void LuaXML_ParseNode (lua_State *L,TiXmlNode* pNode) {
if (!pNode) return;
// resize stack if neccessary
luaL_checkstack(L, 5, "LuaXML_ParseNode : recursion too deep");
@@ -58,7 +59,7 @@ void LuaXML_ParseNode (lua_State *L,TiXmlNode* pNode) { PROFILE
}
}
-static int LuaXML_ParseFile (lua_State *L) { PROFILE
+static int LuaXML_ParseFile (lua_State *L) {
const char* sFileName = luaL_checkstring(L,1);
TiXmlDocument doc(sFileName);
doc.LoadFile();
@@ -67,6 +68,40 @@ static int LuaXML_ParseFile (lua_State *L) { PROFILE
return 1;
}
-void RegisterLuaXML (lua_State *L) {
- lua_register(L,"LuaXML_ParseFile",LuaXML_ParseFile);
+static int LuaXML_ParseString(lua_State *L) {
+ const char * xml_string = luaL_checkstring(L, 1);
+ TiXmlDocument doc;
+ doc.Parse(xml_string);
+ lua_newtable(L);
+ LuaXML_ParseNode(L, &doc);
+}
+
+#define XMLBUFSIZ 81920
+
+static int LuaXML_ParseHandle(lua_State *__L) {
+ Lua * L = Lua::find(__L);
+ Handle * h = (Handle *) LuaObject::getme(L, 1);
+ TiXmlDocument doc;
+ char buffer[XMLBUFSIZ + 1];
+ int l;
+
+ while (!h->IsClosed()) {
+ l = h->read(buffer, XMLBUFSIZ);
+ buffer[l] = 0;
+ doc.Parse(buffer);
+ }
+
+ lua_newtable(__L);
+ LuaXML_ParseNode(__L, &doc);
+}
+
+static const luaL_reg xmllib[] = {
+ { "LoadString", LuaXML_ParseString },
+ { "LoadHandle", LuaXML_ParseHandle },
+ { NULL, NULL }
+};
+
+int luaopen_xml(Lua *L) {
+ L->openlib("xml", xmllib, 0);
+ return 1;
}