Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for defining Dynamic Constants #92

Closed
tabularelf opened this issue Sep 16, 2023 · 0 comments · Fixed by #93
Closed

Add support for defining Dynamic Constants #92

tabularelf opened this issue Sep 16, 2023 · 0 comments · Fixed by #93
Assignees
Labels
enhancement New feature or request

Comments

@tabularelf
Copy link
Contributor

What is your feature request?

Currently there's no way to to define a constant like it were a constant, but have it at like a function. This ideally just needs to be a single getter with no way of passing in arguments (that's what functions are for!)
In my own game, I'm currently exposing constants like

Catspeak.interface.exposeFunction("fps", function() {return fps;});

And in Catspeak I have to do

-- fps()
print(fps);
-- or the shorthand :
print(:fps);

I'm personally not a fan of this approach.

Please describe in detail how you expect this new feature to behave.

If we were to have Catspeak.interface.exposeDynamicConstant(name, function), we could then do

Catspeak.interface.exposeDynamicConstant("fps", function() {return fps;});

Where Catspeak.interface.exposeDynamicConstant is similar to Catspeak.interface.exposeFunction, except that it either attaches isDynamic to the method in some way (maybe via constructor so no one can fiddle with the variable directly) or via an alternative database. And then in Catspeak it's just

print(fps);

This ends up translating as if we were doing fps() within our code, without having to explicitly call it.
If #89 gets added, this could be instead be a toggle for allowing dynamic constants.

@tabularelf tabularelf added the enhancement New feature or request label Sep 16, 2023
@katsaii katsaii linked a pull request Sep 17, 2023 that will close this issue
@katsaii katsaii closed this as completed Sep 17, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants