Files
BusyRabbit/Tools/README.md
2025-09-24 13:57:17 +08:00

126 lines
3.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# UE头文件解析工具
这是一个用于扫描UE头文件并生成slua插件的emmy-lua注解的Python工具。
## 功能特性
- 自动扫描指定目录下的所有UE头文件(.h)
- 解析UCLASS、USTRUCT、UENUM、UFUNCTION、UPROPERTY等宏
- 生成符合emmy-lua标准的类型注解文件(.d.lua)
- 支持C++类型到Lua类型的自动转换
- 支持递归扫描子目录
## 支持的UE宏
- **UCLASS**: 解析类定义,包括继承关系
- **USTRUCT**: 解析结构体定义和属性
- **UENUM**: 解析枚举定义和值
- **UFUNCTION**: 解析函数声明,包括参数和返回值
- **UPROPERTY**: 解析属性声明
- **DECLARE_DYNAMIC_DELEGATE**: 解析委托声明
## 安装和使用
### 前置要求
- Python 3.6+
- 无需额外依赖
### 基本用法
```bash
# 扫描Source目录并生成注解文件到Content/Lua/@types目录
python ue_header_parser.py Source/BusyRabbit -o Content/Lua/@types
# 扫描当前目录并生成注解文件到同目录
python ue_header_parser.py .
# 递归扫描整个项目
python ue_header_parser.py Source --recursive -o Content/Lua/@types
```
### 命令行参数
- `directory`: 要扫描的目录路径(必需)
- `-o, --output`: 输出目录路径(可选,默认为源文件同目录)
- `--recursive`: 递归扫描子目录(可选)
## 生成的注解格式
工具会根据UE头文件生成对应的emmy-lua注解
### 类注解示例
```lua
---@class UInventoryComponent : ULuaActorComponent
---@field Capacity integer
---@field InventoryList table<FInventoryGrid>
---@param ItemID integer
---@param Count integer
---@return boolean
function UInventoryComponent:IsCanContain(ItemID, Count) end
```
### 结构体注解示例
```lua
---@class FInventoryGrid
---@field ItemID integer
---@field CurrentCount integer
---@field MaxCount integer
---@field Priority integer
local FInventoryGrid = {}
```
### 枚举注解示例
```lua
---@enum EBusyRoleState
local EBusyRoleState = {
BonfireIdle = 0,
Searching = 1,
Picking = 2,
PickFinished = 3,
BackBonfire = 4
}
```
### 委托注解示例
```lua
---@class FOnInventoryChanged
---@field Call fun(ItemID: integer)
local FOnInventoryChanged = {}
```
## 类型映射
工具会自动将C++类型映射到Lua类型
| C++类型 | Lua类型 |
|---------|---------|
| int32, int64 | integer |
| float, double | number |
| bool | boolean |
| FString, FText, FName | string |
| void | nil |
| TArray, TMap, TSet | table |
| 其他类型 | any |
## 注意事项
1. 工具会跳过没有UE宏的普通头文件
2. 生成的注解文件会保存在`.d.lua`文件中
3. 如果输出目录不存在,工具会自动创建
4. 工具会处理编码问题但建议确保头文件使用UTF-8编码
5. 对于复杂的模板类型,工具会尝试解析内部类型
## 故障排除
如果遇到解析错误,请检查:
- 头文件语法是否正确
- UE宏格式是否符合标准
- 文件编码是否为UTF-8
- 是否有语法错误或缺失的分号
## 贡献
欢迎提交问题和改进建议!