├── deps
└── LuaBridge-1.0.2
│ ├── .gitignore
│ ├── CHANGES
│ ├── RefCountedPtr.h
│ ├── RefCountedObject.h
│ └── README.md
├── test
├── tutorial.xml
└── test.lua
├── .gitmodules
├── .travis.yml
├── .gitattributes
├── premake4.lua
├── Build
├── linux
│ └── gmake
│ │ ├── Makefile
│ │ └── pugilua.make
├── macosx
│ └── gmake
│ │ ├── Makefile
│ │ └── pugilua.make
└── windows
│ └── vs2013
│ ├── pugilua.vcxproj.filters
│ ├── pugilua.sln
│ └── pugilua.vcxproj
├── LICENSE
├── pugilua
├── pugilua_lib.h
├── pugilua.cpp
└── pugilua_lib.cpp
├── .gitignore
└── README.md
/deps/LuaBridge-1.0.2/.gitignore:
--------------------------------------------------------------------------------
1 | Documentation
2 |
--------------------------------------------------------------------------------
/test/tutorial.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 123
4 |
5 | Simple node
6 |
7 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "pugixml"]
2 | path = deps/pugixml
3 | url = https://github.com/zeux/pugixml.git
4 | [submodule "premake"]
5 | path = premake
6 | url = https://github.com/d-led/premake-meta-cpp.git
7 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: cpp
2 |
3 | sudo: false
4 |
5 | addons:
6 | apt:
7 | packages:
8 | - lua5.1
9 | - liblua5.1-0-dev
10 |
11 | script:
12 | - make -C Build/linux/gmake config=release
13 | - cd test
14 | - lua -e 'package.cpath=[[../bin/linux/gmake/?.so;]]..package.cpath' -l pugilua test.lua
15 |
16 | cache:
17 | - apt
18 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/premake4.lua:
--------------------------------------------------------------------------------
1 | include 'premake'
2 |
3 | make_solution 'pugilua'
4 |
5 | platforms { "native","x32", "x64" }
6 |
7 | lua = assert(dofile 'premake/recipes/lua.lua')
8 |
9 | lua.includedirs.macosx[#lua.includedirs.macosx] = '/usr/local/include/lua'
10 |
11 | OS = os.get()
12 |
13 | make_shared_lib('pugilua', {
14 | "./pugilua/*.h",
15 | "./pugilua/*.cpp",
16 | "./deps/pugixml/src/*.hpp",
17 | "./deps/pugixml/src/*.cpp"
18 | })
19 | includedirs {
20 | './deps/LuaBridge-1.0.2',
21 | './deps/pugixml/src',
22 | lua.includedirs[OS]
23 | }
24 | libdirs { lua.libdirs[OS] }
25 | links( lua.links[OS] )
26 |
27 | targetprefix ""
28 |
--------------------------------------------------------------------------------
/deps/LuaBridge-1.0.2/CHANGES:
--------------------------------------------------------------------------------
1 | Version 1.0.2
2 |
3 | * Option to hide metatables selectable at runtime, default to true.
4 | * addStaticMethod () renamed to addStaticFunction () for consistency.
5 | * addMethod () renamed to addFunction() for consistency.
6 | * addCFunction () registrations.
7 | * Convert null pointers to and from nil.
8 | * Small performance increase in class pointer extraction.
9 |
10 | 2012-05-30 Version 1.0.1
11 |
12 | * Backward compatibility with Lua 5.1.x.
13 |
14 | 2012-05-29 Version 1.0
15 |
16 | * Explicit lifetime management models.
17 | * Generalized containers.
18 | * Single header distribution.
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Build/linux/gmake/Makefile:
--------------------------------------------------------------------------------
1 | # GNU Make solution makefile autogenerated by Premake
2 | # Type "make help" for usage help
3 |
4 | ifndef config
5 | config=debug32
6 | endif
7 | export config
8 |
9 | PROJECTS := pugilua
10 |
11 | .PHONY: all clean help $(PROJECTS)
12 |
13 | all: $(PROJECTS)
14 |
15 | pugilua:
16 | @echo "==== Building pugilua ($(config)) ===="
17 | @${MAKE} --no-print-directory -C . -f pugilua.make
18 |
19 | clean:
20 | @${MAKE} --no-print-directory -C . -f pugilua.make clean
21 |
22 | help:
23 | @echo "Usage: make [config=name] [target]"
24 | @echo ""
25 | @echo "CONFIGURATIONS:"
26 | @echo " debug32"
27 | @echo " release32"
28 | @echo " debug64"
29 | @echo " release64"
30 | @echo " debug"
31 | @echo " release"
32 | @echo ""
33 | @echo "TARGETS:"
34 | @echo " all (default)"
35 | @echo " clean"
36 | @echo " pugilua"
37 | @echo ""
38 | @echo "For more information, see http://industriousone.com/premake/quick-start"
39 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2012-2014 Dmitry Ledentsov
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Build/macosx/gmake/Makefile:
--------------------------------------------------------------------------------
1 | # GNU Make workspace makefile autogenerated by Premake
2 |
3 | .NOTPARALLEL:
4 |
5 | ifndef config
6 | config=debug_native
7 | endif
8 |
9 | ifndef verbose
10 | SILENT = @
11 | endif
12 |
13 | ifeq ($(config),debug_native)
14 | pugilua_config = debug_native
15 | endif
16 | ifeq ($(config),debug_x32)
17 | pugilua_config = debug_x32
18 | endif
19 | ifeq ($(config),debug_x64)
20 | pugilua_config = debug_x64
21 | endif
22 | ifeq ($(config),release_native)
23 | pugilua_config = release_native
24 | endif
25 | ifeq ($(config),release_x32)
26 | pugilua_config = release_x32
27 | endif
28 | ifeq ($(config),release_x64)
29 | pugilua_config = release_x64
30 | endif
31 |
32 | PROJECTS := pugilua
33 |
34 | .PHONY: all clean help $(PROJECTS)
35 |
36 | all: $(PROJECTS)
37 |
38 | pugilua:
39 | ifneq (,$(pugilua_config))
40 | @echo "==== Building pugilua ($(pugilua_config)) ===="
41 | @${MAKE} --no-print-directory -C . -f pugilua.make config=$(pugilua_config)
42 | endif
43 |
44 | clean:
45 | @${MAKE} --no-print-directory -C . -f pugilua.make clean
46 |
47 | help:
48 | @echo "Usage: make [config=name] [target]"
49 | @echo ""
50 | @echo "CONFIGURATIONS:"
51 | @echo " debug_native"
52 | @echo " debug_x32"
53 | @echo " debug_x64"
54 | @echo " release_native"
55 | @echo " release_x32"
56 | @echo " release_x64"
57 | @echo ""
58 | @echo "TARGETS:"
59 | @echo " all (default)"
60 | @echo " clean"
61 | @echo " pugilua"
62 | @echo ""
63 | @echo "For more information, see http://industriousone.com/premake/quick-start"
64 |
--------------------------------------------------------------------------------
/Build/windows/vs2013/pugilua.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {F1A1957C-DDD8-960D-86C5-7C1072DB120F}
6 |
7 |
8 | {E6BACC53-D21D-5CF8-7BA3-94AE67E5277B}
9 |
10 |
11 | {FD7BF78F-E974-16E2-12A7-FB66FEFEF5ED}
12 |
13 |
14 | {FC0DA9C9-68ED-2765-7105-B33BDD638EC6}
15 |
16 |
17 |
18 |
19 | deps\pugixml\src
20 |
21 |
22 | deps\pugixml\src
23 |
24 |
25 | pugilua
26 |
27 |
28 |
29 |
30 | deps\pugixml\src
31 |
32 |
33 | pugilua
34 |
35 |
36 | pugilua
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Build/windows/vs2013/pugilua.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pugilua", "pugilua.vcxproj", "{FC0DA9C9-68ED-2765-7105-B33BDD638EC6}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|native = Debug|native
9 | Debug|Win32 = Debug|Win32
10 | Debug|x64 = Debug|x64
11 | Release|native = Release|native
12 | Release|Win32 = Release|Win32
13 | Release|x64 = Release|x64
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {FC0DA9C9-68ED-2765-7105-B33BDD638EC6}.Debug|native.ActiveCfg = Debug native|Win32
17 | {FC0DA9C9-68ED-2765-7105-B33BDD638EC6}.Debug|native.Build.0 = Debug native|Win32
18 | {FC0DA9C9-68ED-2765-7105-B33BDD638EC6}.Debug|Win32.ActiveCfg = Debug|Win32
19 | {FC0DA9C9-68ED-2765-7105-B33BDD638EC6}.Debug|Win32.Build.0 = Debug|Win32
20 | {FC0DA9C9-68ED-2765-7105-B33BDD638EC6}.Debug|x64.ActiveCfg = Debug|x64
21 | {FC0DA9C9-68ED-2765-7105-B33BDD638EC6}.Debug|x64.Build.0 = Debug|x64
22 | {FC0DA9C9-68ED-2765-7105-B33BDD638EC6}.Release|native.ActiveCfg = Release native|Win32
23 | {FC0DA9C9-68ED-2765-7105-B33BDD638EC6}.Release|native.Build.0 = Release native|Win32
24 | {FC0DA9C9-68ED-2765-7105-B33BDD638EC6}.Release|Win32.ActiveCfg = Release|Win32
25 | {FC0DA9C9-68ED-2765-7105-B33BDD638EC6}.Release|Win32.Build.0 = Release|Win32
26 | {FC0DA9C9-68ED-2765-7105-B33BDD638EC6}.Release|x64.ActiveCfg = Release|x64
27 | {FC0DA9C9-68ED-2765-7105-B33BDD638EC6}.Release|x64.Build.0 = Release|x64
28 | EndGlobalSection
29 | GlobalSection(SolutionProperties) = preSolution
30 | HideSolutionNode = FALSE
31 | EndGlobalSection
32 | EndGlobal
33 |
--------------------------------------------------------------------------------
/pugilua/pugilua_lib.h:
--------------------------------------------------------------------------------
1 | /**
2 | * pugilua - a lua binding for pugixml
3 | * --------------------------------------------------------
4 | * Copyright (C) 2012-2014, by Dmitry Ledentsov (d.ledentsov@gmail.com)
5 | *
6 | * This software is distributed under the MIT License. See notice at the end
7 | * of this file.
8 | *
9 | * This work uses pugixml:
10 | * Copyright (C) 2006-2014, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
11 | */
12 |
13 | #pragma once
14 |
15 | #include
16 |
17 | void register_pugilua (lua_State* L);
18 |
19 | /**
20 | * Copyright (c) 2012-2014 Dmitry Ledentsov
21 | *
22 | * Permission is hereby granted, free of charge, to any person
23 | * obtaining a copy of this software and associated documentation
24 | * files (the "Software"), to deal in the Software without
25 | * restriction, including without limitation the rights to use,
26 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
27 | * copies of the Software, and to permit persons to whom the
28 | * Software is furnished to do so, subject to the following
29 | * conditions:
30 | *
31 | * The above copyright notice and this permission notice shall be
32 | * included in all copies or substantial portions of the Software.
33 | *
34 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
36 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
38 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
39 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
40 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
41 | * OTHER DEALINGS IN THE SOFTWARE.
42 | */
43 |
--------------------------------------------------------------------------------
/pugilua/pugilua.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * pugilua - a lua binding for pugixml
3 | * --------------------------------------------------------
4 | * Copyright (C) 2012-2014, by Dmitry Ledentsov (d.ledentsov@gmail.com)
5 | *
6 | * This software is distributed under the MIT License. See notice at the end
7 | * of this file.
8 | *
9 | * This work uses pugixml:
10 | * Copyright (C) 2006-2014, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
11 | */
12 |
13 | #include
14 | #include
15 |
16 | #include "pugilua_lib.h"
17 |
18 | #ifdef _MSC_VER
19 | #define PUGILUA __declspec(dllexport)
20 | #else
21 | #define PUGILUA
22 | #endif
23 |
24 | extern "C" PUGILUA int luaopen_pugilua (lua_State* L) {
25 | register_pugilua(L);
26 | return 1;
27 | }
28 |
29 | /**
30 | * Copyright (c) 2012-2014 Dmitry Ledentsov
31 | *
32 | * Permission is hereby granted, free of charge, to any person
33 | * obtaining a copy of this software and associated documentation
34 | * files (the "Software"), to deal in the Software without
35 | * restriction, including without limitation the rights to use,
36 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
37 | * copies of the Software, and to permit persons to whom the
38 | * Software is furnished to do so, subject to the following
39 | * conditions:
40 | *
41 | * The above copyright notice and this permission notice shall be
42 | * included in all copies or substantial portions of the Software.
43 | *
44 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
45 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
46 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
47 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
48 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
49 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
50 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
51 | * OTHER DEALINGS IN THE SOFTWARE.
52 | */
53 |
--------------------------------------------------------------------------------
/test/test.lua:
--------------------------------------------------------------------------------
1 | local potential_paths = {
2 | '../bin/windows/vs2013/x32/Release/?.dll',
3 | '../bin/windows/vs2013/x32/Debug/?.dll',
4 | '../bin/windows/vs2013/x64/Release/?.dll',
5 | '../bin/windows/vs2013/x64/Debug/?.dll',
6 | '../bin/windows/vs2013/native/Release/?.dll',
7 | '../bin/windows/vs2013/native/Debug/?.dll',
8 | '../bin/linux/gmake/x32/Release/?.so',
9 | '../bin/linux/gmake/x32/Debug/?.so',
10 | '../bin/linux/gmake/x64/Release/?.so',
11 | '../bin/linux/gmake/?.so',
12 | '../bin/linux/gmake/x64/Debug/?.so',
13 | '../bin/macosx/gmake/x32/Debug/?.dylib',
14 | '../bin/macosx/gmake/x32/Release/?.dylib',
15 | '../bin/macosx/gmake/x64/Debug/?.dylib',
16 | '../bin/macosx/gmake/x64/Release/?.dylib'
17 | }
18 |
19 | local extra_cpath = table.concat(potential_paths, ";");
20 | package.cpath = extra_cpath..';'..package.cpath
21 |
22 | assert(require 'pugilua')
23 |
24 | print(pugi.version)
25 |
26 | local doc=pugi.xml_document()
27 | os.execute("cd")
28 | local res=doc:load_file [[../Build/windows/vs2013/pugilua.vcxproj]]
29 | print(res.description)
30 | assert(res.valid)
31 |
32 | local node=doc:root():child('Project')
33 | assert(node.valid)
34 | print(node.valid)
35 | print(node.name)
36 | local query1=doc:root():select_nodes('Project/PropertyGroup')
37 | local query2=node:select_nodes('PropertyGroup')
38 | assert(query1)
39 | assert(query2)
40 | print(query1.type,pugi.xpath_node_set.type_sorted)
41 | query1:sort(true)
42 | print(query1.type,pugi.xpath_node_set.type_sorted)
43 | print(query1.size,query2.size)
44 | n=query1.size
45 | for i=0,n-1 do
46 | local node=query1:get(i):node()
47 | local attribute=query1:get(i):attribute()
48 | print(node.valid,node.path,attribute.valid)
49 | local a=node:first_attribute()
50 | while a.valid do
51 | print(a.name)
52 | a=a:next_attribute()
53 | end
54 | end
55 |
56 | ----
57 | node=doc:root():child('Project')
58 | --print(node.string)
59 |
60 | ----
61 | doc:reset()
62 | --- from the tutorial
63 | -- add node with some name
64 | local node = doc:root():append_child("node");
65 |
66 | local t=node:append_child("test"):text():set(123)
67 | print(node.string)
68 |
69 | -- add description node with text child
70 | local descr = node:append_child("description");
71 | descr:append(pugi.node_pcdata):set_value("Simple node");
72 |
73 | -- add param node before the description
74 | local param = node:insert_child_before("param", descr);
75 |
76 | -- add attributes to param node
77 | param:append_attribute("name"):set_value("version");
78 | param:append_attribute("value"):set_value(1.1);
79 | param:insert_attribute_after("type", param:attribute("name")):set_value("float");
80 |
81 | print(doc:save_file("tutorial.xml"));
82 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 |
19 | # External tool builders
20 | .externalToolBuilders/
21 |
22 | # Locally stored "Eclipse launch configurations"
23 | *.launch
24 |
25 | # CDT-specific
26 | .cproject
27 |
28 | # PDT-specific
29 | .buildpath
30 |
31 |
32 | #################
33 | ## Visual Studio
34 | #################
35 |
36 | ## Ignore Visual Studio temporary files, build results, and
37 | ## files generated by popular Visual Studio add-ons.
38 |
39 | # User-specific files
40 | *.suo
41 | *.user
42 | *.sln.docstates
43 |
44 | # Build results
45 |
46 | [Dd]ebug/
47 | [Rr]elease/
48 | x64/
49 | [Bb]in/
50 | [Oo]bj/
51 |
52 | # MSTest test Results
53 | [Tt]est[Rr]esult*/
54 | [Bb]uild[Ll]og.*
55 |
56 | *_i.c
57 | *_p.c
58 | *.ilk
59 | *.meta
60 | *.obj
61 | *.pch
62 | *.pdb
63 | *.pgc
64 | *.pgd
65 | *.rsp
66 | *.sbr
67 | *.tlb
68 | *.tli
69 | *.tlh
70 | *.tmp
71 | *.tmp_proj
72 | *.log
73 | *.vspscc
74 | *.vssscc
75 | .builds
76 | *.pidb
77 | *.log
78 | *.scc
79 |
80 | # Visual C++ cache files
81 | ipch/
82 | *.aps
83 | *.ncb
84 | *.opensdf
85 | *.sdf
86 | *.cachefile
87 |
88 | # Visual Studio profiler
89 | *.psess
90 | *.vsp
91 | *.vspx
92 |
93 | # Guidance Automation Toolkit
94 | *.gpState
95 |
96 | # ReSharper is a .NET coding add-in
97 | _ReSharper*/
98 | *.[Rr]e[Ss]harper
99 |
100 | # TeamCity is a build add-in
101 | _TeamCity*
102 |
103 | # DotCover is a Code Coverage Tool
104 | *.dotCover
105 |
106 | # NCrunch
107 | *.ncrunch*
108 | .*crunch*.local.xml
109 |
110 | # Installshield output folder
111 | [Ee]xpress/
112 |
113 | # DocProject is a documentation generator add-in
114 | DocProject/buildhelp/
115 | DocProject/Help/*.HxT
116 | DocProject/Help/*.HxC
117 | DocProject/Help/*.hhc
118 | DocProject/Help/*.hhk
119 | DocProject/Help/*.hhp
120 | DocProject/Help/Html2
121 | DocProject/Help/html
122 |
123 | # Click-Once directory
124 | publish/
125 |
126 | # Publish Web Output
127 | *.Publish.xml
128 | *.pubxml
129 |
130 | # NuGet Packages Directory
131 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
132 | #packages/
133 |
134 | # Windows Azure Build Output
135 | csx
136 | *.build.csdef
137 |
138 | # Windows Store app package directory
139 | AppPackages/
140 |
141 | # Others
142 | sql/
143 | *.Cache
144 | ClientBin/
145 | [Ss]tyle[Cc]op.*
146 | ~$*
147 | *~
148 | *.dbmdl
149 | *.[Pp]ublish.xml
150 | *.pfx
151 | *.publishsettings
152 |
153 | # RIA/Silverlight projects
154 | Generated_Code/
155 |
156 | # Backup & report files from converting an old project file to a newer
157 | # Visual Studio version. Backup files are not needed, because we have git ;-)
158 | _UpgradeReport_Files/
159 | Backup*/
160 | UpgradeLog*.XML
161 | UpgradeLog*.htm
162 |
163 | # SQL Server files
164 | App_Data/*.mdf
165 | App_Data/*.ldf
166 |
167 | #############
168 | ## Windows detritus
169 | #############
170 |
171 | # Windows image file caches
172 | Thumbs.db
173 | ehthumbs.db
174 |
175 | # Folder config file
176 | Desktop.ini
177 |
178 | # Recycle Bin used on file shares
179 | $RECYCLE.BIN/
180 |
181 | # Mac crap
182 | .DS_Store
183 |
184 |
185 | #############
186 | ## Python
187 | #############
188 |
189 | *.py[co]
190 |
191 | # Packages
192 | *.egg
193 | *.egg-info
194 | dist/
195 | eggs/
196 | parts/
197 | var/
198 | sdist/
199 | develop-eggs/
200 | .installed.cfg
201 |
202 | # Installer logs
203 | pip-log.txt
204 |
205 | # Unit test / coverage reports
206 | .coverage
207 | .tox
208 |
209 | #Translations
210 | *.mo
211 |
212 | #Mr Developer
213 | .mr.developer.cfg
214 | *.db
215 | Build/windows/vs2013/pugilua.VC.VC.opendb
216 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | pugilua
2 | =======
3 |
4 | An almost one-to-one lua binding for [pugixml](http://pugixml.org/).
5 |
6 | [](https://travis-ci.org/d-led/pugilua)
7 |
8 | Usage
9 | -----
10 |
11 | ````lua
12 | require 'pugilua'
13 |
14 |
15 | ---- reading ----
16 | local doc=pugi.xml_document()
17 | local res=doc:load_file [[..\..\scripts\pugilua\pugilua.vcxproj]]
18 |
19 | print(res.description)
20 |
21 | local node1=doc:root():child('Project')
22 | local query1=doc:root():select_nodes('Project/PropertyGroup')
23 |
24 | local n=query1.size
25 | for i=0,n-1 do
26 | local node=query1:get(i):node()
27 | local attribute=query1:get(i):attribute()
28 | print(node.valid,node.path)
29 | local a=node:first_attribute()
30 | while a.valid do
31 | print(a.name)
32 | a=a:next_attribute()
33 | end
34 | end
35 |
36 | ---- creating ----
37 | doc:reset()
38 | --- from the tutorial
39 | -- add node with some name
40 | local node = doc:root():append_child("node")
41 |
42 | -- add description node with text child
43 | local descr = node:append_child("description")
44 | descr:append(pugi.node_pcdata):set_value("Simple node")
45 |
46 | -- add param node before the description
47 | local param = node:insert_child_before("param", descr)
48 |
49 | -- add attributes to param node
50 | param:append_attribute("name"):set_value("version")
51 | param:append_attribute("value"):set_value(1.1)
52 | param:insert_attribute_after("type", param:attribute("name")):set_value("float")
53 |
54 | doc:save_file("tutorial.xml")
55 | ````
56 |
57 | See an [imperfect example](https://gist.github.com/3832071) of dumping an xml file in a less verbose format,
58 | or a filter of [vcproj](https://gist.github.com/3832285) or [vcxproj](https://gist.github.com/3832290) source files into lua tables
59 |
60 | ### API differences
61 |
62 | * 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
63 | * lua classes do not have inheritance as pugixml classes do
64 | * Getter methods are mapped to lua properties and not methods
65 |
66 | In-detail API mapping from pugixml to pugilua can be viewed on [google docs](https://docs.google.com/spreadsheet/ccc?key=0AnZVgVA3E-DRdFY5eVp1ZUZHZW9GMzUwY0pfT0VuRVE)
67 |
68 | ### Building
69 |
70 | A premake4 script and a couple of batch files reside in the top directory to generate makefiles into the Build directory. The generated Visual Studio 2013 solution is available in the repository.
71 |
72 | Before generating or using the makefiles, check the include and linker paths, so that you compile with the correct lua headers and link to the correct library.
73 |
74 | The output is always put into Lua/lib at the moment for convenience, but might be changed, so that different versions can coexist.
75 |
76 | Dependencies
77 | ------------
78 |
79 | * [pugixml](https://github.com/zeux/pugixml) the original library
80 | * [lua](http://www.lua.org/)
81 | * [LuaBridge](https://github.com/vinniefalco/LuaBridge) for the declarative bindings to Lua
82 | * [premake4](http://industriousone.com/premake) for generating makefiles
83 |
84 | License
85 | -------
86 |
87 | This library is distributed under the MIT License:
88 |
89 | Copyright (c) 2012-2014 Dmitry Ledentsov
90 |
91 | Permission is hereby granted, free of charge, to any person
92 | obtaining a copy of this software and associated documentation
93 | files (the "Software"), to deal in the Software without
94 | restriction, including without limitation the rights to use,
95 | copy, modify, merge, publish, distribute, sublicense, and/or sell
96 | copies of the Software, and to permit persons to whom the
97 | Software is furnished to do so, subject to the following
98 | conditions:
99 |
100 | The above copyright notice and this permission notice shall be
101 | included in all copies or substantial portions of the Software.
102 |
103 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
104 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
105 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
106 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
107 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
108 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
109 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
110 | OTHER DEALINGS IN THE SOFTWARE.
111 |
--------------------------------------------------------------------------------
/deps/LuaBridge-1.0.2/RefCountedPtr.h:
--------------------------------------------------------------------------------
1 | //==============================================================================
2 | /*
3 | https://github.com/vinniefalco/LuaBridge
4 | https://github.com/vinniefalco/LuaBridgeDemo
5 |
6 | Copyright (C) 2012, Vinnie Falco
7 | Copyright (C) 2007, Nathan Reed
8 |
9 | License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
10 |
11 | Permission is hereby granted, free of charge, to any person obtaining a copy
12 | of this software and associated documentation files (the "Software"), to deal
13 | in the Software without restriction, including without limitation the rights
14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | copies of the Software, and to permit persons to whom the Software is
16 | furnished to do so, subject to the following conditions:
17 |
18 | The above copyright notice and this permission notice shall be included in all
19 | copies or substantial portions of the Software.
20 |
21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 | SOFTWARE.
28 | */
29 | //==============================================================================
30 |
31 | #ifndef LUABRIDGE_REFCOUNTEDPTR_HEADER
32 | #define LUABRIDGE_REFCOUNTEDPTR_HEADER
33 |
34 | #ifdef _MSC_VER
35 | # include
36 | #else
37 | # include
38 | # include
39 | #endif
40 |
41 | //==============================================================================
42 | /**
43 | Support for our RefCountedPtr.
44 | */
45 | struct RefCountedPtrBase
46 | {
47 | // Declaration of container for the refcounts
48 | #ifdef _MSC_VER
49 | typedef stdext::hash_map RefCountsType;
50 | #else
51 | struct ptr_hash
52 | {
53 | size_t operator () (const void * const v) const
54 | {
55 | static __gnu_cxx::hash H;
56 | return H(uintptr_t(v));
57 | }
58 | };
59 | typedef __gnu_cxx::hash_map RefCountsType;
60 | #endif
61 |
62 | protected:
63 | inline RefCountsType& getRefCounts ()
64 | {
65 | static RefCountsType refcounts;
66 | return refcounts ;
67 | }
68 | };
69 |
70 | //==============================================================================
71 | /**
72 | A reference counted smart pointer.
73 |
74 | The api is compatible with boost::RefCountedPtr and std::RefCountedPtr, in the
75 | sense that it implements a strict subset of the functionality.
76 |
77 | This implementation uses a hash table to look up the reference count
78 | associated with a particular pointer.
79 |
80 | @tparam T The class type.
81 |
82 | @todo Decompose RefCountedPtr using a policy. At a minimum, the underlying
83 | reference count should be policy based (to support atomic operations)
84 | and the delete behavior should be policy based (to support custom
85 | disposal methods).
86 |
87 | @todo Provide an intrusive version of RefCountedPtr.
88 | */
89 | template
90 | class RefCountedPtr : private RefCountedPtrBase
91 | {
92 | public:
93 | template
94 | struct rebind
95 | {
96 | typedef RefCountedPtr other;
97 | };
98 |
99 | /** Construct as nullptr or from existing pointer to T.
100 |
101 | @param p The optional, existing pointer to assign from.
102 | */
103 | RefCountedPtr (T* p = 0) : m_p (p)
104 | {
105 | ++getRefCounts () [m_p];
106 | }
107 |
108 | /** Construct from another RefCountedPtr.
109 |
110 | @param rhs The RefCountedPtr to assign from.
111 | */
112 | RefCountedPtr (RefCountedPtr const& rhs) : m_p (rhs.get())
113 | {
114 | ++getRefCounts () [m_p];
115 | }
116 |
117 | /** Construct from a RefCountedPtr of a different type.
118 |
119 | @invariant A pointer to U must be convertible to a pointer to T.
120 |
121 | @param rhs The RefCountedPtr to assign from.
122 | @tparam U The other object type.
123 | */
124 | template
125 | RefCountedPtr (RefCountedPtr const& rhs) : m_p (static_cast (rhs.get()))
126 | {
127 | ++getRefCounts () [m_p];
128 | }
129 |
130 | /** Release the object.
131 |
132 | If there are no more references then the object is deleted.
133 | */
134 | ~RefCountedPtr ()
135 | {
136 | reset();
137 | }
138 |
139 | /** Assign from another RefCountedPtr.
140 |
141 | @param rhs The RefCountedPtr to assign from.
142 | @return A reference to the RefCountedPtr.
143 | */
144 | RefCountedPtr & operator= (RefCountedPtr const& rhs)
145 | {
146 | if (m_p != rhs.m_p)
147 | {
148 | reset ();
149 | m_p = rhs.m_p;
150 | ++getRefCounts () [m_p];
151 | }
152 | return *this;
153 | }
154 |
155 | /** Assign from another RefCountedPtr of a different type.
156 |
157 | @note A pointer to U must be convertible to a pointer to T.
158 |
159 | @tparam U The other object type.
160 | @param rhs The other RefCountedPtr to assign from.
161 | @return A reference to the RefCountedPtr.
162 | */
163 | template
164 | RefCountedPtr & operator= (RefCountedPtr const& rhs)
165 | {
166 | reset ();
167 | m_p = static_cast (rhs.get());
168 | ++getRefCounts () [m_p];
169 | return *this;
170 | }
171 |
172 | /** Retrieve the raw pointer.
173 |
174 | @return A pointer to the object.
175 | */
176 | T* get () const
177 | {
178 | return m_p;
179 | }
180 |
181 | /** Retrieve the raw pointer.
182 |
183 | @return A pointer to the object.
184 | */
185 | T* operator* () const
186 | {
187 | return m_p;
188 | }
189 |
190 | /** Retrieve the raw pointer.
191 |
192 | @return A pointer to the object.
193 | */
194 | T* operator-> () const
195 | {
196 | return m_p;
197 | }
198 |
199 | /** Determine the number of references.
200 |
201 | @note This is not thread-safe.
202 |
203 | @return The number of active references.
204 | */
205 | long use_count () const
206 | {
207 | return getRefCounts () [m_p];
208 | }
209 |
210 | /** Release the pointer.
211 |
212 | The reference count is decremented. If the reference count reaches
213 | zero, the object is deleted.
214 | */
215 | void reset ()
216 | {
217 | if (m_p != 0)
218 | {
219 | if (--getRefCounts () [m_p] <= 0)
220 | delete m_p;
221 |
222 | m_p = 0;
223 | }
224 | }
225 |
226 | private:
227 | T* m_p;
228 | };
229 |
230 | //==============================================================================
231 |
232 | namespace luabridge
233 | {
234 |
235 | template
236 | struct ContainerTraits >
237 | {
238 | typedef T Type;
239 |
240 | static T* get (RefCountedPtr const& c)
241 | {
242 | return c.get ();
243 | }
244 | };
245 |
246 | }
247 |
248 | #endif
249 |
--------------------------------------------------------------------------------
/Build/linux/gmake/pugilua.make:
--------------------------------------------------------------------------------
1 | # GNU Make project makefile autogenerated by Premake
2 | ifndef config
3 | config=debug32
4 | endif
5 |
6 | ifndef verbose
7 | SILENT = @
8 | endif
9 |
10 | CC = gcc
11 | CXX = g++
12 | AR = ar
13 |
14 | ifndef RESCOMP
15 | ifdef WINDRES
16 | RESCOMP = $(WINDRES)
17 | else
18 | RESCOMP = windres
19 | endif
20 | endif
21 |
22 | ifeq ($(config),debug32)
23 | OBJDIR = ../../../obj/linux/gmake/x32/Debug/pugilua/x32
24 | TARGETDIR = ../../../bin/linux/gmake/x32/Debug
25 | TARGET = $(TARGETDIR)/pugilua.so
26 | DEFINES += -D_DEBUG
27 | INCLUDES += -I../../../deps/LuaBridge-1.0.2 -I../../../deps/pugixml/src -I/usr/include/lua5.1
28 | ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
29 | ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -m32 -fPIC
30 | ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
31 | ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
32 | ALL_LDFLAGS += $(LDFLAGS) -L. -shared -m32 -L/usr/lib32
33 | LDDEPS +=
34 | LIBS += $(LDDEPS) -llua5.1
35 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
36 | define PREBUILDCMDS
37 | endef
38 | define PRELINKCMDS
39 | endef
40 | define POSTBUILDCMDS
41 | endef
42 | endif
43 |
44 | ifeq ($(config),release32)
45 | OBJDIR = ../../../obj/linux/gmake/x32/Release/pugilua/x32
46 | TARGETDIR = ../../../bin/linux/gmake/x32/Release
47 | TARGET = $(TARGETDIR)/pugilua.so
48 | DEFINES +=
49 | INCLUDES += -I../../../deps/LuaBridge-1.0.2 -I../../../deps/pugixml/src -I/usr/include/lua5.1
50 | ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
51 | ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -O2 -m32 -fPIC
52 | ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
53 | ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
54 | ALL_LDFLAGS += $(LDFLAGS) -L. -s -shared -m32 -L/usr/lib32
55 | LDDEPS +=
56 | LIBS += $(LDDEPS) -llua5.1
57 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
58 | define PREBUILDCMDS
59 | endef
60 | define PRELINKCMDS
61 | endef
62 | define POSTBUILDCMDS
63 | endef
64 | endif
65 |
66 | ifeq ($(config),debug64)
67 | OBJDIR = ../../../obj/linux/gmake/x64/Debug/pugilua/x64
68 | TARGETDIR = ../../../bin/linux/gmake/x64/Debug
69 | TARGET = $(TARGETDIR)/pugilua.so
70 | DEFINES += -D_DEBUG
71 | INCLUDES += -I../../../deps/LuaBridge-1.0.2 -I../../../deps/pugixml/src -I/usr/include/lua5.1
72 | ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
73 | ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -m64 -fPIC
74 | ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
75 | ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
76 | ALL_LDFLAGS += $(LDFLAGS) -L. -shared -m64 -L/usr/lib64
77 | LDDEPS +=
78 | LIBS += $(LDDEPS) -llua5.1
79 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
80 | define PREBUILDCMDS
81 | endef
82 | define PRELINKCMDS
83 | endef
84 | define POSTBUILDCMDS
85 | endef
86 | endif
87 |
88 | ifeq ($(config),release64)
89 | OBJDIR = ../../../obj/linux/gmake/x64/Release/pugilua/x64
90 | TARGETDIR = ../../../bin/linux/gmake/x64/Release
91 | TARGET = $(TARGETDIR)/pugilua.so
92 | DEFINES +=
93 | INCLUDES += -I../../../deps/LuaBridge-1.0.2 -I../../../deps/pugixml/src -I/usr/include/lua5.1
94 | ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
95 | ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -O2 -m64 -fPIC
96 | ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
97 | ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
98 | ALL_LDFLAGS += $(LDFLAGS) -L. -s -shared -m64 -L/usr/lib64
99 | LDDEPS +=
100 | LIBS += $(LDDEPS) -llua5.1
101 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
102 | define PREBUILDCMDS
103 | endef
104 | define PRELINKCMDS
105 | endef
106 | define POSTBUILDCMDS
107 | endef
108 | endif
109 |
110 | ifeq ($(config),debug)
111 | OBJDIR = ../../../obj/linux/gmake/Native/Debug/pugilua
112 | TARGETDIR = ../../../bin/linux/gmake
113 | TARGET = $(TARGETDIR)/pugilua.so
114 | DEFINES += -D_DEBUG
115 | INCLUDES += -I../../../deps/LuaBridge-1.0.2 -I../../../deps/pugixml/src -I/usr/include/lua5.1
116 | ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
117 | ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -fPIC
118 | ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
119 | ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
120 | ALL_LDFLAGS += $(LDFLAGS) -L. -shared
121 | LDDEPS +=
122 | LIBS += $(LDDEPS) -llua5.1
123 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
124 | define PREBUILDCMDS
125 | endef
126 | define PRELINKCMDS
127 | endef
128 | define POSTBUILDCMDS
129 | endef
130 | endif
131 |
132 | ifeq ($(config),release)
133 | OBJDIR = ../../../obj/linux/gmake/Native/Release/pugilua
134 | TARGETDIR = ../../../bin/linux/gmake
135 | TARGET = $(TARGETDIR)/pugilua.so
136 | DEFINES +=
137 | INCLUDES += -I../../../deps/LuaBridge-1.0.2 -I../../../deps/pugixml/src -I/usr/include/lua5.1
138 | ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
139 | ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -O2 -fPIC
140 | ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
141 | ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
142 | ALL_LDFLAGS += $(LDFLAGS) -L. -s -shared
143 | LDDEPS +=
144 | LIBS += $(LDDEPS) -llua5.1
145 | LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
146 | define PREBUILDCMDS
147 | endef
148 | define PRELINKCMDS
149 | endef
150 | define POSTBUILDCMDS
151 | endef
152 | endif
153 |
154 | OBJECTS := \
155 | $(OBJDIR)/pugilua.o \
156 | $(OBJDIR)/pugilua_lib.o \
157 | $(OBJDIR)/pugixml.o \
158 |
159 | RESOURCES := \
160 |
161 | SHELLTYPE := msdos
162 | ifeq (,$(ComSpec)$(COMSPEC))
163 | SHELLTYPE := posix
164 | endif
165 | ifeq (/bin,$(findstring /bin,$(SHELL)))
166 | SHELLTYPE := posix
167 | endif
168 |
169 | .PHONY: clean prebuild prelink
170 |
171 | all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)
172 | @:
173 |
174 | $(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES)
175 | @echo Linking pugilua
176 | $(SILENT) $(LINKCMD)
177 | $(POSTBUILDCMDS)
178 |
179 | $(TARGETDIR):
180 | @echo Creating $(TARGETDIR)
181 | ifeq (posix,$(SHELLTYPE))
182 | $(SILENT) mkdir -p $(TARGETDIR)
183 | else
184 | $(SILENT) mkdir $(subst /,\\,$(TARGETDIR))
185 | endif
186 |
187 | $(OBJDIR):
188 | @echo Creating $(OBJDIR)
189 | ifeq (posix,$(SHELLTYPE))
190 | $(SILENT) mkdir -p $(OBJDIR)
191 | else
192 | $(SILENT) mkdir $(subst /,\\,$(OBJDIR))
193 | endif
194 |
195 | clean:
196 | @echo Cleaning pugilua
197 | ifeq (posix,$(SHELLTYPE))
198 | $(SILENT) rm -f $(TARGET)
199 | $(SILENT) rm -rf $(OBJDIR)
200 | else
201 | $(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET))
202 | $(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR))
203 | endif
204 |
205 | prebuild:
206 | $(PREBUILDCMDS)
207 |
208 | prelink:
209 | $(PRELINKCMDS)
210 |
211 | ifneq (,$(PCH))
212 | $(GCH): $(PCH)
213 | @echo $(notdir $<)
214 | $(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
215 | endif
216 |
217 | $(OBJDIR)/pugilua.o: ../../../pugilua/pugilua.cpp
218 | @echo $(notdir $<)
219 | $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF $(@:%.o=%.d) -c "$<"
220 |
221 | $(OBJDIR)/pugilua_lib.o: ../../../pugilua/pugilua_lib.cpp
222 | @echo $(notdir $<)
223 | $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF $(@:%.o=%.d) -c "$<"
224 |
225 | $(OBJDIR)/pugixml.o: ../../../deps/pugixml/src/pugixml.cpp
226 | @echo $(notdir $<)
227 | $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF $(@:%.o=%.d) -c "$<"
228 |
229 | -include $(OBJECTS:%.o=%.d)
230 | ifneq (,$(PCH))
231 | -include $(OBJDIR)/$(notdir $(PCH)).d
232 | endif
233 |
--------------------------------------------------------------------------------
/Build/macosx/gmake/pugilua.make:
--------------------------------------------------------------------------------
1 | # GNU Make project makefile autogenerated by Premake
2 |
3 | ifndef config
4 | config=debug_native
5 | endif
6 |
7 | ifndef verbose
8 | SILENT = @
9 | endif
10 |
11 | .PHONY: clean prebuild prelink
12 |
13 | ifeq ($(config),debug_native)
14 | RESCOMP = windres
15 | TARGETDIR = ../../../bin/macosx/gmake/native/Debug
16 | TARGET = $(TARGETDIR)/pugilua.dylib
17 | OBJDIR = ../../../obj/macosx/gmake/native/Debug/pugilua
18 | DEFINES += -D_DEBUG
19 | INCLUDES += -I../../../deps/LuaBridge-1.0.2 -I../../../deps/pugixml/src -I/usr/local/include/lua
20 | FORCE_INCLUDE +=
21 | ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
22 | ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g -fPIC
23 | ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
24 | ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
25 | LIBS += -llua
26 | LDDEPS +=
27 | ALL_LDFLAGS += $(LDFLAGS) -L/usr/local/lib -dynamiclib
28 | LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
29 | define PREBUILDCMDS
30 | endef
31 | define PRELINKCMDS
32 | endef
33 | define POSTBUILDCMDS
34 | endef
35 | all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)
36 | @:
37 |
38 | endif
39 |
40 | ifeq ($(config),debug_x32)
41 | RESCOMP = windres
42 | TARGETDIR = ../../../bin/macosx/gmake/x32/Debug
43 | TARGET = $(TARGETDIR)/pugilua.dylib
44 | OBJDIR = ../../../obj/macosx/gmake/x32/Debug/pugilua
45 | DEFINES += -D_DEBUG
46 | INCLUDES += -I../../../deps/LuaBridge-1.0.2 -I../../../deps/pugixml/src -I/usr/local/include/lua
47 | FORCE_INCLUDE +=
48 | ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
49 | ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m32 -g -fPIC
50 | ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
51 | ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
52 | LIBS += -llua
53 | LDDEPS +=
54 | ALL_LDFLAGS += $(LDFLAGS) -L/usr/lib32 -L/usr/local/lib -m32 -dynamiclib
55 | LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
56 | define PREBUILDCMDS
57 | endef
58 | define PRELINKCMDS
59 | endef
60 | define POSTBUILDCMDS
61 | endef
62 | all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)
63 | @:
64 |
65 | endif
66 |
67 | ifeq ($(config),debug_x64)
68 | RESCOMP = windres
69 | TARGETDIR = ../../../bin/macosx/gmake/x64/Debug
70 | TARGET = $(TARGETDIR)/pugilua.dylib
71 | OBJDIR = ../../../obj/macosx/gmake/x64/Debug/pugilua
72 | DEFINES += -D_DEBUG
73 | INCLUDES += -I../../../deps/LuaBridge-1.0.2 -I../../../deps/pugixml/src -I/usr/local/include/lua
74 | FORCE_INCLUDE +=
75 | ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
76 | ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -g -fPIC
77 | ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
78 | ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
79 | LIBS += -llua
80 | LDDEPS +=
81 | ALL_LDFLAGS += $(LDFLAGS) -L/usr/lib64 -L/usr/local/lib -m64 -dynamiclib
82 | LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
83 | define PREBUILDCMDS
84 | endef
85 | define PRELINKCMDS
86 | endef
87 | define POSTBUILDCMDS
88 | endef
89 | all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)
90 | @:
91 |
92 | endif
93 |
94 | ifeq ($(config),release_native)
95 | RESCOMP = windres
96 | TARGETDIR = ../../../bin/macosx/gmake/native/Release
97 | TARGET = $(TARGETDIR)/pugilua.dylib
98 | OBJDIR = ../../../obj/macosx/gmake/native/Release/pugilua
99 | DEFINES +=
100 | INCLUDES += -I../../../deps/LuaBridge-1.0.2 -I../../../deps/pugixml/src -I/usr/local/include/lua
101 | FORCE_INCLUDE +=
102 | ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
103 | ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2 -fPIC
104 | ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
105 | ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
106 | LIBS += -llua
107 | LDDEPS +=
108 | ALL_LDFLAGS += $(LDFLAGS) -L/usr/local/lib -Wl,-x -dynamiclib
109 | LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
110 | define PREBUILDCMDS
111 | endef
112 | define PRELINKCMDS
113 | endef
114 | define POSTBUILDCMDS
115 | endef
116 | all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)
117 | @:
118 |
119 | endif
120 |
121 | ifeq ($(config),release_x32)
122 | RESCOMP = windres
123 | TARGETDIR = ../../../bin/macosx/gmake/x32/Release
124 | TARGET = $(TARGETDIR)/pugilua.dylib
125 | OBJDIR = ../../../obj/macosx/gmake/x32/Release/pugilua
126 | DEFINES +=
127 | INCLUDES += -I../../../deps/LuaBridge-1.0.2 -I../../../deps/pugixml/src -I/usr/local/include/lua
128 | FORCE_INCLUDE +=
129 | ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
130 | ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m32 -O2 -fPIC
131 | ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
132 | ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
133 | LIBS += -llua
134 | LDDEPS +=
135 | ALL_LDFLAGS += $(LDFLAGS) -L/usr/lib32 -L/usr/local/lib -m32 -Wl,-x -dynamiclib
136 | LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
137 | define PREBUILDCMDS
138 | endef
139 | define PRELINKCMDS
140 | endef
141 | define POSTBUILDCMDS
142 | endef
143 | all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)
144 | @:
145 |
146 | endif
147 |
148 | ifeq ($(config),release_x64)
149 | RESCOMP = windres
150 | TARGETDIR = ../../../bin/macosx/gmake/x64/Release
151 | TARGET = $(TARGETDIR)/pugilua.dylib
152 | OBJDIR = ../../../obj/macosx/gmake/x64/Release/pugilua
153 | DEFINES +=
154 | INCLUDES += -I../../../deps/LuaBridge-1.0.2 -I../../../deps/pugixml/src -I/usr/local/include/lua
155 | FORCE_INCLUDE +=
156 | ALL_CPPFLAGS += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
157 | ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -fPIC
158 | ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CFLAGS)
159 | ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
160 | LIBS += -llua
161 | LDDEPS +=
162 | ALL_LDFLAGS += $(LDFLAGS) -L/usr/lib64 -L/usr/local/lib -m64 -Wl,-x -dynamiclib
163 | LINKCMD = $(CXX) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
164 | define PREBUILDCMDS
165 | endef
166 | define PRELINKCMDS
167 | endef
168 | define POSTBUILDCMDS
169 | endef
170 | all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)
171 | @:
172 |
173 | endif
174 |
175 | OBJECTS := \
176 | $(OBJDIR)/pugixml.o \
177 | $(OBJDIR)/pugilua.o \
178 | $(OBJDIR)/pugilua_lib.o \
179 |
180 | RESOURCES := \
181 |
182 | CUSTOMFILES := \
183 |
184 | SHELLTYPE := msdos
185 | ifeq (,$(ComSpec)$(COMSPEC))
186 | SHELLTYPE := posix
187 | endif
188 | ifeq (/bin,$(findstring /bin,$(SHELL)))
189 | SHELLTYPE := posix
190 | endif
191 |
192 | $(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES) ${CUSTOMFILES}
193 | @echo Linking pugilua
194 | $(SILENT) $(LINKCMD)
195 | $(POSTBUILDCMDS)
196 |
197 | $(TARGETDIR):
198 | @echo Creating $(TARGETDIR)
199 | ifeq (posix,$(SHELLTYPE))
200 | $(SILENT) mkdir -p $(TARGETDIR)
201 | else
202 | $(SILENT) mkdir $(subst /,\\,$(TARGETDIR))
203 | endif
204 |
205 | $(OBJDIR):
206 | @echo Creating $(OBJDIR)
207 | ifeq (posix,$(SHELLTYPE))
208 | $(SILENT) mkdir -p $(OBJDIR)
209 | else
210 | $(SILENT) mkdir $(subst /,\\,$(OBJDIR))
211 | endif
212 |
213 | clean:
214 | @echo Cleaning pugilua
215 | ifeq (posix,$(SHELLTYPE))
216 | $(SILENT) rm -f $(TARGET)
217 | $(SILENT) rm -rf $(OBJDIR)
218 | else
219 | $(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET))
220 | $(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR))
221 | endif
222 |
223 | prebuild:
224 | $(PREBUILDCMDS)
225 |
226 | prelink:
227 | $(PRELINKCMDS)
228 |
229 | ifneq (,$(PCH))
230 | $(OBJECTS): $(GCH) $(PCH)
231 | $(GCH): $(PCH)
232 | @echo $(notdir $<)
233 | $(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
234 | endif
235 |
236 | $(OBJDIR)/pugixml.o: ../../../deps/pugixml/src/pugixml.cpp
237 | @echo $(notdir $<)
238 | $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
239 | $(OBJDIR)/pugilua.o: ../../../pugilua/pugilua.cpp
240 | @echo $(notdir $<)
241 | $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
242 | $(OBJDIR)/pugilua_lib.o: ../../../pugilua/pugilua_lib.cpp
243 | @echo $(notdir $<)
244 | $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
245 |
246 | -include $(OBJECTS:%.o=%.d)
247 | ifneq (,$(PCH))
248 | -include $(OBJDIR)/$(notdir $(PCH)).d
249 | endif
250 |
--------------------------------------------------------------------------------
/deps/LuaBridge-1.0.2/RefCountedObject.h:
--------------------------------------------------------------------------------
1 | //==============================================================================
2 | /*
3 | https://github.com/vinniefalco/LuaBridge
4 | https://github.com/vinniefalco/LuaBridgeDemo
5 |
6 | Copyright (C) 2012, Vinnie Falco
7 | Copyright 2004-11 by Raw Material Software Ltd.
8 |
9 | This is a derivative work used by permission from part of
10 | JUCE, available at http://www.rawaterialsoftware.com
11 |
12 | License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
13 |
14 | Permission is hereby granted, free of charge, to any person obtaining a copy
15 | of this software and associated documentation files (the "Software"), to deal
16 | in the Software without restriction, including without limitation the rights
17 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 | copies of the Software, and to permit persons to whom the Software is
19 | furnished to do so, subject to the following conditions:
20 |
21 | The above copyright notice and this permission notice shall be included in all
22 | copies or substantial portions of the Software.
23 |
24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 | SOFTWARE.
31 |
32 | This file incorporates work covered by the following copyright and
33 | permission notice:
34 |
35 | This file is part of the JUCE library - "Jules' Utility Class Extensions"
36 | Copyright 2004-11 by Raw Material Software Ltd.
37 | */
38 | //==============================================================================
39 |
40 | #ifndef LUABRIDGE_REFCOUNTEDOBJECT_HEADER
41 | #define LUABRIDGE_REFCOUNTEDOBJECT_HEADER
42 |
43 | #if !defined (LUABRIDGE_LUABRIDGE_HEADER)
44 | #error LuaBridge.h must be included before including this file
45 | #endif
46 |
47 | //#define LUABRIDGE_COMPILER_SUPPORTS_MOVE_SEMANTICS 1
48 |
49 | //==============================================================================
50 | /**
51 | Adds reference-counting to an object.
52 |
53 | To add reference-counting to a class, derive it from this class, and
54 | use the RefCountedObjectPtr class to point to it.
55 |
56 | e.g. @code
57 | class MyClass : public RefCountedObjectType
58 | {
59 | void foo();
60 |
61 | // This is a neat way of declaring a typedef for a pointer class,
62 | // rather than typing out the full templated name each time..
63 | typedef RefCountedObjectPtr Ptr;
64 | };
65 |
66 | MyClass::Ptr p = new MyClass();
67 | MyClass::Ptr p2 = p;
68 | p = 0;
69 | p2->foo();
70 | @endcode
71 |
72 | Once a new RefCountedObjectType has been assigned to a pointer, be
73 | careful not to delete the object manually.
74 | */
75 | template
76 | class RefCountedObjectType
77 | {
78 | public:
79 | //==============================================================================
80 | /** Increments the object's reference count.
81 |
82 | This is done automatically by the smart pointer, but is public just
83 | in case it's needed for nefarious purposes.
84 | */
85 | inline void incReferenceCount() const
86 | {
87 | ++refCount;
88 | }
89 |
90 | /** Decreases the object's reference count.
91 |
92 | If the count gets to zero, the object will be deleted.
93 | */
94 | inline void decReferenceCount() const
95 | {
96 | assert (getReferenceCount() > 0);
97 |
98 | if (--refCount == 0)
99 | delete this;
100 | }
101 |
102 | /** Returns the object's current reference count. */
103 | inline int getReferenceCount() const
104 | {
105 | return static_cast (refCount);
106 | }
107 |
108 | protected:
109 | //==============================================================================
110 | /** Creates the reference-counted object (with an initial ref count of zero). */
111 | RefCountedObjectType() : refCount ()
112 | {
113 | }
114 |
115 | /** Destructor. */
116 | virtual ~RefCountedObjectType()
117 | {
118 | // it's dangerous to delete an object that's still referenced by something else!
119 | assert (getReferenceCount() == 0);
120 | }
121 |
122 | private:
123 | //==============================================================================
124 | CounterType mutable refCount;
125 | };
126 |
127 | //==============================================================================
128 | /**
129 | A smart-pointer class which points to a reference-counted object.
130 |
131 | The template parameter specifies the class of the object you want to point to - the easiest
132 | way to make a class reference-countable is to simply make it inherit from RefCountedObjectType,
133 | but if you need to, you could roll your own reference-countable class by implementing a pair of
134 | mathods called incReferenceCount() and decReferenceCount().
135 |
136 | When using this class, you'll probably want to create a typedef to abbreviate the full
137 | templated name - e.g.
138 |
139 | @code typedef RefCountedObjectPtr MyClassPtr;@endcode
140 | */
141 | template
142 | class RefCountedObjectPtr
143 | {
144 | public:
145 | /** The class being referenced by this pointer. */
146 | typedef ReferenceCountedObjectClass ReferencedType;
147 |
148 | //==============================================================================
149 | /** Creates a pointer to a null object. */
150 | inline RefCountedObjectPtr() : referencedObject (0)
151 | {
152 | }
153 |
154 | /** Creates a pointer to an object.
155 |
156 | This will increment the object's reference-count if it is non-null.
157 | */
158 | inline RefCountedObjectPtr (ReferenceCountedObjectClass* const refCountedObject)
159 | : referencedObject (refCountedObject)
160 | {
161 | if (refCountedObject != 0)
162 | refCountedObject->incReferenceCount();
163 | }
164 |
165 | /** Copies another pointer.
166 | This will increment the object's reference-count (if it is non-null).
167 | */
168 | inline RefCountedObjectPtr (const RefCountedObjectPtr& other)
169 | : referencedObject (other.referencedObject)
170 | {
171 | if (referencedObject != 0)
172 | referencedObject->incReferenceCount();
173 | }
174 |
175 | #if LUABRIDGE_COMPILER_SUPPORTS_MOVE_SEMANTICS
176 | /** Takes-over the object from another pointer. */
177 | inline RefCountedObjectPtr (RefCountedObjectPtr&& other)
178 | : referencedObject (other.referencedObject)
179 | {
180 | other.referencedObject = 0;
181 | }
182 | #endif
183 |
184 | /** Copies another pointer.
185 | This will increment the object's reference-count (if it is non-null).
186 | */
187 | template
188 | inline RefCountedObjectPtr (const RefCountedObjectPtr& other)
189 | : referencedObject (static_cast (other.getObject()))
190 | {
191 | if (referencedObject != 0)
192 | referencedObject->incReferenceCount();
193 | }
194 |
195 | /** Changes this pointer to point at a different object.
196 |
197 | The reference count of the old object is decremented, and it might be
198 | deleted if it hits zero. The new object's count is incremented.
199 | */
200 | RefCountedObjectPtr& operator= (const RefCountedObjectPtr& other)
201 | {
202 | return operator= (other.referencedObject);
203 | }
204 |
205 | /** Changes this pointer to point at a different object.
206 |
207 | The reference count of the old object is decremented, and it might be
208 | deleted if it hits zero. The new object's count is incremented.
209 | */
210 | template
211 | RefCountedObjectPtr& operator= (const RefCountedObjectPtr& other)
212 | {
213 | return operator= (static_cast (other.getObject()));
214 | }
215 |
216 | #if LUABRIDGE_COMPILER_SUPPORTS_MOVE_SEMANTICS
217 | /** Takes-over the object from another pointer. */
218 | RefCountedObjectPtr& operator= (RefCountedObjectPtr&& other)
219 | {
220 | std::swap (referencedObject, other.referencedObject);
221 | return *this;
222 | }
223 | #endif
224 |
225 | /** Changes this pointer to point at a different object.
226 |
227 | The reference count of the old object is decremented, and it might be
228 | deleted if it hits zero. The new object's count is incremented.
229 | */
230 | RefCountedObjectPtr& operator= (ReferenceCountedObjectClass* const newObject)
231 | {
232 | if (referencedObject != newObject)
233 | {
234 | if (newObject != 0)
235 | newObject->incReferenceCount();
236 |
237 | ReferenceCountedObjectClass* const oldObject = referencedObject;
238 | referencedObject = newObject;
239 |
240 | if (oldObject != 0)
241 | oldObject->decReferenceCount();
242 | }
243 |
244 | return *this;
245 | }
246 |
247 | /** Destructor.
248 |
249 | This will decrement the object's reference-count, and may delete it if it
250 | gets to zero.
251 | */
252 | inline ~RefCountedObjectPtr()
253 | {
254 | if (referencedObject != 0)
255 | referencedObject->decReferenceCount();
256 | }
257 |
258 | /** Returns the object that this pointer references.
259 | The pointer returned may be zero, of course.
260 | */
261 | inline operator ReferenceCountedObjectClass*() const
262 | {
263 | return referencedObject;
264 | }
265 |
266 | // the -> operator is called on the referenced object
267 | inline ReferenceCountedObjectClass* operator->() const
268 | {
269 | return referencedObject;
270 | }
271 |
272 | /** Returns the object that this pointer references.
273 | The pointer returned may be zero, of course.
274 | */
275 | inline ReferenceCountedObjectClass* getObject() const
276 | {
277 | return referencedObject;
278 | }
279 |
280 | private:
281 | //==============================================================================
282 | ReferenceCountedObjectClass* referencedObject;
283 | };
284 |
285 | /** Compares two ReferenceCountedObjectPointers. */
286 | template
287 | bool operator== (const RefCountedObjectPtr& object1, ReferenceCountedObjectClass* const object2)
288 | {
289 | return object1.getObject() == object2;
290 | }
291 |
292 | /** Compares two ReferenceCountedObjectPointers. */
293 | template
294 | bool operator== (const RefCountedObjectPtr& object1, const RefCountedObjectPtr& object2)
295 | {
296 | return object1.getObject() == object2.getObject();
297 | }
298 |
299 | /** Compares two ReferenceCountedObjectPointers. */
300 | template
301 | bool operator== (ReferenceCountedObjectClass* object1, RefCountedObjectPtr& object2)
302 | {
303 | return object1 == object2.getObject();
304 | }
305 |
306 | /** Compares two ReferenceCountedObjectPointers. */
307 | template
308 | bool operator!= (const RefCountedObjectPtr& object1, const ReferenceCountedObjectClass* object2)
309 | {
310 | return object1.getObject() != object2;
311 | }
312 |
313 | /** Compares two ReferenceCountedObjectPointers. */
314 | template
315 | bool operator!= (const RefCountedObjectPtr& object1, RefCountedObjectPtr& object2)
316 | {
317 | return object1.getObject() != object2.getObject();
318 | }
319 |
320 | /** Compares two ReferenceCountedObjectPointers. */
321 | template
322 | bool operator!= (ReferenceCountedObjectClass* object1, RefCountedObjectPtr& object2)
323 | {
324 | return object1 != object2.getObject();
325 | }
326 |
327 | //==============================================================================
328 |
329 | namespace luabridge
330 | {
331 |
332 | template
333 | struct ContainerTraits >
334 | {
335 | typedef T Type;
336 |
337 | static T* get (RefCountedObjectPtr const& c)
338 | {
339 | return c.getObject ();
340 | }
341 | };
342 |
343 | }
344 |
345 | //==============================================================================
346 |
347 | #endif
348 |
349 |
--------------------------------------------------------------------------------
/Build/windows/vs2013/pugilua.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug native
6 | Win32
7 |
8 |
9 | Debug native
10 | x64
11 |
12 |
13 | Debug
14 | Win32
15 |
16 |
17 | Debug
18 | x64
19 |
20 |
21 | Release native
22 | Win32
23 |
24 |
25 | Release native
26 | x64
27 |
28 |
29 | Release
30 | Win32
31 |
32 |
33 | Release
34 | x64
35 |
36 |
37 |
38 | {FC0DA9C9-68ED-2765-7105-B33BDD638EC6}
39 | true
40 | Win32Proj
41 | pugilua
42 |
43 |
44 |
45 | DynamicLibrary
46 | true
47 | MultiByte
48 | v120
49 |
50 |
51 | DynamicLibrary
52 | true
53 | MultiByte
54 | v120
55 |
56 |
57 | DynamicLibrary
58 | true
59 | MultiByte
60 | v120
61 |
62 |
63 | DynamicLibrary
64 | false
65 | MultiByte
66 | v120
67 |
68 |
69 | DynamicLibrary
70 | false
71 | MultiByte
72 | v120
73 |
74 |
75 | DynamicLibrary
76 | false
77 | MultiByte
78 | v120
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 | true
104 | ..\..\..\bin\windows\vs2013\native\Debug\
105 | ..\..\..\obj\windows\vs2013\native\Debug\pugilua\
106 | pugilua
107 | .dll
108 |
109 |
110 | true
111 | ..\..\..\bin\windows\vs2013\x32\Debug\
112 | ..\..\..\obj\windows\vs2013\x32\Debug\pugilua\
113 | pugilua
114 | .dll
115 |
116 |
117 | true
118 | ..\..\..\bin\windows\vs2013\x64\Debug\
119 | ..\..\..\obj\windows\vs2013\x64\Debug\pugilua\
120 | pugilua
121 | .dll
122 |
123 |
124 | false
125 | ..\..\..\bin\windows\vs2013\native\Release\
126 | ..\..\..\obj\windows\vs2013\native\Release\pugilua\
127 | pugilua
128 | .dll
129 |
130 |
131 | false
132 | ..\..\..\bin\windows\vs2013\x32\Release\
133 | ..\..\..\obj\windows\vs2013\x32\Release\pugilua\
134 | pugilua
135 | .dll
136 |
137 |
138 | false
139 | ..\..\..\bin\windows\vs2013\x64\Release\
140 | ..\..\..\obj\windows\vs2013\x64\Release\pugilua\
141 | pugilua
142 | .dll
143 |
144 |
145 |
146 | NotUsing
147 | Level3
148 | DEBUG;_DEBUG;%(PreprocessorDefinitions)
149 | ..\..\..\deps\LuaBridge-1.0.2;..\..\..\deps\pugixml\src;C:\luarocks\2.1\include;%(AdditionalIncludeDirectories)
150 | EditAndContinue
151 | Disabled
152 |
153 |
154 | DEBUG;_DEBUG;%(PreprocessorDefinitions)
155 | ..\..\..\deps\LuaBridge-1.0.2;..\..\..\deps\pugixml\src;C:\luarocks\2.1\include;%(AdditionalIncludeDirectories)
156 |
157 |
158 | Windows
159 | true
160 | lua5.1.lib;%(AdditionalDependencies)
161 | C:\luarocks\2.1;%(AdditionalLibraryDirectories)
162 | ..\..\..\bin\windows\vs2013\native\Debug\pugilua.lib
163 |
164 |
165 |
166 |
167 | NotUsing
168 | Level3
169 | DEBUG;_DEBUG;%(PreprocessorDefinitions)
170 | ..\..\..\deps\LuaBridge-1.0.2;..\..\..\deps\pugixml\src;C:\luarocks\2.1\include;%(AdditionalIncludeDirectories)
171 | EditAndContinue
172 | Disabled
173 |
174 |
175 | DEBUG;_DEBUG;%(PreprocessorDefinitions)
176 | ..\..\..\deps\LuaBridge-1.0.2;..\..\..\deps\pugixml\src;C:\luarocks\2.1\include;%(AdditionalIncludeDirectories)
177 |
178 |
179 | Windows
180 | true
181 | lua5.1.lib;%(AdditionalDependencies)
182 | C:\luarocks\2.1;%(AdditionalLibraryDirectories)
183 | ..\..\..\bin\windows\vs2013\x32\Debug\pugilua.lib
184 |
185 |
186 |
187 |
188 | NotUsing
189 | Level3
190 | DEBUG;_DEBUG;%(PreprocessorDefinitions)
191 | ..\..\..\deps\LuaBridge-1.0.2;..\..\..\deps\pugixml\src;C:\luarocks\2.1\include;%(AdditionalIncludeDirectories)
192 | ProgramDatabase
193 | Disabled
194 |
195 |
196 | DEBUG;_DEBUG;%(PreprocessorDefinitions)
197 | ..\..\..\deps\LuaBridge-1.0.2;..\..\..\deps\pugixml\src;C:\luarocks\2.1\include;%(AdditionalIncludeDirectories)
198 |
199 |
200 | Windows
201 | true
202 | lua5.1.lib;%(AdditionalDependencies)
203 | C:\luarocks\2.1;%(AdditionalLibraryDirectories)
204 | ..\..\..\bin\windows\vs2013\x64\Debug\pugilua.lib
205 |
206 |
207 |
208 |
209 | NotUsing
210 | Level3
211 | RELEASE;%(PreprocessorDefinitions)
212 | ..\..\..\deps\LuaBridge-1.0.2;..\..\..\deps\pugixml\src;C:\luarocks\2.1\include;%(AdditionalIncludeDirectories)
213 | Full
214 | true
215 | true
216 | false
217 | true
218 |
219 |
220 | RELEASE;%(PreprocessorDefinitions)
221 | ..\..\..\deps\LuaBridge-1.0.2;..\..\..\deps\pugixml\src;C:\luarocks\2.1\include;%(AdditionalIncludeDirectories)
222 |
223 |
224 | Windows
225 | false
226 | true
227 | true
228 | lua5.1.lib;%(AdditionalDependencies)
229 | C:\luarocks\2.1;%(AdditionalLibraryDirectories)
230 | ..\..\..\bin\windows\vs2013\native\Release\pugilua.lib
231 |
232 |
233 |
234 |
235 | NotUsing
236 | Level3
237 | RELEASE;%(PreprocessorDefinitions)
238 | ..\..\..\deps\LuaBridge-1.0.2;..\..\..\deps\pugixml\src;C:\luarocks\2.1\include;%(AdditionalIncludeDirectories)
239 | Full
240 | true
241 | true
242 | false
243 | true
244 |
245 |
246 | RELEASE;%(PreprocessorDefinitions)
247 | ..\..\..\deps\LuaBridge-1.0.2;..\..\..\deps\pugixml\src;C:\luarocks\2.1\include;%(AdditionalIncludeDirectories)
248 |
249 |
250 | Windows
251 | false
252 | true
253 | true
254 | lua5.1.lib;%(AdditionalDependencies)
255 | C:\luarocks\2.1;%(AdditionalLibraryDirectories)
256 | ..\..\..\bin\windows\vs2013\x32\Release\pugilua.lib
257 |
258 |
259 |
260 |
261 | NotUsing
262 | Level3
263 | RELEASE;%(PreprocessorDefinitions)
264 | ..\..\..\deps\LuaBridge-1.0.2;..\..\..\deps\pugixml\src;C:\luarocks\2.1\include;%(AdditionalIncludeDirectories)
265 | Full
266 | true
267 | true
268 | false
269 | true
270 |
271 |
272 | RELEASE;%(PreprocessorDefinitions)
273 | ..\..\..\deps\LuaBridge-1.0.2;..\..\..\deps\pugixml\src;C:\luarocks\2.1\include;%(AdditionalIncludeDirectories)
274 |
275 |
276 | Windows
277 | false
278 | true
279 | true
280 | lua5.1.lib;%(AdditionalDependencies)
281 | C:\luarocks\2.1;%(AdditionalLibraryDirectories)
282 | ..\..\..\bin\windows\vs2013\x64\Release\pugilua.lib
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
--------------------------------------------------------------------------------
/deps/LuaBridge-1.0.2/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | # LuaBridge 1.0.2
6 |
7 | [LuaBridge][3] is a lightweight, dependency-free library for making C++ data,
8 | functions, and classes available to [Lua][5]: A powerful, fast, lightweight,
9 | embeddable scripting language. LuaBridge has been tested and works with Lua
10 | revisions starting from 5.1.5., although it should work in any version of Lua
11 | from 5.1.0 and later.
12 |
13 | LuaBridge offers the following features:
14 |
15 | - Nothing to compile, just include one header file!
16 |
17 | - Simple, light, and nothing else needed (like Boost).
18 |
19 | - Supports different object lifetime management models.
20 |
21 | - Convenient, type-safe access to the Lua stack.
22 |
23 | - Automatic function parameter type binding.
24 |
25 | - Does not require C++11.
26 |
27 | LuaBridge is distributed as a single header file. You simply add
28 | `#include "LuaBridge.h"` where you want to bind your functions, classes, and
29 | variables. There are no additional source files, no compilation settings, and
30 | no Makefiles or IDE-specific project files. LuaBridge is easy to integrate.
31 | A few additional header files provide optional features. Like the main header
32 | file, these are simply used via `#include`. No additional source files need
33 | to be compiled.
34 |
35 | C++ concepts like variables and classes are made available to Lua through a
36 | process called _registration_. Because Lua is weakly typed, the resulting
37 | structure is not rigid. The API is based on C++ template metaprogramming. It
38 | contains template code to automatically generate at compile-time the various
39 | Lua C API calls necessary to export your program's classes and functions to
40 | the Lua environment.
41 |
42 | ### Version
43 |
44 | LuaBridge repository branches are as follows:
45 |
46 | - **[master][7]**: Tagged, stable release versions.
47 |
48 | - **[release][8]**: Tagged candidates for imminent release.
49 |
50 | - **[develop][9]**: Work in progress.
51 |
52 | ## LuaBridge Demo and Tests
53 |
54 | LuaBridge provides both a command line program and a stand-alone graphical
55 | program for compiling and running the test suite. The graphical program brings
56 | up an interactive window where you can enter execute Lua statements in a
57 | persistent environment. This application is cross platform and works on
58 | Windows, Mac OS, iOS, Android, and GNU/Linux systems with X11. The stand-alone
59 | program should work anywhere. Both of these applications include LuaBridge,
60 | Lua version 5.2, and the code necessary to produce a cross platform graphic
61 | application. They are all together in a separate repository, with no
62 | additional dependencies, available on Github at [LuaBridge Demo and Tests][4].
63 | This is what the GUI application looks like, along with the C++ code snippet
64 | for registering the two classes:
65 |
66 |
67 |
68 |
69 |
70 | ## Registration
71 |
72 | There are five types of objects that LuaBridge can register:
73 |
74 | - **Data**: Global variables, data members, and static data members.
75 |
76 | - **Functions**: Global functions, member functions, and static member
77 | functions.
78 |
79 | - **CFunctions**: A regular function, member function, or static member
80 | function that uses the `lua_CFunction` calling convention.
81 |
82 | - **Namespaces**: A namespace is simply a table containing registrations of
83 | functions, data, properties, and other namespaces.
84 |
85 | - **Properties**: Global properties, property members, and static property
86 | members. These appear like data to Lua, but are implemented
87 | using get and set functions on the C++ side.
88 |
89 | Both data and properties can be marked as _read-only_ at the time of
90 | registration. This is different from `const`; the values of these objects can
91 | be modified on the C++ side, but Lua scripts cannot change them. Code samples
92 | that follow are in C++ or Lua, depending on context. For brevity of exposition
93 | code samples in C++ assume the traditional variable `lua_State* L` is defined,
94 | and that a `using namespace luabridge` using-directive is in effect.
95 |
96 | ### Namespaces
97 |
98 | All LuaBridge registrations take place in a _namespace_. When we refer to a
99 | _namespace_ we are always talking about a namespace in the Lua sense, which is
100 | implemented using tables. The namespace need not correspond to a C++ namespace;
101 | in fact no C++ namespaces need to exist at all unless you want them to.
102 | LuaBridge namespaces are visible only to Lua scripts; they are used as a
103 | logical grouping tool. To obtain access to the global namespace we write:
104 |
105 | getGlobalNamespace (L);
106 |
107 | This returns an object on which further registrations can be performed. The
108 | subsequent registrations will go into the global namespace, a practice which
109 | is not recommended. Instead, we can add our own namespace by writing:
110 |
111 | getGlobalNamespace (L)
112 | .beginNamespace ("test");
113 |
114 | This creates a table in `_G` called "test". Since we have not performed any
115 | registrations, this table will be empty except for some bookkeeping key/value
116 | pairs. LuaBridge reserves all identifiers that start with a double underscore.
117 | So `__test` would be an invalid name (although LuaBridge will silently accept
118 | it). Functions like `beginNamespace` return the corresponding object on which
119 | we can make more registrations. Given:
120 |
121 | getGlobalNamespace (L)
122 | .beginNamespace ("test")
123 | .beginNamespace ("detail")
124 | .endNamespace ()
125 | .beginNamespace ("utility")
126 | .endNamespace ()
127 | .endNamespace ();
128 |
129 | The results are accessible to Lua as `test`, `test.detail`, and
130 | `test.utility`. Here we introduce the `endNamespace` function; it returns an
131 | object representing the original enclosing namespace. All LuaBridge functions
132 | which create registrations return an object upon which subsequent
133 | registrations can be made, allowing for an unlimited number of registrations
134 | to be chained together using the dot operator `.`. Adding two objects with the
135 | same name, in the same namespace, results in undefined behavior (although
136 | LuaBridge will silently accept it).
137 |
138 | A namespace can be re-opened later to add more functions. This lets you split
139 | up the registration between different source files. These are equivalent:
140 |
141 | getGlobalNamespace (L)
142 | .beginNamespace ("test")
143 | .addFunction ("foo", foo)
144 | .endNamespace ();
145 |
146 | getGlobalNamespace (L)
147 | .beginNamespace ("test")
148 | .addFunction ("bar", bar)
149 | .endNamespace ();
150 |
151 | and
152 |
153 | getGlobalNamespace (L)
154 | .beginNamespace ("test")
155 | .addFunction ("foo", foo)
156 | .addFunction ("bar", bar)
157 | .endNamespace ();
158 |
159 |
160 | ### Data, Properties, Functions, and CFunctions.
161 |
162 | These are registered into a namespace using `addVariable`, `addProperty`,
163 | `addFunction`, and `addCFunction`. When registered functions are called by
164 | scripts, LuaBridge automatically takes care of the conversion of arguments
165 | into the appropriate data type when doing so is possible. This automated
166 | system works for the function's return value, and up to 8 parameters although
167 | more can be added by extending the templates. Pointers, references, and
168 | objects of class type as parameters are treated specially, and explained
169 | later. If we have:
170 |
171 | int globalVar;
172 | static float staticVar;
173 |
174 | std::string stringProperty;
175 | std::string getString () { return stringProperty; }
176 | void setString (std::string s) { return s; }
177 |
178 | int foo () { return 42; }
179 | void bar (char const*) { }
180 | int cFunc (lua_State* L) { return 0; }
181 |
182 | These are registered with:
183 |
184 | getGlobalNamespace (L)
185 | .beginNamespace ("test")
186 | .addVariable ("var1", &globalVar)
187 | .addVariable ("var2", &staticVar, false) // read-only
188 | .addProperty ("prop1", getString, setString)
189 | .addProperty ("prop2", getString) // read only
190 | .addFunction ("foo", foo)
191 | .addFunction ("bar", bar)
192 | .addCFunction ("cfunc", cFunc)
193 | .endNamespace ();
194 |
195 | Variables can be marked _read-only_ by passing `false` in the second optional
196 | parameter. If the parameter is omitted, `true` is used making the variable
197 | read/write. Properties are marked read-only by omitting the set function.
198 | After the registrations above, the following Lua identifiers are valid:
199 |
200 | test -- a namespace
201 | test.var1 -- a lua_Number variable
202 | test.var2 -- a read-only lua_Number variable
203 | test.prop1 -- a lua_String property
204 | test.prop2 -- a read-only lua_String property
205 | test.foo -- a function returning a lua_Number
206 | test.bar -- a function taking a lua_String as a parameter
207 | test.cfunc -- a function with a variable argument list and multi-return
208 |
209 | Note that `test.prop1` and `test.prop2` both refer to the same value. However,
210 | since `test.prop2` is read-only, assignment does not work. These Lua
211 | statements have the stated effects:
212 |
213 | test.var1 = 5 -- okay
214 | test.var2 = 6 -- error: var2 is not writable
215 | test.prop1 = "Hello" -- okay
216 | test.prop1 = 68 -- okay, Lua converts the number to a string.
217 | test.prop2 = "bar" -- error: prop2 is not writable
218 |
219 | test.foo () -- calls foo and discards the return value
220 | test.var1 = foo () -- calls foo and stores the result in var1
221 | test.bar ("Employee") -- calls bar with a string
222 | test.bar (test) -- error: bar expects a string not a table
223 |
224 | LuaBridge does not support overloaded functions nor is it likely to in the
225 | future. Since Lua is dynamically typed, any system that tries to resolve a set
226 | of parameters passed from a script will face considerable ambiguity when
227 | trying to choose an appropriately matching C++ function signature.
228 |
229 | ### Classes
230 |
231 | A class registration is opened using either `beginClass` or `deriveClass` and
232 | ended using `endClass`. Once registered, a class can later be re-opened for
233 | more registrations using `beginClass`. However, `deriveClass` should only be
234 | used once. To add more registrations to an already registered derived class,
235 | use `beginClass`. These declarations:
236 |
237 | struct A {
238 | static int staticData;
239 | static float staticProperty;
240 |
241 | static float getStaticProperty () { return staticProperty; }
242 | static void setStaticProperty (float f) { staticProperty = f; }
243 | static void staticFunc () { }
244 |
245 | static int staticCFunc () { return 0; }
246 |
247 | std::string dataMember;
248 |
249 | char dataProperty;
250 | char getProperty () const { return dataProperty; }
251 | void setProperty (char v) { dataProperty = v; }
252 |
253 | void func1 () { }
254 | virtual void virtualFunc () { }
255 |
256 | int cfunc (lua_State* L) { return 0; }
257 | };
258 |
259 | struct B : public A {
260 | double dataMember2;
261 |
262 | void func1 () { }
263 | void func2 () { }
264 | void virtualFunc () { }
265 | };
266 |
267 | int A::staticData;
268 | float A::staticProperty;
269 |
270 | Are registered using:
271 |
272 | getGlobalNamespace (L)
273 | .beginNamespace ("test")
274 | .beginClass ("A")
275 | .addStaticData ("staticData", &A::staticData)
276 | .addStaticProperty ("staticProperty", &A::staticProperty)
277 | .addStaticFunction ("staticFunc", &A::staticFunc)
278 | .addStaticCFunction ("staticCFunc", &A::staticCFunc)
279 | .addData ("data", &A::dataMember)
280 | .addProperty ("prop", &A::getProperty, &A::setProperty)
281 | .addFunction ("func1", &A::func1)
282 | .addFunction ("virtualFunc", &A::virtualFunc)
283 | .addCFunction ("cfunc", &A::cfunc)
284 | .endClass ()
285 | .deriveClass ("B")
286 | .addData ("data", &B::dataMember2)
287 | .addFunction ("func1", &B::func1)
288 | .addFunction ("func2", &B::func2)
289 | .endClass ()
290 | .endClass ();
291 |
292 | Method registration works just like function registration. Virtual methods
293 | work normally; no special syntax is needed. const methods are detected and
294 | const-correctness is enforced, so if a function returns a const object (or
295 | a container holding to a const object) to Lua, that reference to the object
296 | will be considered const and only const methods can be called on it.
297 | Destructors are registered automatically for each class.
298 |
299 | As with regular variables and properties, class data and properties can be
300 | marked read-only by passing false in the second parameter, or omitting the set
301 | set function respectively. The `deriveClass` takes two template arguments: the
302 | class to be registered, and its base class. Inherited methods do not have to
303 | be re-declared and will function normally in Lua. If a class has a base class
304 | that is **not** registered with Lua, there is no need to declare it as a
305 | subclass.
306 |
307 | ### Property Member Proxies
308 |
309 | Sometimes when registering a class which comes from a third party library, the
310 | data is not exposed in a way that can be expressed as a pointer to member,
311 | there are no get or set functions, or the get and set functons do not have the
312 | right function signature. Since the class declaration is closed for changes,
313 | LuaBridge provides allows a _property member proxy_. This is a pair of get
314 | and set flat functions which take as their first parameter a pointer to
315 | the object. This is easily understood with the following example:
316 |
317 | // Third party declaration, can't be changed
318 | struct Vec
319 | {
320 | float coord [3];
321 | };
322 |
323 | Taking the address of an array element, e.g. `&Vec::coord [0]` results in an
324 | error instead of a pointer-to-member. The class is closed for modifications,
325 | but we want to export Vec objects to Lua using the familiar object notation.
326 | To do this, first we add a "helper" class:
327 |
328 | struct VecHelper
329 | {
330 | template
331 | static float get (Vec const* vec)
332 | {
333 | return vec->coord [index];
334 | }
335 |
336 | template
337 | static void set (Vec* vec, float value)
338 | {
339 | vec->coord [index] = value;
340 | }
341 | };
342 |
343 | This helper class is only used to provide property member proxies. `Vec`
344 | continues to be used in the C++ code as it was before. Now we can register
345 | the `Vec` class with property member proxies for `x`, `y`, and `z`:
346 |
347 | getGlobalNamespace (L)
348 | .beginNamespace ("test")
349 | .beginClass ("Vec")
350 | .addProperty ("x", &VecHelper::get <0>, &VecHelper::set <0>)
351 | .addProperty ("y", &VecHelper::get <1>, &VecHelper::set <1>)
352 | .addProperty ("z", &VecHelper::get <2>, &VecHelper::set <2>)
353 | .endClass ()
354 | .endNamespace ();
355 |
356 | ### Constructors
357 |
358 | A single constructor may be added for a class using `addConstructor`.
359 | LuaBridge cannot automatically determine the number and types of constructor
360 | parameters like it can for functions and methods, so you must provide them.
361 | This is done by specifying the signature of the desired constructor function
362 | as the first template parameter to `addConstructor`. The parameter types will
363 | be extracted from this (the return type is ignored). For example, these
364 | statements register constructors for the given classes:
365 |
366 | struct A {
367 | A ();
368 | };
369 |
370 | struct B {
371 | explicit B (char const* s, int nChars);
372 | };
373 |
374 | getGlobalNamespace (L)
375 | .beginNamespace ("test")
376 | .beginClass ("A")
377 | .addConstructor ()
378 | .endClass ()
379 | .beginClass ("B")
380 | .addConstructor ()
381 | .endClass ();
382 | .endNamespace ()
383 |
384 | Constructors added in this fashion are called from Lua using the fully
385 | qualified name of the class. This Lua code will create instances of `A` and
386 | `B`
387 |
388 | a = test.A () -- Create a new A.
389 | b = test.B ("hello", 5) -- Create a new B.
390 | b = test.B () -- Error: expected string in argument 1
391 |
392 | ## The Lua Stack
393 |
394 | In the Lua C API, all operations on the `lua_State` are performed through the
395 | Lua stack. In order to pass parameters back and forth between C++ and Lua,
396 | LuaBridge uses specializations of this template class concept:
397 |
398 | template
399 | struct Stack
400 | {
401 | static void push (lua_State* L, T t);
402 | static T get (lua_State* L, int index);
403 | };
404 |
405 | The Stack template class specializations are used automatically for variables,
406 | properties, data members, property members, function arguments and return
407 | values. These basic types are supported:
408 |
409 | - `bool`
410 | - `char`, converted to a string of length one.
411 | - `char const*` and `std::string` strings.
412 | - Integers, `float`, and `double`, converted to `Lua_number`.
413 |
414 | User-defined types which are convertible to one of the basic types are
415 | possible, simply provide a `Stack <>` specialization in the `luabridge`
416 | namespace for your user-defined type, modeled after the existing types.
417 | For example, here is a specialization for a [juce::String][6]:
418 |
419 | template <>
420 | struct Stack
421 | {
422 | static void push (lua_State* L, juce::String s)
423 | {
424 | lua_pushstring (L, s.toUTF8 ());
425 | }
426 |
427 | static juce::String get (lua_State* L, int index)
428 | {
429 | return juce::String (luaL_checkstring (L, index));
430 | }
431 | };
432 |
433 | ### The `lua_State*`
434 |
435 | Sometimes it is convenient from within a bound function or member function
436 | to gain access to the `lua_State*` normally available to a `lua_CFunction`.
437 | With LuaBridge, all you need to do is add a `lua_State*` as the last
438 | parameter of your bound function:
439 |
440 | void useState (lua_State* L);
441 |
442 | getGlobalNamespace (L).addFunction ("useState", &useState);
443 |
444 | You can still include regular arguments while receiving the state:
445 |
446 | void useStateAndArgs (int i, std::string s, lua_State* L);
447 |
448 | getGlobalNamespace (L).addFunction ("useStateAndArgs", &useStateAndArgs);
449 |
450 | When a script calls `useStateAndArgs`, it passes only the integer and string
451 | parameters. LuaBridge takes care of inserting the `lua_State*` into the
452 | argument list for the corresponding C++ function. This will work correctly
453 | even for the state created by coroutines. Undefined behavior results if
454 | the `lua_State*` is not the last parameter.
455 |
456 | ### Class Object Types
457 |
458 | An object of a registered class `T` may be passed to Lua as:
459 |
460 | - `T*` or `T&`: Passed by reference, with _C++ lifetime_.
461 | - `T const*` or `T const&`: Passed by const reference, with _C++ lifetime_.
462 | - `T` or `T const`: Passed by value (a copy), with _Lua lifetime_.
463 |
464 | ### C++ Lifetime
465 |
466 | The creation and deletion of objects with _C++ lifetime_ is controlled by
467 | the C++ code. Lua does nothing when it garbage collects a reference to such an
468 | object. Specifically, the object's destructor is not called (since C++ owns
469 | it). Care must be taken to ensure that objects with C++ lifetime are not
470 | deleted while still being referenced by a `lua_State*`, or else undefined
471 | behavior results. In the previous examples, an instance of `A` can be passed
472 | to Lua with C++ lifetime, like this:
473 |
474 | A a;
475 |
476 | push (L, &a); // pointer to 'a', C++ lifetime
477 | lua_setglobal (L, "a");
478 |
479 | push (L, (A const*)&a); // pointer to 'a const', C++ lifetime
480 | lua_setglobal (L, "ac");
481 |
482 | push (L, &a); // equivalent to push (L, (A const*)&a)
483 | lua_setglobal (L, "ac2");
484 |
485 | push (L, new A); // compiles, but will leak memory
486 | lua_setglobal (L, "ap");
487 |
488 | ### Lua Lifetime
489 |
490 | When an object of a registered class is passed by value to Lua, it will have
491 | _Lua lifetime_. A copy of the passed object is constructed inside the
492 | userdata. When Lua has no more references to the object, it becomes eligible
493 | for garbage collection. When the userdata is collected, the destructor for
494 | the class will be called on the object. Care must be taken to ensure that
495 | objects with Lua lifetime are not accessed by C++ after they are garbage
496 | collected, or else undefined behavior results. An instance of `B` can be
497 | passed to Lua with Lua lifetime this way:
498 |
499 | B b;
500 |
501 | push (L, b); // Copy of b passed, Lua lifetime.
502 | lua_setglobal (L, "b");
503 |
504 | Given the previous code segments, these Lua statements are applicable:
505 |
506 | print (test.A.staticData) -- Prints the static data member.
507 | print (test.A.staticProperty) -- Prints the static property member.
508 | test.A.staticFunc () -- Calls the static method.
509 |
510 | print (a.data) -- Prints the data member.
511 | print (a.prop) -- Prints the property member.
512 | a:func1 () -- Calls A::func1 ().
513 | test.A.func1 (a) -- Equivalent to a:func1 ().
514 | test.A.func1 ("hello") -- Error: "hello" is not a class A.
515 | a:virtualFunc () -- Calls A::virtualFunc ().
516 |
517 | print (b.data) -- Prints B::dataMember.
518 | print (b.prop) -- Prints inherited property member.
519 | b:func1 () -- Calls B::func1 ().
520 | b:func2 () -- Calls B::func2 ().
521 | test.B.func2 (a) -- Error: a is not a class B.
522 | test.A.func1 (b) -- Calls A::func1 ().
523 | b:virtualFunc () -- Calls B::virtualFunc ().
524 | test.B.virtualFunc (b) -- Calls B::virtualFunc ().
525 | test.A.virtualFunc (b) -- Calls B::virtualFunc ().
526 | test.B.virtualFunc (a) -- Error: a is not a class B.
527 |
528 | a = nil; collectgarbage () -- 'a' still exists in C++.
529 | b = nil; collectgarbage () -- Lua calls ~B() on the copy of b.
530 |
531 | When Lua script creates an object of class type using a registered
532 | constructor, the resulting value will have Lua lifetime. After Lua no longer
533 | references the object, it becomes eligible for garbage collection. You can
534 | still pass these to C++, either by reference or by value. If passed by
535 | reference, the usual warnings apply about accessing the reference later,
536 | after it has been garbage collected.
537 |
538 | ### Pointers, References, and Pass by Value
539 |
540 | When C++ objects are passed from Lua back to C++ as arguments to functions,
541 | or set as data members, LuaBridge does its best to automate the conversion.
542 | Using the previous definitions, the following functions may be registered
543 | to Lua:
544 |
545 | void func0 (A a);
546 | void func1 (A* a);
547 | void func2 (A const* a);
548 | void func3 (A& a);
549 | void func4 (A const& a);
550 |
551 | Executing this Lua code will have the prescribed effect:
552 |
553 | func0 (a) -- Passes a copy of a, using A's copy constructor.
554 | func1 (a) -- Passes a pointer to a.
555 | func2 (a) -- Passes a pointer to a const a.
556 | func3 (a) -- Passes a reference to a.
557 | func4 (a) -- Passes a reference to a const a.
558 |
559 | In the example above, all functions can read the data members and property
560 | members of `a`, or call const member functions of `a`. Only `func0`, `func1`
561 | and `func3` can modify the data members and data properties, or call
562 | non-const member functions of `a`.
563 |
564 | The usual C++ inheritance and pointer assignment rules apply. Given:
565 |
566 | void func5 (B b);
567 | void func6 (B* b);
568 |
569 | These Lua statements hold:
570 |
571 | func5 (b) - Passes a copy of b, using B's copy constructor.
572 | func6 (b) - Passes a pointer to b.
573 | func6 (a) - Error: Pointer to B expected.
574 | func1 (b) - Okay, b is a subclass of a.
575 |
576 | When a pointer or pointer to const is passed to Lua and the pointer is null
577 | (zero), LuaBridge will pass Lua a `nil` instead. When Lua passes a `nil`
578 | to C++ where a pointer is expected, a null (zero) is passed instead.
579 | Attempting to pass a null pointer to a C++ function expecting a reference
580 | results in `lua_error` being called.
581 |
582 | ## Shared Lifetime
583 |
584 | LuaBridge supports a "shared lifetime" model: dynamically allocated and
585 | reference counted objects whose ownership is shared by both Lua and C++.
586 | The object remains in existence until there are no remaining C++ or Lua
587 | references, and Lua performs its usual garbage collection cycle. A container
588 | is recognized by a specialization of the `ContainerTraits` template class.
589 | LuaBridge will automatically recognize when a data type is a container when
590 | the correspoding specialization is present. Two styles of containers come with
591 | LuaBridge, including the necessary specializations:
592 |
593 | ### The `RefCountedObjectPtr` Container
594 |
595 | This is an intrusive style container. Your existing class declaration must be
596 | changed to be also derived from `RefCountedObject`. Given `class T`, derived
597 | from `RefCountedObject`, the container `RefCountedObjectPtr ` may be used.
598 | In order for reference counts to be maintained properly, all C++ code must
599 | store a container instead of the pointer. This is similar in style to
600 | `std::shared_ptr` although there are slight differences. For example:
601 |
602 | // A is reference counted.
603 | struct A : public RefCountedObject
604 | {
605 | void foo () { }
606 | };
607 |
608 | struct B
609 | {
610 | RefCountedObjectPtr a; // holds a reference to A
611 | };
612 |
613 | void bar (RefCountedObjectPtr a)
614 | {
615 | a->foo ();
616 | }
617 |
618 | ### The `RefCountedPtr` Container
619 |
620 | This is a non intrusive reference counted pointer. The reference counts are
621 | kept in a global hash table, which does incur a small performance penalty.
622 | However, it does not require changing any already existing class declarations.
623 | This is especially useful when the classes to be registered come from a third
624 | party library and cannot be modified. To use it, simply wrap all pointers
625 | to class objects with the container instead:
626 |
627 | struct A
628 | {
629 | void foo () { }
630 | };
631 |
632 | struct B
633 | {
634 | RefCountedPtr a;
635 | };
636 |
637 | RefCountedPtr createA ()
638 | {
639 | return new A;
640 | }
641 |
642 | void bar (RefCountedPtr a)
643 | {
644 | a->foo ();
645 | }
646 |
647 | void callFoo ()
648 | {
649 | bar (createA ());
650 |
651 | // The created A will be destroyed
652 | // when we leave this scope
653 | }
654 |
655 | ### Custom Containers
656 |
657 | If you have your own container, you must provide a specialization of
658 | `ContainerTraits` in the `luabridge` namespace for your type before it will be
659 | recognized by LuaBridge (or else the code will not compile):
660 |
661 | template
662 | struct ContainerTraits >
663 | {
664 | typedef typename T Type;
665 |
666 | static T* get (CustomContainer const& c)
667 | {
668 | return c.getPointerToObject ();
669 | }
670 | };
671 |
672 | Standard containers like `std::shared_ptr` or `boost::shared_ptr` **will not
673 | work**. This is because of type erasure; when the object goes from C++ to
674 | Lua and back to C++, there is no way to associate the object with the
675 | original container. The new container is constructed from a pointer to the
676 | object instead of an existing container. The result is undefined behavior
677 | since there are now two sets of reference counts.
678 |
679 | ### Container Construction
680 |
681 | When a constructor is registered for a class, there is an additional
682 | optional second template parameter describing the type of container to use.
683 | If this parameter is specified, calls to the constructor will create the
684 | object dynamically, via operator new, and place it a container of that
685 | type. The container must have been previously specialized in
686 | `ContainerTraits`, or else a compile error will result. This code will
687 | register two objects, each using a constructor that creates an object
688 | with Lua lifetime using the specified container:
689 |
690 | class C : public RefCountedObject
691 | {
692 | C () { }
693 | };
694 |
695 | class D
696 | {
697 | D () { }
698 | };
699 |
700 | getGlobalNamespace (L)
701 | .beginNamespace ("test")
702 | .beginClass ("C")
703 | .addConstructor > ()
704 | .endClass ()
705 | .beginClass ("D")
706 | .addConstructor > ()
707 | .endClass ();
708 | .endNamespace ()
709 |
710 | ### Mixing Lifetimes
711 |
712 | Mixing object lifetime models is entirely possible, subject to the usual
713 | caveats of holding references to objects which could get deleted. For
714 | example, C++ can be called from Lua with a pointer to an object of class
715 | type; the function can modify the object or call non-const data members.
716 | These modifications are visible to Lua (since they both refer to the same
717 | object). An object store in a container can be passed to a function expecting
718 | a pointer. These conversion work seamlessly.
719 |
720 | ## Security
721 |
722 | The metatables and userdata that LuaBridge creates in the `lua_State*` are
723 | protected using a security system, to eliminate the possibility of undefined
724 | behavior resulting from scripted manipulation of the environment. The
725 | security system has these components:
726 |
727 | - Class and const class tables use the 'table proxy' technique. The
728 | corresponding metatables have `__index` and `__newindex` metamethods,
729 | so these class tables are immutable from Lua.
730 |
731 | - Metatables have `__metatable` set to a boolean value. Scripts cannot
732 | obtain the metatable from a LuaBridge object.
733 |
734 | - Classes are mapped to metatables through the registry, which Lua scripts
735 | cannot access. The global environment does not expose metatables
736 |
737 | - Metatables created by LuaBridge are tagged with a lightuserdata key which
738 | is unique in the process. Other libraries cannot forge a LuaBridge
739 | metatable.
740 |
741 | This security system can be easily bypassed if scripts are given access to
742 | the debug library (or functionality similar to it, i.e. a raw `getmetatable`).
743 | The security system can also be defeated by C code in the host, either by
744 | revealing the unique lightuserdata key to another module or by putting a
745 | LuaBridge metatable in a place that can be accessed by scripts.
746 |
747 | When a class member function is called, or class property member accessed,
748 | the `this` pointer is type-checked. This is because member functions exposed
749 | to Lua are just plain functions that usually get called with the Lua colon
750 | notation, which passes the object in question as the first parameter. Lua's
751 | dynamic typing makes this type-checking mandatory to prevent undefined
752 | behavior resulting from improper use.
753 |
754 | If a type check error occurs, LuaBridge uses the `lua_error` mechanism to
755 | trigger a failure. A host program can always recover from an error through
756 | the use of `lua_pcall`; proper usage of LuaBridge will never result in
757 | undefined behavior.
758 |
759 | ## Limitations
760 |
761 | LuaBridge does not support:
762 |
763 | - Enumerated constants
764 | - More than 8 parameters on a function or method (although this can be
765 | increased by adding more `TypeListValues` specializations).
766 | - Overloaded functions, methods, or constructors.
767 | - Global variables (variables must be wrapped in a named scope).
768 | - Automatic conversion between STL container types and Lua tables.
769 | - Inheriting Lua classes from C++ classes.
770 | - Passing nil to a C++ function that expects a pointer or reference.
771 | - Standard containers like `std::shared_ptr`.
772 |
773 | ## Development
774 |
775 | [Github][3] is the new official home for LuaBridge. The old SVN repository is
776 | deprecated since it is no longer used, or maintained. The original author has
777 | graciously passed the reins to Vinnie Falco for maintaining and improving the
778 | project. To obtain the older official releases, checkout the tags from 0.2.1
779 | and earlier.
780 |
781 | If you are an existing LuaBridge user, a new LuaBridge user, or a potential
782 | LuaBridge user, we welcome your input, feedback, and contributions. Feel
783 | free to open Issues, or fork the repository. All questions, comments,
784 | suggestions, and/or proposed changes will be handled by the new maintainer.
785 |
786 | ## License
787 |
788 | Copyright (C) 2012, [Vinnie Falco][1] ([e-mail][0])
789 | Copyright (C) 2007, Nathan Reed
790 |
791 | Portions from The Loki Library:
792 | Copyright (C) 2001 by Andrei Alexandrescu
793 |
794 | License: The [MIT License][2]
795 |
796 | Older versions of LuaBridge up to and including 0.2 are distributed under the
797 | BSD 3-Clause License. See the corresponding license file in those versions
798 | for more details.
799 |
800 | [0]: mailto:vinnie.falco@gmail.com "Vinnie Falco (Email)"
801 | [1]: http://www.vinniefalco.com "Vinnie Falco"
802 | [2]: http://www.opensource.org/licenses/mit-license.html "The MIT License"
803 | [3]: https://github.com/vinniefalco/LuaBridge "LuaBridge"
804 | [4]: https://github.com/vinniefalco/LuaBridgeDemo "LuaBridge Demo"
805 | [5]: http://lua.org "The Lua Programming Language"
806 | [6]: http://www.rawmaterialsoftware.com/juce/api/classString.html "juce::String"
807 | [7]: https://github.com/vinniefalco/LuaBridge "LuaBridge master branch"
808 | [8]: https://github.com/vinniefalco/LuaBridge/tree/release "LuaBridge release branch"
809 | [9]: https://github.com/vinniefalco/LuaBridge/tree/develop "LuaBridge develop branch"
810 |
--------------------------------------------------------------------------------
/pugilua/pugilua_lib.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * pugilua - a lua binding for pugixml
3 | * --------------------------------------------------------
4 | * Copyright (C) 2012-2014, by Dmitry Ledentsov (d.ledentsov@gmail.com)
5 | *
6 | * This software is distributed under the MIT License. See notice at the end
7 | * of this file.
8 | *
9 | * This work uses pugixml:
10 | * Copyright (C) 2006-2014, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
11 | */
12 |
13 | #include "pugilua_lib.h"
14 |
15 | #define PUGIXML_NO_EXCEPTIONS
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 |
23 | namespace pugi {
24 | namespace lua {
25 |
26 | static char const* version = "0.1.7";
27 |
28 | static int pugixml_version = PUGIXML_VERSION;
29 |
30 | class options {
31 | public:
32 | options& with(int o) { options_|=o; return *this; }
33 | options& without(int o) { options_&=~o; return *this; }
34 | int get() const { return options_; }
35 | options(int o):options_(o){}
36 | private:
37 | int options_;
38 | };
39 |
40 |
41 | class lxpath_node;
42 | class lxpath_node_set;
43 | class lxml_node;
44 | class lxpath_variable_set;
45 | class lxpath_query;
46 |
47 | ////////////////////
48 | static int encoding_auto = (int)pugi::encoding_auto;
49 | static int encoding_utf8 = (int)pugi::encoding_utf8;
50 | static int encoding_utf16_le = (int)pugi::encoding_utf16_le;
51 | static int encoding_utf16_be = (int)pugi::encoding_utf16_be;
52 | static int encoding_utf16 = (int)pugi::encoding_utf16;
53 | static int encoding_utf32_le = (int)pugi::encoding_utf32_le;
54 | static int encoding_utf32_be = (int)pugi::encoding_utf32_be;
55 | static int encoding_utf32 = (int)pugi::encoding_utf32;
56 | static int encoding_wchar = (int)pugi::encoding_wchar;
57 | static int encoding_latin1 = (int)pugi::encoding_latin1;
58 |
59 | ////////////////////
60 | static int status_ok = (int)pugi::status_ok;
61 | static int status_file_not_found = (int)pugi::status_file_not_found;
62 | static int status_io_error = (int)pugi::status_io_error;
63 | static int status_out_of_memory = (int)pugi::status_out_of_memory;
64 | static int status_internal_error = (int)pugi::status_internal_error;
65 | static int status_unrecognized_tag = (int)pugi::status_unrecognized_tag;
66 | static int status_bad_pi = (int)pugi::status_bad_pi;
67 | static int status_bad_comment = (int)pugi::status_bad_comment;
68 | static int status_bad_cdata = (int)pugi::status_bad_cdata;
69 | static int status_bad_doctype = (int)pugi::status_bad_doctype;
70 | static int status_bad_pcdata = (int)pugi::status_bad_pcdata;
71 | static int status_bad_start_element = (int)pugi::status_bad_start_element;
72 | static int status_bad_attribute = (int)pugi::status_bad_attribute;
73 | static int status_bad_end_element = (int)pugi::status_bad_end_element;
74 | static int status_end_element_mismatch = (int)pugi::status_end_element_mismatch ;
75 |
76 | ////////////////////
77 | static int xpath_type_none = (int)pugi::xpath_type_none;
78 | static int xpath_type_node_set = (int)pugi::xpath_type_node_set;
79 | static int xpath_type_number = (int)pugi::xpath_type_number;
80 | static int xpath_type_string = (int)pugi::xpath_type_string;
81 | static int xpath_type_boolean = (int)pugi::xpath_type_boolean;
82 |
83 | ////////////////////
84 | static int format_indent = (int)pugi::format_indent;
85 | static int format_write_bom = (int)pugi::format_write_bom;
86 | static int format_raw = (int)pugi::format_raw;
87 | static int format_no_declaration = (int)pugi::format_no_declaration;
88 | static int format_no_escapes = (int)pugi::format_no_escapes;
89 | static int format_save_file_text = (int)pugi::format_save_file_text;
90 | static int format_default = (int)pugi::format_default;
91 |
92 | ////////////////////
93 | static int parse_cdata = (int)pugi::parse_cdata;
94 | static int parse_comments = (int)pugi::parse_comments;
95 | static int parse_declaration = (int)pugi::parse_declaration;
96 | static int parse_default = (int)pugi::parse_default;
97 | static int parse_doctype = (int)pugi::parse_doctype;
98 | static int parse_eol = (int)pugi::parse_eol;
99 | static int parse_escapes = (int)pugi::parse_escapes;
100 | static int parse_full = (int)pugi::parse_full;
101 | static int parse_minimal = (int)pugi::parse_minimal;
102 | static int parse_pi = (int)pugi::parse_pi;
103 | static int parse_ws_pcdata = (int)pugi::parse_ws_pcdata;
104 | static int parse_ws_pcdata_single = (int)pugi::parse_ws_pcdata_single;
105 | static int parse_wconv_attribute = (int)pugi::parse_wconv_attribute;
106 | static int parse_wnorm_attribute = (int)pugi::parse_wnorm_attribute;
107 |
108 | ////////////////////
109 | static int node_null = (int)pugi::node_null;
110 | static int node_document = (int)pugi::node_document;
111 | static int node_element = (int)pugi::node_element;
112 | static int node_pcdata = (int)pugi::node_pcdata;
113 | static int node_cdata = (int)pugi::node_cdata;
114 | static int node_comment = (int)pugi::node_comment;
115 | static int node_pi = (int)pugi::node_pi;
116 | static int node_declaration = (int)pugi::node_declaration;
117 | static int node_doctype = (int)pugi::node_doctype;
118 |
119 | ////////////////////
120 | class lxml_attribute {
121 | public:
122 | lxml_attribute(pugi::xml_attribute const& a):att(a) {}
123 | lxml_attribute() {}
124 |
125 | public:
126 | bool valid() const { return att?true:false; }
127 | bool empty() const { return att.empty(); }
128 | std::string name() const { return att.name(); }
129 | std::string value() const { return att.value(); }
130 | double number() const { return att.as_double(); }
131 | bool as_bool() const { return att.as_bool(); }
132 |
133 | bool set_name(char const* n) { return att.set_name(n); }
134 | bool set_value(char const* v) { return att.set_value(v); }
135 |
136 | bool same_as(lxml_attribute const& other) const { return other.att==att; }
137 |
138 | RefCountedPtr next_attribute() const {
139 | return RefCountedPtr(new lxml_attribute(att.next_attribute()));
140 | }
141 |
142 | RefCountedPtr previous_attribute() const {
143 | return RefCountedPtr(new lxml_attribute(att.previous_attribute()));
144 | }
145 |
146 | size_t hash_value() const {
147 | return att.hash_value();
148 | }
149 |
150 | public: // non-lua interface
151 | pugi::xml_attribute const& get() const {
152 | return att;
153 | }
154 |
155 | private:
156 | pugi::xml_attribute att;
157 | };
158 |
159 | ///////////////////////
160 | class lxml_parse_result {
161 | public:
162 | lxml_parse_result(pugi::xml_parse_result const& r);
163 | lxml_parse_result();
164 |
165 | public:
166 | std::string description() const;
167 |
168 | bool valid() const;
169 |
170 | int status() const {
171 | return res.status;
172 | }
173 |
174 | int encoding() const {
175 | return res.encoding;
176 | }
177 |
178 | ptrdiff_t offset() const {
179 | return res.offset;
180 | }
181 |
182 | private:
183 | pugi::xml_parse_result res;
184 | };
185 |
186 |
187 | ///////////////
188 | class lxml_text {
189 | public:
190 | lxml_text(pugi::xml_text const& t):text(t) {}
191 | lxml_text() {}
192 |
193 | public:
194 | bool valid() const {
195 | return text?true:false;
196 | }
197 |
198 | bool empty() const {
199 | return text.empty();
200 | }
201 |
202 | bool set(char const* str) {
203 | return text.set(str);
204 | }
205 |
206 | std::string string() const {
207 | return text.get();
208 | }
209 |
210 | double number() const {
211 | return text.as_double();
212 | }
213 |
214 | bool as_bool() const {
215 | return text.as_bool();
216 | }
217 |
218 | bool same_as(lxml_text const& other) const {
219 | return other.text==text;
220 | }
221 |
222 | RefCountedPtr data() const;
223 |
224 | private:
225 | pugi::xml_text text;
226 | };
227 |
228 | ///////////////
229 | class lxml_node {
230 | public:
231 | lxml_node(pugi::xml_node const& n);
232 | lxml_node();
233 |
234 | public:
235 | bool valid() const;
236 |
237 | std::string name() const;
238 | std::string value() const;
239 |
240 | bool empty() const;
241 |
242 | int type() const;
243 |
244 | RefCountedPtr first_attribute() const;
245 | RefCountedPtr last_attribute() const;
246 |
247 | RefCountedPtr first_child() const;
248 | RefCountedPtr last_child() const;
249 |
250 | RefCountedPtr parent() const;
251 | RefCountedPtr root() const;
252 |
253 | RefCountedPtr child(char const* name) const;
254 | RefCountedPtr attribute(char const* name) const;
255 |
256 | RefCountedPtr next() const;
257 | RefCountedPtr previous() const;
258 |
259 | RefCountedPtr next_sibling(char const* name) const;
260 | RefCountedPtr previous_sibling(char const* name) const;
261 |
262 | std::string child_value(char const* name) const;
263 |
264 | bool set_name(char const* rhs);
265 | bool set_value(char const* rhs);
266 |
267 | RefCountedPtr append_attribute(const char* name);
268 | RefCountedPtr prepend_attribute(const char* name);
269 | RefCountedPtr insert_attribute_after(const char* name, RefCountedPtr attr);
270 | RefCountedPtr insert_attribute_before(const char* name, RefCountedPtr attr);
271 |
272 | RefCountedPtr append_attribute_copy(RefCountedPtr proto);
273 | RefCountedPtr prepend_attribute_copy(RefCountedPtr proto);
274 | RefCountedPtr insert_attribute_copy_after(RefCountedPtr proto, RefCountedPtr attr);
275 | RefCountedPtr insert_attribute_copy_before(RefCountedPtr proto, RefCountedPtr attr);
276 |
277 | RefCountedPtr append(int type);
278 | RefCountedPtr prepend(int type);
279 | RefCountedPtr insert_after(int type, RefCountedPtr _node);
280 | RefCountedPtr insert_before(int type, RefCountedPtr _node);
281 |
282 | RefCountedPtr append_child(const char* name);
283 | RefCountedPtr prepend_child(const char* name);
284 | RefCountedPtr insert_child_after(const char* name, RefCountedPtr _node);
285 | RefCountedPtr insert_child_before(const char* name, RefCountedPtr _node);
286 |
287 | RefCountedPtr append_copy(RefCountedPtr proto);
288 | RefCountedPtr prepend_copy(RefCountedPtr proto);
289 | RefCountedPtr insert_copy_after(RefCountedPtr proto, RefCountedPtr _node);
290 | RefCountedPtr insert_copy_before(RefCountedPtr proto, RefCountedPtr _node);
291 |
292 | bool remove_attribute(RefCountedPtr a);
293 | bool remove_attribute_by_name(const char* name);
294 |
295 | bool remove_child(RefCountedPtr n);
296 | bool remove_child_by_name(const char* name);
297 |
298 | RefCountedPtr find_child_by_name_and_attribute(const char* name, const char* attr_name, const char* attr_value) const;
299 | RefCountedPtr find_child_by_attribute(const char* attr_name, const char* attr_value) const;
300 |
301 | std::string path() const;
302 |
303 | RefCountedPtr first_element_by_path(const char* path) const;
304 |
305 | RefCountedPtr select_single_node(const char* query) const;
306 |
307 | RefCountedPtr select_single_node_with_variables(const char* query,RefCountedPtr variables) const;
308 |
309 | RefCountedPtr select_single_node_query(RefCountedPtr query) const;
310 |
311 | RefCountedPtr select_nodes(char const* query) const;
312 |
313 | RefCountedPtr select_nodes_with_variables(char const* query,RefCountedPtr variables) const;
314 |
315 | RefCountedPtr select_nodes_query(RefCountedPtr query) const;
316 |
317 | std::string string() const;
318 |
319 | std::string as_string_with_options(char const* indent, int flags, int encoding, int depth) const;
320 |
321 | RefCountedPtr text() const;
322 |
323 | bool same_as(lxml_node const& other) const;
324 |
325 | ptrdiff_t offset_debug() const;
326 |
327 | size_t hash_value() const;
328 |
329 | //todo: text(), xml_tree_walker somehow
330 |
331 | public: // non-lua interface
332 | pugi::xml_node const& get() const;
333 |
334 | private:
335 | pugi::xml_node node;
336 | };
337 |
338 | ///////////////////
339 | class lxml_document {
340 | public:
341 | RefCountedPtr root() const;
342 |
343 | bool valid() const;
344 |
345 | void reset();
346 | void reset_with(lxml_document const* other);
347 |
348 | RefCountedPtr load_file(char const* path);
349 | RefCountedPtr load_file_with_options(char const* path,int options, int encoding);
350 | RefCountedPtr load(char const* contents);
351 | RefCountedPtr load_with_options(char const* contents,int options);
352 | bool save_file(char const* path) const;
353 | bool save_file_with_options(char const* path,char const* indent,int flags,int encoding) const;
354 |
355 | private:
356 | pugi::xml_document doc;
357 | };
358 |
359 | ////////////////////////
360 | class lxpath_parse_result {
361 | public:
362 | lxpath_parse_result(pugi::xpath_parse_result const& r) {
363 | res=r;
364 | }
365 | lxpath_parse_result() {}
366 |
367 | public:
368 | std::string error() const {
369 | return res.error;
370 | }
371 |
372 | ptrdiff_t offset() const {
373 | return res.offset;
374 | }
375 |
376 | bool valid() const {
377 | return (bool)res;
378 | }
379 |
380 | std::string description() const {
381 | return res.description();
382 | }
383 |
384 | private:
385 | pugi::xpath_parse_result res;
386 | };
387 |
388 | /////////////////
389 | class lxpath_node {
390 | public:
391 | lxpath_node(pugi::xpath_node const& n);
392 | lxpath_node();
393 |
394 | bool valid() const;
395 |
396 | RefCountedPtr node() const;
397 | RefCountedPtr attribute() const;
398 | void from_node(RefCountedPtr other);
399 | void from_attribute(RefCountedPtr,RefCountedPtr other);
400 | RefCountedPtr parent() const;
401 | bool same_as(RefCountedPtr other) const;
402 |
403 | public: //non-interface
404 | pugi::xpath_node const& get() {
405 | return _node;
406 | }
407 |
408 | private:
409 | pugi::xpath_node _node;
410 | };
411 |
412 | /////////////////////
413 | class lxpath_node_set {
414 | public:
415 | lxpath_node_set(pugi::xpath_node_set const& s);
416 | lxpath_node_set();
417 | public:
418 |
419 | int type() const;
420 |
421 | size_t size() const;
422 |
423 | // todo: think if 1..size is a better convention for lua
424 | RefCountedPtr get(size_t i);
425 |
426 | void sort(bool reverse);
427 |
428 | bool empty() const;
429 |
430 | RefCountedPtr first() const;
431 |
432 | public:
433 | // enums
434 | static int type_unsorted () { return pugi::xpath_node_set::type_unsorted; }
435 | static int type_sorted () { return pugi::xpath_node_set::type_sorted; }
436 | static int type_sorted_reverse () { return pugi::xpath_node_set::type_sorted_reverse; }
437 |
438 | public: //non-interface
439 | pugi::xpath_node_set const& get_node_set() const {
440 | return node_set;
441 | }
442 |
443 | private:
444 | pugi::xpath_node_set node_set;
445 | };
446 |
447 | ////////////////////
448 | class lxpath_variable {
449 | public:
450 | lxpath_variable():var(0){}
451 |
452 | public:
453 | std::string name() const {
454 | if (var)
455 | return var->name();
456 | else
457 | return "";
458 | }
459 |
460 | int type() const {
461 | if (var)
462 | return (int)var->type();
463 | else
464 | return pugi::xpath_type_none;
465 | }
466 |
467 | bool get_boolean() const {
468 | if (var)
469 | return var->get_boolean();
470 | else
471 | return false;
472 | }
473 |
474 | double number() const {
475 | if (var)
476 | return var->get_number();
477 | else
478 | return 0;
479 | }
480 |
481 | std::string get_string() const {
482 | if (var)
483 | return var->get_string();
484 | else
485 | return "";
486 | }
487 |
488 | RefCountedPtr get_node_set() const {
489 | if (var)
490 | return RefCountedPtr(new lxpath_node_set(var->get_node_set()));
491 | else
492 | return RefCountedPtr(new lxpath_node_set(pugi::xpath_node_set()));
493 | }
494 |
495 | bool set(char const* val) {
496 | if (var)
497 | return var->set(val);
498 | else
499 | return false;
500 | }
501 |
502 | bool set_node_set(RefCountedPtr s) {
503 | if (var)
504 | return var->set(!!s.get());
505 | else
506 | return false;
507 | }
508 |
509 | bool valid() const {
510 | return var?true:false;
511 | }
512 |
513 | public: //non-interface
514 |
515 | void set_var(pugi::xpath_variable* v) {
516 | var=v;
517 | }
518 |
519 | private:
520 | pugi::xpath_variable* var;
521 | };
522 |
523 | /////////////////////////
524 | class lxpath_variable_set {
525 | public:
526 | lxpath_variable_set():set_(0) {}
527 | public:
528 | RefCountedPtr add(char const* name,int type) {
529 | RefCountedPtr res(new lxpath_variable);
530 | if (set_) {
531 | res->set_var(set_->add(name,(pugi::xpath_value_type)type));
532 | }
533 | return res;
534 | }
535 |
536 | bool set(char const* name,char const* value) {
537 | if (set_)
538 | return set_->set(name,value);
539 | else
540 | return false;
541 | }
542 |
543 | bool set_node_set(char const* name,RefCountedPtr value) {
544 | if (set_)
545 | return set_->set(name,value->get_node_set());
546 | else
547 | return false;
548 | }
549 |
550 | RefCountedPtr get(char const* name) {
551 | RefCountedPtr res(new lxpath_variable);
552 | if (set_) {
553 | res->set_var(set_->get(name));
554 | }
555 | return res;
556 | }
557 |
558 | public:
559 | bool valid() const {
560 | return set_?true:false;
561 | }
562 |
563 | public: //non-interface
564 | void set_set(pugi::xpath_variable_set* s) {
565 | set_=s;
566 | }
567 |
568 | pugi::xpath_variable_set* get_set() {
569 | return set_;
570 | }
571 |
572 | private:
573 | pugi::xpath_variable_set* set_;
574 | };
575 |
576 | //////////////////
577 | class lxpath_query {
578 | public:
579 | explicit lxpath_query(char const* s):q(s) {}
580 | explicit lxpath_query(char const* s,RefCountedPtr v):q(s,v->get_set()) {}
581 |
582 | public: //static constructors
583 | static RefCountedPtr from_string(char const* s);
584 | static RefCountedPtr with_variables(char const* s,RefCountedPtr v);
585 |
586 | public:
587 | bool evaluate_boolean(RefCountedPtr n) const {
588 | return q.evaluate_boolean(n->get());
589 | }
590 |
591 | double evaluate_number(RefCountedPtr n) const {
592 | return q.evaluate_number(n->get());
593 | }
594 |
595 | std::string evaluate_string(RefCountedPtr n) const {
596 | return q.evaluate_string(n->get());
597 | }
598 |
599 | RefCountedPtr evaluate_node_set(RefCountedPtr n) const {
600 | return RefCountedPtr(new lxpath_node_set(q.evaluate_node_set(n->get())));
601 | }
602 |
603 | int return_type() const {
604 | return (int)q.return_type();
605 | }
606 |
607 | RefCountedPtr result() const {
608 | return RefCountedPtr(new lxpath_parse_result(q.result()));
609 | }
610 |
611 | bool valid() const {
612 | return q?true:false;
613 | }
614 |
615 | public:
616 | pugi::xpath_query const& get() {
617 | return q;
618 | }
619 |
620 | private:
621 | pugi::xpath_query q;
622 | };
623 |
624 | ////////////////////////////////////////////////////////////////////
625 | RefCountedPtr lxpath_query::from_string(char const* s) {
626 | return RefCountedPtr(new lxpath_query(s));
627 | }
628 |
629 | RefCountedPtr lxpath_query::with_variables(char const* s,RefCountedPtr v) {
630 | return RefCountedPtr(new lxpath_query(s,v));
631 | }
632 | }
633 | }
634 |
635 | namespace pugi {
636 | namespace lua {
637 |
638 | ///////////////////////
639 | lxml_parse_result::lxml_parse_result(pugi::xml_parse_result const& r):res(r) { }
640 | lxml_parse_result::lxml_parse_result() { }
641 |
642 | std::string lxml_parse_result::description() const {
643 | return res.description();
644 | }
645 |
646 | bool lxml_parse_result::valid() const {
647 | return (bool)res;
648 | }
649 |
650 |
651 | ///////////////
652 | lxml_node::lxml_node(pugi::xml_node const& n):node(n){}
653 | lxml_node::lxml_node() { }
654 |
655 | pugi::xml_node const& lxml_node::get() const {
656 | return node;
657 | }
658 |
659 | bool lxml_node::valid() const {
660 | return node?true:false;
661 | }
662 |
663 | RefCountedPtr lxml_node::child(char const* name) const {
664 | return RefCountedPtr(new lxml_node(node.child(name)));
665 | }
666 |
667 | std::string lxml_node::name() const {
668 | return node.name();
669 | }
670 |
671 | std::string lxml_node::value() const {
672 | return node.value();
673 | }
674 |
675 | RefCountedPtr lxml_node::select_nodes(char const* query) const {
676 | try {
677 | return RefCountedPtr(new lxpath_node_set(node.select_nodes(query)));
678 | } catch (std::exception const& e) {
679 | std::cerr<<"Error: "<(new lxpath_node_set());
681 | }
682 | }
683 |
684 | RefCountedPtr lxml_node::select_nodes_with_variables(char const* query,RefCountedPtr variables) const {
685 | try {
686 | return RefCountedPtr(new lxpath_node_set(node.select_nodes(query,variables->get_set())));
687 | } catch (std::exception const& e) {
688 | std::cerr<<"Error: "<(new lxpath_node_set());
690 | }
691 | }
692 |
693 | RefCountedPtr lxml_node::select_nodes_query(RefCountedPtr query) const {
694 | try {
695 | return RefCountedPtr(new lxpath_node_set(node.select_nodes(query->get())));
696 | } catch (std::exception const& e) {
697 | std::cerr<<"Error: "<(new lxpath_node_set());
699 | }
700 | }
701 |
702 | bool lxml_node::empty() const {
703 | return node.empty();
704 | }
705 |
706 | int lxml_node::type() const {
707 | return node.type();
708 | }
709 |
710 | RefCountedPtr lxml_node::first_attribute() const {
711 | return RefCountedPtr(new lxml_attribute(node.first_attribute()));
712 | }
713 |
714 | RefCountedPtr lxml_node::last_attribute() const {
715 | return RefCountedPtr(new lxml_attribute(node.last_attribute()));
716 | }
717 |
718 | RefCountedPtr lxml_node::first_child() const {
719 | return RefCountedPtr(new lxml_node(node.first_child()));
720 | }
721 |
722 | RefCountedPtr lxml_node::last_child() const {
723 | return RefCountedPtr(new lxml_node(node.last_child()));
724 | }
725 |
726 | RefCountedPtr lxml_node::parent() const {
727 | return RefCountedPtr(new lxml_node(node.parent()));
728 | }
729 |
730 | RefCountedPtr lxml_node::root() const {
731 | return RefCountedPtr(new lxml_node(node.root()));
732 | }
733 |
734 | RefCountedPtr lxml_node::attribute(char const* name) const {
735 | return RefCountedPtr(new lxml_attribute(node.attribute(name)));
736 | }
737 |
738 | RefCountedPtr lxml_node::next() const {
739 | return RefCountedPtr(new lxml_node(node.next_sibling()));
740 | }
741 |
742 | RefCountedPtr lxml_node::previous() const {
743 | return RefCountedPtr(new lxml_node(node.previous_sibling()));
744 | }
745 |
746 | RefCountedPtr lxml_node::next_sibling(char const* name) const {
747 | return RefCountedPtr(new lxml_node(node.next_sibling(name)));
748 | }
749 |
750 | RefCountedPtr lxml_node::previous_sibling(char const* name) const {
751 | return RefCountedPtr(new lxml_node(node.previous_sibling(name)));
752 | }
753 |
754 | std::string lxml_node::child_value(char const* name) const {
755 | return node.child_value(name);
756 | }
757 |
758 | bool lxml_node::set_name(char const* rhs) {
759 | return node.set_name(rhs);
760 | }
761 |
762 | bool lxml_node::set_value(char const* rhs) {
763 | return node.set_value(rhs);
764 | }
765 |
766 | RefCountedPtr lxml_node::append_attribute(const char* name) {
767 | return RefCountedPtr(new lxml_attribute(node.append_attribute(name)));
768 | }
769 |
770 | RefCountedPtr lxml_node::prepend_attribute(const char* name) {
771 | return RefCountedPtr(new lxml_attribute(node.prepend_attribute(name)));
772 | }
773 |
774 | RefCountedPtr lxml_node::insert_attribute_after(const char* name, RefCountedPtr attr) {
775 | return RefCountedPtr(new lxml_attribute(node.insert_attribute_after(name,attr->get())));
776 | }
777 |
778 | RefCountedPtr lxml_node::insert_attribute_before(const char* name, RefCountedPtr attr) {
779 | return RefCountedPtr(new lxml_attribute(node.insert_attribute_before(name,attr->get())));
780 | }
781 |
782 | RefCountedPtr lxml_node::append_attribute_copy(RefCountedPtr proto) {
783 | return RefCountedPtr(new lxml_attribute(node.append_copy(proto->get())));
784 | }
785 |
786 | RefCountedPtr lxml_node::prepend_attribute_copy(RefCountedPtr proto) {
787 | return RefCountedPtr(new lxml_attribute(node.prepend_copy(proto->get())));
788 | }
789 |
790 | RefCountedPtr lxml_node::insert_attribute_copy_after(RefCountedPtr proto, RefCountedPtr attr) {
791 | return RefCountedPtr(new lxml_attribute(node.insert_copy_after(proto->get(),attr->get())));
792 | }
793 |
794 | RefCountedPtr lxml_node::insert_attribute_copy_before(RefCountedPtr proto, RefCountedPtr attr) {
795 | return RefCountedPtr(new lxml_attribute(node.insert_copy_before(proto->get(),attr->get())));
796 | }
797 |
798 | RefCountedPtr lxml_node::append(int type) {
799 | return RefCountedPtr(new lxml_node(node.append_child((xml_node_type)type)));
800 | }
801 |
802 | RefCountedPtr