tsujikiri 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tsujikiri-0.1.0/LICENSE +21 -0
- tsujikiri-0.1.0/PKG-INFO +315 -0
- tsujikiri-0.1.0/README.md +290 -0
- tsujikiri-0.1.0/pyproject.toml +57 -0
- tsujikiri-0.1.0/setup.cfg +4 -0
- tsujikiri-0.1.0/src/tsujikiri/__init__.py +1 -0
- tsujikiri-0.1.0/src/tsujikiri/__main__.py +4 -0
- tsujikiri-0.1.0/src/tsujikiri/clang_base_enumerations.py +454 -0
- tsujikiri-0.1.0/src/tsujikiri/cli.py +186 -0
- tsujikiri-0.1.0/src/tsujikiri/configurations.py +440 -0
- tsujikiri-0.1.0/src/tsujikiri/filters.py +166 -0
- tsujikiri-0.1.0/src/tsujikiri/formats/__init__.py +70 -0
- tsujikiri-0.1.0/src/tsujikiri/formats/luabridge3.output.yml +114 -0
- tsujikiri-0.1.0/src/tsujikiri/formats/luals.output.yml +131 -0
- tsujikiri-0.1.0/src/tsujikiri/generator.py +587 -0
- tsujikiri-0.1.0/src/tsujikiri/helpers/generate_clang_base_enumeration_member_types.py +25 -0
- tsujikiri-0.1.0/src/tsujikiri/helpers/generate_cursor_manager.py +47 -0
- tsujikiri-0.1.0/src/tsujikiri/ir.py +125 -0
- tsujikiri-0.1.0/src/tsujikiri/parser.py +215 -0
- tsujikiri-0.1.0/src/tsujikiri/transforms.py +279 -0
- tsujikiri-0.1.0/src/tsujikiri.egg-info/PKG-INFO +315 -0
- tsujikiri-0.1.0/src/tsujikiri.egg-info/SOURCES.txt +24 -0
- tsujikiri-0.1.0/src/tsujikiri.egg-info/dependency_links.txt +1 -0
- tsujikiri-0.1.0/src/tsujikiri.egg-info/entry_points.txt +2 -0
- tsujikiri-0.1.0/src/tsujikiri.egg-info/requires.txt +9 -0
- tsujikiri-0.1.0/src/tsujikiri.egg-info/top_level.txt +1 -0
tsujikiri-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kunitoki
|
|
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.
|
tsujikiri-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tsujikiri
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 辻斬り Generic C++ Bindings Generator
|
|
5
|
+
Author-email: kunitoki <kunitoki@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/kunitoki/tsujikiri
|
|
8
|
+
Classifier: Topic :: Utilities
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Requires-Python: >=3.12
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: libclang==16.0.6
|
|
17
|
+
Requires-Dist: pyyaml>=6.0
|
|
18
|
+
Requires-Dist: jinja2>=3.1
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest>=9.0; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest-cov>=5.0; extra == "dev"
|
|
22
|
+
Requires-Dist: cmake>=3.20; extra == "dev"
|
|
23
|
+
Requires-Dist: zig-bin>=0.15.2; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# tsujikiri — 辻斬り
|
|
27
|
+
|
|
28
|
+
> **Generic C++ Bindings Generator**
|
|
29
|
+
|
|
30
|
+
[](https://github.com/kunitoki/tsujikiri/actions/workflows/tests.yml)
|
|
31
|
+
[](https://codecov.io/gh/kunitoki/tsujikiri)
|
|
32
|
+
[](https://pypi.org/project/tsujikiri/)
|
|
33
|
+
[](https://pypi.org/project/tsujikiri/)
|
|
34
|
+
[](LICENSE)
|
|
35
|
+
|
|
36
|
+
tsujikiri parses C++ headers via **libclang** and generates binding code through a **template-driven pipeline**. Define what to expose, plug in a target format, and get ready-to-compile bindings.
|
|
37
|
+
|
|
38
|
+
Built-in support for [LuaBridge3](https://github.com/kunitoki/LuaBridge3) (Lua bindings) and [LuaLS](https://luals.github.io/) (Lua Language Server annotations). Custom formats are first-class.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## How It Works
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
C++ Header (.hpp)
|
|
46
|
+
│
|
|
47
|
+
▼ libclang
|
|
48
|
+
Intermediate Representation (IR)
|
|
49
|
+
│
|
|
50
|
+
├─▶ FilterEngine suppress classes / methods / fields by pattern
|
|
51
|
+
│
|
|
52
|
+
├─▶ Transform Pipeline rename, inject, remap types
|
|
53
|
+
│
|
|
54
|
+
▼ Jinja2 templates
|
|
55
|
+
Target Binding Code
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Each phase is independently configurable per input file and per output format.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install tsujikiri
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Requirements:** Python ≥ 3.12, libclang 16
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Quick Start
|
|
73
|
+
|
|
74
|
+
### 1. Write an input config
|
|
75
|
+
|
|
76
|
+
```yaml
|
|
77
|
+
# myproject.input.yml
|
|
78
|
+
source:
|
|
79
|
+
path: myproject.hpp
|
|
80
|
+
parse_args: ["-std=c++17"]
|
|
81
|
+
include_paths: ["/usr/local/include"]
|
|
82
|
+
|
|
83
|
+
filters:
|
|
84
|
+
namespaces: ["myproject"]
|
|
85
|
+
classes:
|
|
86
|
+
whitelist: ["Vec3", "Matrix4", "Camera"]
|
|
87
|
+
constructors:
|
|
88
|
+
include: true
|
|
89
|
+
|
|
90
|
+
generation:
|
|
91
|
+
includes: ["<myproject.hpp>"]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 2. Generate bindings
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Print to stdout
|
|
98
|
+
tsujikiri -i myproject.input.yml -o luabridge3
|
|
99
|
+
|
|
100
|
+
# Write to file
|
|
101
|
+
tsujikiri -i myproject.input.yml -o luabridge3 -O bindings.cpp
|
|
102
|
+
|
|
103
|
+
# Dry-run: parse and filter, print summary
|
|
104
|
+
tsujikiri -i myproject.input.yml -o luabridge3 --dry-run
|
|
105
|
+
|
|
106
|
+
# List available formats
|
|
107
|
+
tsujikiri --list-formats
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 3. Example output (LuaBridge3)
|
|
111
|
+
|
|
112
|
+
Given a header with a `Vec3` class, tsujikiri emits:
|
|
113
|
+
|
|
114
|
+
```cpp
|
|
115
|
+
#include <myproject.hpp>
|
|
116
|
+
#include <LuaBridge/LuaBridge.h>
|
|
117
|
+
|
|
118
|
+
void register_myproject(lua_State* L)
|
|
119
|
+
{
|
|
120
|
+
luabridge::getGlobalNamespace(L)
|
|
121
|
+
.beginClass<myproject::Vec3>("Vec3")
|
|
122
|
+
.addConstructor<void(*)(float, float, float)>()
|
|
123
|
+
.addFunction("length", &myproject::Vec3::length)
|
|
124
|
+
.addFunction("dot", &myproject::Vec3::dot)
|
|
125
|
+
.addProperty("x", &myproject::Vec3::x)
|
|
126
|
+
.addProperty("y", &myproject::Vec3::y)
|
|
127
|
+
.addProperty("z", &myproject::Vec3::z)
|
|
128
|
+
.endClass();
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Input Configuration Reference
|
|
135
|
+
|
|
136
|
+
```yaml
|
|
137
|
+
source:
|
|
138
|
+
path: "myheader.hpp" # C++ header to parse
|
|
139
|
+
parse_args: ["-std=c++17"] # Extra clang flags
|
|
140
|
+
include_paths: [] # Additional include directories
|
|
141
|
+
|
|
142
|
+
filters:
|
|
143
|
+
namespaces: [] # Restrict parsing to these namespaces
|
|
144
|
+
classes:
|
|
145
|
+
whitelist: [] # Include only matching class names (supports regex)
|
|
146
|
+
blacklist: [] # Exclude matching class names
|
|
147
|
+
methods:
|
|
148
|
+
global_blacklist: [] # Exclude methods from all classes
|
|
149
|
+
per_class: # Per-class method exclusion
|
|
150
|
+
MyClass: ["internalHelper"]
|
|
151
|
+
fields:
|
|
152
|
+
global_blacklist: []
|
|
153
|
+
constructors:
|
|
154
|
+
include: false # Whether to emit constructors
|
|
155
|
+
signatures: [] # Filter by parameter type signature
|
|
156
|
+
functions:
|
|
157
|
+
blacklist: [] # Exclude free functions
|
|
158
|
+
|
|
159
|
+
transforms:
|
|
160
|
+
- stage: rename_method
|
|
161
|
+
class: MyClass
|
|
162
|
+
from: getValueForKey
|
|
163
|
+
to: get
|
|
164
|
+
|
|
165
|
+
- stage: rename_class
|
|
166
|
+
from: SomeInternal
|
|
167
|
+
to: PublicName
|
|
168
|
+
|
|
169
|
+
- stage: suppress_method
|
|
170
|
+
class: "*"
|
|
171
|
+
pattern: "operator.*"
|
|
172
|
+
is_regex: true
|
|
173
|
+
|
|
174
|
+
- stage: inject_method
|
|
175
|
+
class: MyClass
|
|
176
|
+
snippet: ".addFunction(\"create\", &MyClass::create)"
|
|
177
|
+
|
|
178
|
+
- stage: add_type_mapping
|
|
179
|
+
from: "std::string_view"
|
|
180
|
+
to: "std::string"
|
|
181
|
+
|
|
182
|
+
generation:
|
|
183
|
+
includes: ["<mylib.h>"] # Extra #include lines in output
|
|
184
|
+
prefix: "" # Literal text prepended to output
|
|
185
|
+
postfix: "" # Literal text appended to output
|
|
186
|
+
|
|
187
|
+
format_overrides: # Per-format overrides (filters, transforms, generation)
|
|
188
|
+
luabridge3:
|
|
189
|
+
generation:
|
|
190
|
+
includes: ["<LuaBridge/LuaBridge.h>"]
|
|
191
|
+
transforms:
|
|
192
|
+
- stage: suppress_method
|
|
193
|
+
class: "*"
|
|
194
|
+
pattern: "clone"
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Transform stages
|
|
198
|
+
|
|
199
|
+
| Stage | Effect |
|
|
200
|
+
|---|---|
|
|
201
|
+
| `rename_method` | Change the emitted name of a method |
|
|
202
|
+
| `rename_class` | Change the emitted name of a class |
|
|
203
|
+
| `suppress_method` | Remove a method from output |
|
|
204
|
+
| `suppress_class` | Remove a class from output |
|
|
205
|
+
| `inject_method` | Inject raw template snippet into a class block |
|
|
206
|
+
| `add_type_mapping` | Rewrite a C++ type spelling in all signatures |
|
|
207
|
+
|
|
208
|
+
All `pattern` fields accept plain strings or regex (`is_regex: true`). Use `"*"` to match all classes.
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Built-in Formats
|
|
213
|
+
|
|
214
|
+
### `luabridge3`
|
|
215
|
+
|
|
216
|
+
Generates C++ registration code for [LuaBridge3](https://github.com/kunitoki/LuaBridge3).
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
tsujikiri -i project.input.yml -o luabridge3 -O bindings/lua_bindings.cpp
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Handles: classes, constructors, instance/static methods, overloaded methods, properties, enums, free functions, inheritance.
|
|
223
|
+
|
|
224
|
+
### `luals`
|
|
225
|
+
|
|
226
|
+
Generates [Lua Language Server](https://luals.github.io/) annotation stubs.
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
tsujikiri -i project.input.yml -o luals -O types/myproject.lua
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Emits `---@class`, `---@field`, `---@param`, `---@return` annotations with C++→Lua type mappings.
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Custom Formats
|
|
237
|
+
|
|
238
|
+
Create a `myformat.output.yml` alongside your templates:
|
|
239
|
+
|
|
240
|
+
```yaml
|
|
241
|
+
format_name: "myformat"
|
|
242
|
+
format_version: "1.0"
|
|
243
|
+
description: "My custom binding format"
|
|
244
|
+
|
|
245
|
+
type_mappings:
|
|
246
|
+
"std::string": "String"
|
|
247
|
+
"int32_t": "int"
|
|
248
|
+
|
|
249
|
+
unsupported_types:
|
|
250
|
+
- "CFStringRef"
|
|
251
|
+
|
|
252
|
+
templates:
|
|
253
|
+
prologue: |
|
|
254
|
+
// Generated by tsujikiri
|
|
255
|
+
package {{ module_name }};
|
|
256
|
+
class_begin: "register_class<{{ qualified_class_name }}>(\"{{ class_name }}\""
|
|
257
|
+
# ... define all template keys
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Point tsujikiri at your format directory:
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
tsujikiri -i project.input.yml -o myformat -F ./my_formats/ -O out/bindings.cpp
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## CLI Reference
|
|
269
|
+
|
|
270
|
+
```
|
|
271
|
+
tsujikiri [OPTIONS]
|
|
272
|
+
|
|
273
|
+
Options:
|
|
274
|
+
-i, --input FILE Input config YAML (required)
|
|
275
|
+
-o, --output FORMAT|FILE Built-in format name or path to .output.yml
|
|
276
|
+
-O, --output-file FILE Write output to file instead of stdout
|
|
277
|
+
-c, --classname CLASS Generate bindings for a single class only
|
|
278
|
+
-F, --formats-dir DIR Extra directory to search for .output.yml files (repeatable)
|
|
279
|
+
--list-formats Print available formats and exit
|
|
280
|
+
--dry-run Parse and filter only; print IR summary without generating
|
|
281
|
+
-h, --help Show this message and exit
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Development
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
# Install task runner and sync dependencies
|
|
290
|
+
pip install just uv
|
|
291
|
+
just sync
|
|
292
|
+
|
|
293
|
+
# Run tests
|
|
294
|
+
just test
|
|
295
|
+
|
|
296
|
+
# Run tests with coverage
|
|
297
|
+
just coverage
|
|
298
|
+
|
|
299
|
+
# Build wheel
|
|
300
|
+
just build
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
The test suite covers parsing, filtering, transforms, generation, CLI integration, and end-to-end compilation with LuaBridge3.
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## Coverage
|
|
308
|
+
|
|
309
|
+
[](https://codecov.io/gh/kunitoki/tsujikiri)
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## License
|
|
314
|
+
|
|
315
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
# tsujikiri — 辻斬り
|
|
2
|
+
|
|
3
|
+
> **Generic C++ Bindings Generator**
|
|
4
|
+
|
|
5
|
+
[](https://github.com/kunitoki/tsujikiri/actions/workflows/tests.yml)
|
|
6
|
+
[](https://codecov.io/gh/kunitoki/tsujikiri)
|
|
7
|
+
[](https://pypi.org/project/tsujikiri/)
|
|
8
|
+
[](https://pypi.org/project/tsujikiri/)
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
|
|
11
|
+
tsujikiri parses C++ headers via **libclang** and generates binding code through a **template-driven pipeline**. Define what to expose, plug in a target format, and get ready-to-compile bindings.
|
|
12
|
+
|
|
13
|
+
Built-in support for [LuaBridge3](https://github.com/kunitoki/LuaBridge3) (Lua bindings) and [LuaLS](https://luals.github.io/) (Lua Language Server annotations). Custom formats are first-class.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## How It Works
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
C++ Header (.hpp)
|
|
21
|
+
│
|
|
22
|
+
▼ libclang
|
|
23
|
+
Intermediate Representation (IR)
|
|
24
|
+
│
|
|
25
|
+
├─▶ FilterEngine suppress classes / methods / fields by pattern
|
|
26
|
+
│
|
|
27
|
+
├─▶ Transform Pipeline rename, inject, remap types
|
|
28
|
+
│
|
|
29
|
+
▼ Jinja2 templates
|
|
30
|
+
Target Binding Code
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Each phase is independently configurable per input file and per output format.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install tsujikiri
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Requirements:** Python ≥ 3.12, libclang 16
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
### 1. Write an input config
|
|
50
|
+
|
|
51
|
+
```yaml
|
|
52
|
+
# myproject.input.yml
|
|
53
|
+
source:
|
|
54
|
+
path: myproject.hpp
|
|
55
|
+
parse_args: ["-std=c++17"]
|
|
56
|
+
include_paths: ["/usr/local/include"]
|
|
57
|
+
|
|
58
|
+
filters:
|
|
59
|
+
namespaces: ["myproject"]
|
|
60
|
+
classes:
|
|
61
|
+
whitelist: ["Vec3", "Matrix4", "Camera"]
|
|
62
|
+
constructors:
|
|
63
|
+
include: true
|
|
64
|
+
|
|
65
|
+
generation:
|
|
66
|
+
includes: ["<myproject.hpp>"]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 2. Generate bindings
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Print to stdout
|
|
73
|
+
tsujikiri -i myproject.input.yml -o luabridge3
|
|
74
|
+
|
|
75
|
+
# Write to file
|
|
76
|
+
tsujikiri -i myproject.input.yml -o luabridge3 -O bindings.cpp
|
|
77
|
+
|
|
78
|
+
# Dry-run: parse and filter, print summary
|
|
79
|
+
tsujikiri -i myproject.input.yml -o luabridge3 --dry-run
|
|
80
|
+
|
|
81
|
+
# List available formats
|
|
82
|
+
tsujikiri --list-formats
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 3. Example output (LuaBridge3)
|
|
86
|
+
|
|
87
|
+
Given a header with a `Vec3` class, tsujikiri emits:
|
|
88
|
+
|
|
89
|
+
```cpp
|
|
90
|
+
#include <myproject.hpp>
|
|
91
|
+
#include <LuaBridge/LuaBridge.h>
|
|
92
|
+
|
|
93
|
+
void register_myproject(lua_State* L)
|
|
94
|
+
{
|
|
95
|
+
luabridge::getGlobalNamespace(L)
|
|
96
|
+
.beginClass<myproject::Vec3>("Vec3")
|
|
97
|
+
.addConstructor<void(*)(float, float, float)>()
|
|
98
|
+
.addFunction("length", &myproject::Vec3::length)
|
|
99
|
+
.addFunction("dot", &myproject::Vec3::dot)
|
|
100
|
+
.addProperty("x", &myproject::Vec3::x)
|
|
101
|
+
.addProperty("y", &myproject::Vec3::y)
|
|
102
|
+
.addProperty("z", &myproject::Vec3::z)
|
|
103
|
+
.endClass();
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Input Configuration Reference
|
|
110
|
+
|
|
111
|
+
```yaml
|
|
112
|
+
source:
|
|
113
|
+
path: "myheader.hpp" # C++ header to parse
|
|
114
|
+
parse_args: ["-std=c++17"] # Extra clang flags
|
|
115
|
+
include_paths: [] # Additional include directories
|
|
116
|
+
|
|
117
|
+
filters:
|
|
118
|
+
namespaces: [] # Restrict parsing to these namespaces
|
|
119
|
+
classes:
|
|
120
|
+
whitelist: [] # Include only matching class names (supports regex)
|
|
121
|
+
blacklist: [] # Exclude matching class names
|
|
122
|
+
methods:
|
|
123
|
+
global_blacklist: [] # Exclude methods from all classes
|
|
124
|
+
per_class: # Per-class method exclusion
|
|
125
|
+
MyClass: ["internalHelper"]
|
|
126
|
+
fields:
|
|
127
|
+
global_blacklist: []
|
|
128
|
+
constructors:
|
|
129
|
+
include: false # Whether to emit constructors
|
|
130
|
+
signatures: [] # Filter by parameter type signature
|
|
131
|
+
functions:
|
|
132
|
+
blacklist: [] # Exclude free functions
|
|
133
|
+
|
|
134
|
+
transforms:
|
|
135
|
+
- stage: rename_method
|
|
136
|
+
class: MyClass
|
|
137
|
+
from: getValueForKey
|
|
138
|
+
to: get
|
|
139
|
+
|
|
140
|
+
- stage: rename_class
|
|
141
|
+
from: SomeInternal
|
|
142
|
+
to: PublicName
|
|
143
|
+
|
|
144
|
+
- stage: suppress_method
|
|
145
|
+
class: "*"
|
|
146
|
+
pattern: "operator.*"
|
|
147
|
+
is_regex: true
|
|
148
|
+
|
|
149
|
+
- stage: inject_method
|
|
150
|
+
class: MyClass
|
|
151
|
+
snippet: ".addFunction(\"create\", &MyClass::create)"
|
|
152
|
+
|
|
153
|
+
- stage: add_type_mapping
|
|
154
|
+
from: "std::string_view"
|
|
155
|
+
to: "std::string"
|
|
156
|
+
|
|
157
|
+
generation:
|
|
158
|
+
includes: ["<mylib.h>"] # Extra #include lines in output
|
|
159
|
+
prefix: "" # Literal text prepended to output
|
|
160
|
+
postfix: "" # Literal text appended to output
|
|
161
|
+
|
|
162
|
+
format_overrides: # Per-format overrides (filters, transforms, generation)
|
|
163
|
+
luabridge3:
|
|
164
|
+
generation:
|
|
165
|
+
includes: ["<LuaBridge/LuaBridge.h>"]
|
|
166
|
+
transforms:
|
|
167
|
+
- stage: suppress_method
|
|
168
|
+
class: "*"
|
|
169
|
+
pattern: "clone"
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Transform stages
|
|
173
|
+
|
|
174
|
+
| Stage | Effect |
|
|
175
|
+
|---|---|
|
|
176
|
+
| `rename_method` | Change the emitted name of a method |
|
|
177
|
+
| `rename_class` | Change the emitted name of a class |
|
|
178
|
+
| `suppress_method` | Remove a method from output |
|
|
179
|
+
| `suppress_class` | Remove a class from output |
|
|
180
|
+
| `inject_method` | Inject raw template snippet into a class block |
|
|
181
|
+
| `add_type_mapping` | Rewrite a C++ type spelling in all signatures |
|
|
182
|
+
|
|
183
|
+
All `pattern` fields accept plain strings or regex (`is_regex: true`). Use `"*"` to match all classes.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Built-in Formats
|
|
188
|
+
|
|
189
|
+
### `luabridge3`
|
|
190
|
+
|
|
191
|
+
Generates C++ registration code for [LuaBridge3](https://github.com/kunitoki/LuaBridge3).
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
tsujikiri -i project.input.yml -o luabridge3 -O bindings/lua_bindings.cpp
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Handles: classes, constructors, instance/static methods, overloaded methods, properties, enums, free functions, inheritance.
|
|
198
|
+
|
|
199
|
+
### `luals`
|
|
200
|
+
|
|
201
|
+
Generates [Lua Language Server](https://luals.github.io/) annotation stubs.
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
tsujikiri -i project.input.yml -o luals -O types/myproject.lua
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Emits `---@class`, `---@field`, `---@param`, `---@return` annotations with C++→Lua type mappings.
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## Custom Formats
|
|
212
|
+
|
|
213
|
+
Create a `myformat.output.yml` alongside your templates:
|
|
214
|
+
|
|
215
|
+
```yaml
|
|
216
|
+
format_name: "myformat"
|
|
217
|
+
format_version: "1.0"
|
|
218
|
+
description: "My custom binding format"
|
|
219
|
+
|
|
220
|
+
type_mappings:
|
|
221
|
+
"std::string": "String"
|
|
222
|
+
"int32_t": "int"
|
|
223
|
+
|
|
224
|
+
unsupported_types:
|
|
225
|
+
- "CFStringRef"
|
|
226
|
+
|
|
227
|
+
templates:
|
|
228
|
+
prologue: |
|
|
229
|
+
// Generated by tsujikiri
|
|
230
|
+
package {{ module_name }};
|
|
231
|
+
class_begin: "register_class<{{ qualified_class_name }}>(\"{{ class_name }}\""
|
|
232
|
+
# ... define all template keys
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Point tsujikiri at your format directory:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
tsujikiri -i project.input.yml -o myformat -F ./my_formats/ -O out/bindings.cpp
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## CLI Reference
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
tsujikiri [OPTIONS]
|
|
247
|
+
|
|
248
|
+
Options:
|
|
249
|
+
-i, --input FILE Input config YAML (required)
|
|
250
|
+
-o, --output FORMAT|FILE Built-in format name or path to .output.yml
|
|
251
|
+
-O, --output-file FILE Write output to file instead of stdout
|
|
252
|
+
-c, --classname CLASS Generate bindings for a single class only
|
|
253
|
+
-F, --formats-dir DIR Extra directory to search for .output.yml files (repeatable)
|
|
254
|
+
--list-formats Print available formats and exit
|
|
255
|
+
--dry-run Parse and filter only; print IR summary without generating
|
|
256
|
+
-h, --help Show this message and exit
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Development
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
# Install task runner and sync dependencies
|
|
265
|
+
pip install just uv
|
|
266
|
+
just sync
|
|
267
|
+
|
|
268
|
+
# Run tests
|
|
269
|
+
just test
|
|
270
|
+
|
|
271
|
+
# Run tests with coverage
|
|
272
|
+
just coverage
|
|
273
|
+
|
|
274
|
+
# Build wheel
|
|
275
|
+
just build
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
The test suite covers parsing, filtering, transforms, generation, CLI integration, and end-to-end compilation with LuaBridge3.
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## Coverage
|
|
283
|
+
|
|
284
|
+
[](https://codecov.io/gh/kunitoki/tsujikiri)
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## License
|
|
289
|
+
|
|
290
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=69", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tsujikiri"
|
|
7
|
+
description = "辻斬り Generic C++ Bindings Generator"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.12"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "kunitoki", email = "kunitoki@gmail.com" },
|
|
12
|
+
]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"libclang==16.0.6",
|
|
15
|
+
"pyyaml>=6.0",
|
|
16
|
+
"jinja2>=3.1",
|
|
17
|
+
]
|
|
18
|
+
license = "MIT"
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Topic :: Utilities",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Development Status :: 3 - Alpha",
|
|
23
|
+
"Environment :: Console",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
]
|
|
26
|
+
dynamic = ["version"]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/kunitoki/tsujikiri"
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
tsujikiri = "tsujikiri.__main__:main"
|
|
33
|
+
|
|
34
|
+
[tool.setuptools]
|
|
35
|
+
package-dir = { "" = "src" }
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.packages.find]
|
|
38
|
+
where = ["src"]
|
|
39
|
+
include = ["tsujikiri*"]
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.package-data]
|
|
42
|
+
tsujikiri = ["formats/*.yml"]
|
|
43
|
+
|
|
44
|
+
[tool.setuptools.dynamic]
|
|
45
|
+
version = { attr = "tsujikiri.__version__" }
|
|
46
|
+
|
|
47
|
+
[project.optional-dependencies]
|
|
48
|
+
dev = [
|
|
49
|
+
"pytest>=9.0",
|
|
50
|
+
"pytest-cov>=5.0",
|
|
51
|
+
"cmake>=3.20",
|
|
52
|
+
"zig-bin>=0.15.2",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[tool.pytest.ini_options]
|
|
56
|
+
testpaths = ["tests"]
|
|
57
|
+
addopts = "-v"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|