diff --git a/Lua/lib/liblua.a b/Lua/lib/liblua.a new file mode 100644 index 0000000..ff13531 Binary files /dev/null and b/Lua/lib/liblua.a differ diff --git a/Lua/lib/lua b/Lua/lib/lua new file mode 100755 index 0000000..e2fc049 Binary files /dev/null and b/Lua/lib/lua differ diff --git a/Lua/lib/pugilua.dll b/Lua/lib/pugilua.dll index a6c982e..20c03b6 100644 Binary files a/Lua/lib/pugilua.dll and b/Lua/lib/pugilua.dll differ diff --git a/Lua/lib/pugilua.lib b/Lua/lib/pugilua.lib index 38324fb..ee888c5 100644 Binary files a/Lua/lib/pugilua.lib and b/Lua/lib/pugilua.lib differ diff --git a/Lua/lib/test.lua b/Lua/lib/test.lua index b412417..20a500b 100644 --- a/Lua/lib/test.lua +++ b/Lua/lib/test.lua @@ -34,4 +34,24 @@ end ---- node=doc:root():child('Project') -print(node.text) \ No newline at end of file +print(node.text) + +---- +doc:reset() +--- from the tutorial +-- add node with some name +local node = doc:root():append_child("node"); + +-- add description node with text child +local descr = node:append_child("description"); +descr:append(pugi.node_pcdata):set_value("Simple node"); + +-- add param node before the description +local param = node:insert_child_before("param", descr); + +-- add attributes to param node +param:append_attribute("name"):set_value("version"); +param:append_attribute("value"):set_value(1.1); +param:insert_attribute_after("type", param:attribute("name")):set_value("float"); + +print(doc:save_file("tutorial.xml")); \ No newline at end of file diff --git a/Lua/lib/tutorial.xml b/Lua/lib/tutorial.xml new file mode 100644 index 0000000..0b77a35 --- /dev/null +++ b/Lua/lib/tutorial.xml @@ -0,0 +1,5 @@ + + + + Simple node + diff --git a/README.md b/README.md index 2633f9a..72c7101 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,65 @@ pugilua ======= -An almost one-to-one lua binding for [pugixml](http://pugixml.org/). Currently, work in progress ... +An almost one-to-one lua binding for [pugixml](http://pugixml.org/). Usage ----- Use the visual studio project to compile in Visual Studio. The release build will be copied into the Lua/lib folder, where you can start -lua directly and use the library by calling `require 'pugilua'`. Follow the test for API differences from the original C++ API. Pugilua objects reside in the +lua directly and use the library by calling `require 'pugilua'`. Follow the test and the binding definitions in contrib/pugilua/pugilua_lib.cpp for API differences from the original C++ API. Pugilua objects reside in the pugi 'namespace' in Lua. -A usage sketch: +Example of usage: ```` require 'pugilua' + +---- reading ---- local doc=pugi.xml_document() local res=doc:load_file [[..\..\scripts\pugilua\pugilua.vcxproj]] -assert(res.valid) + print(res.description) -local node=doc:child('Project') -assert(node.valid) +local node1=doc:root():child('Project') +local query1=doc:root():select_nodes('Project/PropertyGroup') + +local n=query1.size +for i=0,n-1 do + local node=query1:get(i):node() + local attribute=query1:get(i):attribute() + print(node.valid,node.path) + local a=node:first_attribute() + while a.valid do + print(a.name) + a=a:next_attribute() + end +end + +---- creating ---- +doc:reset() +--- from the tutorial +-- add node with some name +local node = doc:root():append_child("node") + +-- add description node with text child +local descr = node:append_child("description") +descr:append(pugi.node_pcdata):set_value("Simple node") + +-- add param node before the description +local param = node:insert_child_before("param", descr) + +-- add attributes to param node +param:append_attribute("name"):set_value("version") +param:append_attribute("value"):set_value(1.1) +param:insert_attribute_after("type", param:attribute("name")):set_value("float") + +doc:save_file("tutorial.xml") ```` +See an [imperfect example](https://gist.github.com/3832071) of dumping an xml file in a less verbose format, +or a filter of [vcproj](https://gist.github.com/3832285) or [vcxproj](https://gist.github.com/3832290) source files into lua tables + ### API differences * There's no explicit cast to boolean of the pugilua objects, hence the classes `xml_parse_result, xml_node and xml_document` have a boolean `property` valid @@ -35,6 +72,7 @@ Dependencies * [pugixml](https://github.com/zeux/pugixml) the original library * [lua](http://www.lua.org/) the language, Lua 5.1.4 from [luaforwindows](http://code.google.com/p/luaforwindows/), but it should work for every proper lua which is supported by LuaBridge * [LuaBridge](https://github.com/vinniefalco/LuaBridge) for the declarative bindings to Lua + * [premake4](http://industriousone.com/premake) for generating make files License ------- diff --git a/contrib/pugilua/pugilua.cpp b/contrib/pugilua/pugilua.cpp index 30a780c..aeaf21e 100644 --- a/contrib/pugilua/pugilua.cpp +++ b/contrib/pugilua/pugilua.cpp @@ -3,7 +3,13 @@ #include "pugilua_lib.h" -extern "C" __declspec(dllexport) int luaopen_pugilua (lua_State* L) { +#ifdef WIN32 +#define PUGILUA __declspec(dllexport) +#else +#define PUGILUA +#endif + +extern "C" PUGILUA int luaopen_pugilua (lua_State* L) { register_pugilua(L); return 1; -} \ No newline at end of file +} diff --git a/contrib/pugilua/pugilua_lib.cpp b/contrib/pugilua/pugilua_lib.cpp index 6891949..d2d0cf2 100644 --- a/contrib/pugilua/pugilua_lib.cpp +++ b/contrib/pugilua/pugilua_lib.cpp @@ -1,7 +1,7 @@ #include "pugilua_lib.h" #include -#include +#include #include #include #include @@ -79,7 +79,7 @@ namespace pugi { /////////////////////// class lxml_parse_result { public: - lxml_parse_result(pugi::xml_parse_result& r); + lxml_parse_result(pugi::xml_parse_result const& r); lxml_parse_result(); public: @@ -215,7 +215,7 @@ namespace pugi { /////////////////// class lxml_document { public: - RefCountedPtr lxml_document::root() const; + RefCountedPtr root() const; bool valid() const; @@ -247,7 +247,7 @@ namespace pugi { ///////////////////// class lxpath_node_set { public: - lxpath_node_set(pugi::xpath_node_set& s); + lxpath_node_set(pugi::xpath_node_set const& s); lxpath_node_set(); public: @@ -276,7 +276,7 @@ namespace pugi { namespace lua { /////////////////////// - lxml_parse_result::lxml_parse_result(pugi::xml_parse_result& r):res(r) { } + lxml_parse_result::lxml_parse_result(pugi::xml_parse_result const& r):res(r) { } lxml_parse_result::lxml_parse_result() { } std::string lxml_parse_result::description() const { @@ -555,7 +555,7 @@ namespace pugi { ///////////////////// - lxpath_node_set::lxpath_node_set(pugi::xpath_node_set& s):node_set(s) { } + lxpath_node_set::lxpath_node_set(pugi::xpath_node_set const& s):node_set(s) { } lxpath_node_set::lxpath_node_set() { } int lxpath_node_set::type() const { @@ -727,4 +727,4 @@ void register_pugilua (lua_State* L) { .endNamespace() ; -} \ No newline at end of file +} diff --git a/scripts/pugilua/make_vs2008.bat b/scripts/pugilua/make_vs2008.bat new file mode 100644 index 0000000..3de9ad4 --- /dev/null +++ b/scripts/pugilua/make_vs2008.bat @@ -0,0 +1,3 @@ +premake4 clean +premake4 vs2008 +pause \ No newline at end of file diff --git a/scripts/pugilua/make_vs2010.bat b/scripts/pugilua/make_vs2010.bat new file mode 100644 index 0000000..0f2771f --- /dev/null +++ b/scripts/pugilua/make_vs2010.bat @@ -0,0 +1,3 @@ +premake4 clean +premake4 vs2010 +pause \ No newline at end of file diff --git a/scripts/pugilua/premake4 b/scripts/pugilua/premake4 new file mode 100755 index 0000000..60547d6 Binary files /dev/null and b/scripts/pugilua/premake4 differ diff --git a/scripts/pugilua/premake4.exe b/scripts/pugilua/premake4.exe new file mode 100644 index 0000000..877212c Binary files /dev/null and b/scripts/pugilua/premake4.exe differ diff --git a/scripts/pugilua/premake4.lua b/scripts/pugilua/premake4.lua new file mode 100644 index 0000000..e4f65d4 --- /dev/null +++ b/scripts/pugilua/premake4.lua @@ -0,0 +1,88 @@ +local OS=os.get() + +local cmd = { + dir = { linux = "ls", windows = "dir" } +} + +local Commands={} + +for i,v in pairs(cmd) do + Commands[i]=cmd[i][OS] +end + +-- Apply to current "filter" (solution/project) +function DefaultConfig() + location "Build" + configuration "Debug" + defines { "DEBUG", "_DEBUG" } + objdir "Build/obj" + targetdir "Build/Debug" + flags { "Symbols" } + configuration "Release" + defines { "RELEASE" } + objdir "Build/obj" + targetdir "Build/Release" + flags { "Optimize" } + configuration "*" -- to reset configuration filter +end + +function CompilerSpecificConfiguration() + configuration {"xcode*" } + postbuildcommands {"$TARGET_BUILD_DIR/$TARGET_NAME"} + + configuration {"gmake"} + postbuildcommands { "$(TARGET)" } + buildoptions { "-std=gnu++0x" } + + configuration {"codeblocks" } + postbuildcommands { "$(TARGET_OUTPUT_FILE)"} + + configuration { "vs*"} + postbuildcommands { "\"$(TargetPath)\"" } +end + +---------------------------------------------------------------------------------------------------------------- + +newaction { + trigger = "run", + description = "run lua", + execute = function () + os.execute("lua -l pugilua") + end +} + +---------------------------------------------------------------------------------------------------------------- + +-- A solution contains projects, and defines the available configurations +local sln=solution "pugilua" + location "Build" + sln.absbasedir=path.getabsolute(sln.basedir) + configurations { "Debug", "Release" } + platforms { "native" } + libdirs { [[../../lua/lib]], + [[/usr/local/lib]]} + includedirs { + [[../../lua/include]], + [[../../LuaBridge]], + [[../../src]], + [[/usr/local/include]] + } + vpaths { + ["Headers"] = {"**.h","**.hpp"}, + ["Sources"] = {"**.c", "**.cpp"}, + } + +---------------------------------------------------------------------------------------------------------------- + local dll=project "pugilua" + location "Build" + kind "SharedLib" + DefaultConfig() + language "C++" + files { + "../../contrib/pugilua/*.h", + "../../contrib/pugilua/*.cpp", + "../../src/*.hpp", + "../../src/*.cpp" + } + if (OS=='linux') then links { "lua" } + else links { "lua5.1" } end diff --git a/scripts/pugilua/start_lua.bat b/scripts/pugilua/start_lua.bat new file mode 100644 index 0000000..03bb78b --- /dev/null +++ b/scripts/pugilua/start_lua.bat @@ -0,0 +1,2 @@ +cd Build\Release +lua -l pugilua \ No newline at end of file diff --git a/scripts/pugilua/start_lua.sh b/scripts/pugilua/start_lua.sh new file mode 100755 index 0000000..6cf2063 --- /dev/null +++ b/scripts/pugilua/start_lua.sh @@ -0,0 +1,2 @@ +cp Build/Release/libpugilua.so ./pugilua.so +../../Lua/lib/lua -l pugilua