rune icon indicating copy to clipboard operation
rune copied to clipboard

Function attributes

Open pkolaczk opened this issue 3 years ago • 4 comments

I noticed the parser parses function attributes:

#[load(iterations = 1)]
pub async fn load(db, i) {
}
19 │ #[load(iterations = 1)]
   │ ^^^^^^^^^^^^^^^^^^^^^^^ unrecognized function attribute

Is there a way to define them to make them recognized? I'd like to be able to provide some metadata in the embedded rune script that would be read by the host app.

pkolaczk avatar Nov 07 '21 16:11 pkolaczk

Is there a way to define them to make them recognized?

Not at the moment. There's currently no hook to perform custom processing but all of it has to happen by the compiler.

udoprog avatar Nov 08 '21 10:11 udoprog

I think there's two workflows to this: proc-macro like attributes, and information for the host. I'm wondering whether having a builtin #[meta(tag, key=value, ...)] could be enough for most things in the second group?

And then being some way of both querying for all things with a meta key, and some way of getting a specific function's meta... I guess it'd be a bit awkward in the above example, would need #[meta(load, iterations = 1)]; ... Unless we let LHS and RHS be anything that can be made a (const) value.

tgolsson avatar Nov 08 '21 10:11 tgolsson

+1

jasal82 avatar Mar 03 '23 09:03 jasal82

I'd also find this feature really useful, for the second workflow stated above (information for the host), because it would provide a mechanism by which Rune script could advertise certain functions as being available to the host (provided the host also has a means of iterating them)

jbrd avatar Sep 08 '23 12:09 jbrd