armory3d / armory3d/armory

Macro trait/prop parser

Open
#2,472 7 comments 2 reactions 0 assignees View on GitHub
feature request
Dominant language
C++
Stars
3.3k
Forks
353
Avg merge
3d 16h
Merged PRs (30d)
1

Description

Following the discussion at #2291 i've created a [haxe macro](https://github.com/tong/armory/blob/macro-trait-parser/Sources/armory/macro/Build.hx) which writes trait information json format to stdout.

The idea is to replace the current (python) @prop parser, which would have several advantages:
- No parsing errors (implied we trust the haxe compiler)
- Allow multiple package paths to hold Trait sub classes
- Ignore commented out @prop (#2291)
- Multiple trait sub classes in single module
- Metadata usage
- Allow to get trait information without opening blender
- Show Trait class and @prop documentation in blender ui
- …

Some meta data usage ideas:
- `@prop({min:0,max:10})` Allowed value range for `Int`, `Float` and `String`(min/max length)
- `@prop({internal:true})` To hide the property in blender ui (access from code only)
- `@prop({required:true})` Show error in blender ui if no value has been set
- …

Downsides of this approach are that it only works for already built projects and the mandatory usage of the haxe build server to have bearable build times. Fully cached, a request to this macro takes about 100-200ms.

Any thoughts welcome!

---

Example:

```haxe
package arm;

import iron.math.Vec4;

/**
Here is nothing
**/
class MyTrait extends iron.Trait {

/**
My value
**/
@prop
var myInt:Int = 11;

@prop var myFloat:Float = 345.43535;

@prop var myString = "Armory!";

@prop var myObj:iron.object.Object;

@prop var myVec2 = new iron.math.Vec2(1, 3);
@prop var myVec3 = new iron.math.Vec3();
@prop var myVec4:Vec4;

//@prop var myIvalidType : armory.data.Config;

//@prop function update() {}
}
```
Call the macro:
```sh
haxe --no-output --cwd build_test/debug project-krom.hxml --macro 'armory.macro.Build.fetch_traits(true)'
```

Outputs:
```json
[
{
"name": "MyTrait",
"doc": "Here is nothing",
"pack": [
"arm"
],
"props": [
{
"name": "myInt",
"doc": "My value",
"type": "Int",
"value": 11
},
{
"name": "myFloat",
"type": "Float",
"value": "345.43535"
},
{
"name": "myString",
"type": "String",
"value": "Armory!"
},
{
"name": "myObj",
"type": "Object"
},
{
"name": "myVec2",
"type": "Vec2",
"value": [
1,
3
]
},
{
"name": "myVec3",
"type": "Vec3",
"value": []
},
{
"name": "myVec4",
"type": "Vec4"
}
]
}
]
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Read the discussion at #2291 and the linked Sources/armory/macro/Build.hx, then run the shown haxe macro command to inspect its JSON output. The issue has no settled implementation scope; done would require an agreed replacement for the current Python @prop parser and a defined integration path.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.