merge from master

This commit is contained in:
d-led 2012-10-04 21:23:08 +02:00
parent 17dd58b78c
commit 56307e917f
16 changed files with 183 additions and 16 deletions

BIN
Lua/lib/liblua.a Normal file

Binary file not shown.

BIN
Lua/lib/lua Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -34,4 +34,24 @@ end
----
node=doc:root():child('Project')
print(node.text)
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"));

5
Lua/lib/tutorial.xml Normal file
View File

@ -0,0 +1,5 @@
<?xml version="1.0"?>
<node>
<param name="version" type="float" value="1.1" />
<description>Simple node</description>
</node>

View File

@ -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
-------

View File

@ -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;
}
}

View File

@ -1,7 +1,7 @@
#include "pugilua_lib.h"
#include <pugixml.hpp>
#include <luabridge.h>
#include <LuaBridge.h>
#include <RefCountedPtr.h>
#include <string>
#include <iostream>
@ -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_node> lxml_document::root() const;
RefCountedPtr<lxml_node> 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()
;
}
}

View File

@ -0,0 +1,3 @@
premake4 clean
premake4 vs2008
pause

View File

@ -0,0 +1,3 @@
premake4 clean
premake4 vs2010
pause

BIN
scripts/pugilua/premake4 Executable file

Binary file not shown.

Binary file not shown.

View File

@ -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

View File

@ -0,0 +1,2 @@
cd Build\Release
lua -l pugilua

2
scripts/pugilua/start_lua.sh Executable file
View File

@ -0,0 +1,2 @@
cp Build/Release/libpugilua.so ./pugilua.so
../../Lua/lib/lua -l pugilua