[Feature request] Decorators / attributes
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 613
- Forks
- 45
- PR merge metrics
- No merged PRs in 30d
Description
It would be nice if we could write something like this:
add_class_tostring = (target, name) ->
target.<tostring> = () => "<class '#{name}'>"
target
#[add_class_tostring]
class FooBar
-- ...
print(FooBar) --> <class 'FooBar'>
It would be equivalent to this:
FooBar = add_class_tostring(class FooBar
-- ...
"FooBar")
The name parameter would be statically determined from the declaration. This has the advantage that a statement like
#[wrap_func]
local x = () -> print("...")
would also have access to the name (x in this case). That would be equal to:
local x = wrap_func((() -> print("...")), "x")
Of course, name would have to be nil if the statement doesn't have a name (like a name-less class).
Additionally, macros should also be invocable as attributes:
macro example = (target, name) ->
target
#[$example]
class FooBar
-- ...
That would be equivalent to:
FooBar = $example(class FooBar
-- ...
FooBar)
Note that, unlike a regular macro, the output of an attribute macro would not need to be wrapped in a do-expression.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining the YueScript compiler and parser entry points; the issue provides no file or test names. Compare the requested decorator and attribute-macro examples with existing class, function, and macro handling. Done means the syntax, name binding, macro invocation, and generated Lua behavior are implemented and covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100