Skip to content

Commit cf9fdbf

Browse files
committed
fix: move tools to separate folders
1 parent 5b3ee8d commit cf9fdbf

File tree

8 files changed

+218
-0
lines changed

8 files changed

+218
-0
lines changed

tools/generator/README.md

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
# Plugify C++ Header Generator
2+
3+
A Python tool that automatically generates C++ header files with type-safe bindings for Plugify plugins from JSON manifest files.
4+
5+
## Overview
6+
7+
This generator reads `.pplugin` JSON manifest files and produces corresponding C++ header files (`.hpp`) that provide:
8+
- Type-safe function wrappers
9+
- Enum definitions
10+
- Delegate (function pointer) type definitions
11+
- Automatic method pointer resolution
12+
- Doxygen-compatible documentation comments
13+
14+
## Requirements
15+
16+
- Python 3.10 or higher
17+
- Input: `.pplugin` JSON manifest file
18+
- Output: A directory for generated headers
19+
20+
## Installation
21+
22+
No installation required. Simply download the `generator.py` script and ensure it's executable:
23+
24+
```bash
25+
chmod +x generator.py
26+
```
27+
28+
## Usage
29+
30+
### Basic Syntax
31+
32+
```bash
33+
python3 generator.py <manifest_path> <output_directory> [--override]
34+
```
35+
36+
### Arguments
37+
38+
| Argument | Required | Description |
39+
|----------|----------|-------------|
40+
| `manifest_path` | Yes | Path to the `.pplugin` JSON manifest file |
41+
| `output_directory` | Yes | Directory where the generated header will be saved |
42+
| `--override` | No | Overwrite existing files (otherwise, script exits if file exists) |
43+
44+
### Examples
45+
46+
**Generate a header file:**
47+
```bash
48+
python3 generator.py my_plugin.pplugin ./output
49+
```
50+
51+
**Override existing files:**
52+
```bash
53+
python3 generator.py my_plugin.pplugin ./output --override
54+
```
55+
56+
**Result:**
57+
```
58+
Header generated at: ./output/pps/my_plugin.hpp
59+
```
60+
61+
## Input Format
62+
63+
The script expects a JSON manifest file with the following structure:
64+
65+
```json
66+
{
67+
"name": "my_plugin",
68+
"methods": [
69+
{
70+
"name": "MyFunction",
71+
"description": "Does something useful",
72+
"retType": {
73+
"type": "int32",
74+
"description": "Return value description"
75+
},
76+
"paramTypes": [
77+
{
78+
"name": "value",
79+
"type": "float",
80+
"description": "Parameter description"
81+
}
82+
]
83+
}
84+
]
85+
}
86+
```
87+
88+
### Supported Types
89+
90+
**Basic types:** `void`, `bool`, `char8`, `char16`, `int8`, `int16`, `int32`, `int64`, `uint8`, `uint16`, `uint32`, `uint64`, `ptr64`, `float`, `double`, `string`, `any`, `function`
91+
92+
**Vector types:** `vec2`, `vec3`, `vec4`, `mat4x4`
93+
94+
**Array types:** Add `[]` suffix (e.g., `int32[]`, `string[]`, `vec2[]`)
95+
96+
**Special features:**
97+
- Enums with custom types
98+
- Delegates (function pointers)
99+
- Reference parameters (`"ref": true`)
100+
- Default parameter values
101+
102+
## Output Format
103+
104+
The generated header includes:
105+
106+
```cpp
107+
#pragma once
108+
109+
#include <plg/plugin.hpp>
110+
#include <plg/any.hpp>
111+
#include <cstdint>
112+
113+
namespace my_plugin {
114+
// Enums
115+
enum class MyEnum : int32_t { /* ... */ };
116+
117+
// Delegates
118+
using MyCallback = void (*)(int32_t);
119+
120+
// Function wrappers
121+
/**
122+
* @brief Does something useful
123+
* @function MyFunction
124+
* @param value (float): Parameter description
125+
* @return int32: Return value description
126+
*/
127+
inline int32_t MyFunction(float value) {
128+
using MyFunctionFn = int32_t (*)(float);
129+
static MyFunctionFn __func = nullptr;
130+
if (__func == nullptr)
131+
plg::GetMethodPtr2("my_plugin.MyFunction",
132+
reinterpret_cast<void**>(&__func));
133+
return __func(value);
134+
}
135+
}
136+
```
137+
138+
## Features
139+
140+
### Automatic Type Conversion
141+
- Converts JSON types to appropriate C++ types
142+
- Handles value types, references, and return types differently
143+
- Supports vectors with `plg::vector<T>`
144+
145+
### Name Sanitization
146+
- Automatically appends `_` to C++ reserved keywords
147+
- Prevents naming conflicts
148+
149+
### Documentation Generation
150+
- Creates Doxygen-style comments from JSON descriptions
151+
- Documents parameters and return types
152+
153+
### Duplicate Prevention
154+
- Tracks generated enums and delegates
155+
- Avoids duplicate definitions
156+
157+
## Error Handling
158+
159+
The script will exit with an error if:
160+
- Manifest file doesn't exist
161+
- Output directory doesn't exist
162+
- Output file already exists (without `--override`)
163+
- JSON parsing fails
164+
- Unsupported type is encountered
165+
166+
## Integration
167+
168+
Include the generated header in your C++ project:
169+
170+
```cpp
171+
#include "pps/my_plugin.hpp"
172+
173+
int main() {
174+
float result = my_plugin::MyFunction(3.14f);
175+
return 0;
176+
}
177+
```
178+
179+
## Troubleshooting
180+
181+
**"Manifest file does not exist"**
182+
- Check the path to your `.pplugin` file
183+
184+
**"Output directory does not exist"**
185+
- Create the output directory first: `mkdir -p output`
186+
187+
**"Output file already exists"**
188+
- Use `--override` flag or delete existing file
189+
190+
**"Unsupported type"**
191+
- Check that all types in your manifest are in the supported types list
192+
193+
## Download Generator Script
194+
195+
The generator script is available at:
196+
- **GitHub Repository:** https://github.com/untrustedmodders/plugify-module-cpp
197+
- **Direct Link:** https://raw.githubusercontent.com/untrustedmodders/plugify-module-cpp/main/generator/generator.py
198+
199+
### Quick Download
200+
201+
```bash
202+
# Using wget
203+
wget https://raw.githubusercontent.com/untrustedmodders/plugify-module-cpp/main/generator/generator.py
204+
205+
# Using curl
206+
curl -O https://raw.githubusercontent.com/untrustedmodders/plugify-module-cpp/main/generator/generator.py
207+
208+
# Make it executable
209+
chmod +x generator.py
210+
```
211+
212+
## License
213+
214+
[Add license information]
215+
216+
## Contributing
217+
218+
For issues, feature requests, or contributions, please visit the GitHub repository.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)