rokucommunity / brighterscript

A superset of Roku's BrightScript language
MIT License
152 stars 47 forks source link

Suggestion: expose/export component functions #232

Open jeanbenitez opened 3 years ago

jeanbenitez commented 3 years ago

Hi all! I'm relatively new reading and learning about Brighterscript language, and I like a lot this idea!

One thing I found when exposing functions is that sometimes I forgot to declare the <function> tag in the XML file, I know there is a runtime warning when you try to call a non-existent function in a node using callFunc, but I consider that could be a great idea to unify this in Brighterscript code, I think in something like this:

expose function sayHello (name as string) as string
    return "Hello, my name is " + string
end function

Reserved word can be expose or export, I like expose, but maybe someone has a better argument for using export.

That's it!

elsassph commented 3 years ago

There is a nice opportunity to allow plugins taking care of that, without necessarily adding it to the compiler formally. The idea would be to allow declaring metadata like

@expose
function say hello()
end function

Which would make it rather trivial to write a plugin for what you're describing.

georgejecook commented 3 years ago

I would love this. I use annotations all the time in my code (using the plugins), so this would be very welcomed

TwitchBronBron commented 3 years ago

I definitely like this idea! I'm torn on whether to include it in BrighterScript or push it off to a plugin. I'll need to give this some more thought. I do like @elsassph 's idea though, if we did this, it should probably be an annotation (which don't exist yet...but might soon)

elsassph commented 3 years ago

This indeed is borderline as a language feature - it needs to be thoroughly spec'd with all the edge cases. Implementing as a plugin will allow to experiment on it.

chrisdp commented 3 years ago

@TwitchBronBron Based on more recent chats does this seem like it more falls under the realm of component support? Or are we thinking this is something talk we would still look at doing for following the old way to make components.