Skip to content

Using an enum custom type to declare string constants#4

Draft
jbarrett wants to merge 1 commit intoTamarou:pufrom
jbarrett:keyboard
Draft

Using an enum custom type to declare string constants#4
jbarrett wants to merge 1 commit intoTamarou:pufrom
jbarrett:keyboard

Conversation

@jbarrett
Copy link
Copy Markdown
Contributor

@jbarrett jbarrett commented Mar 23, 2025

This is not yet working - the enum constructor expects the occasional aligning value, then a list of strings which it increments the value for. I tried coercing all the values to arrayrefs with pair, but the constructor is so-far unhappy with this.

It should at least show off how this should work. The parameter to your FFI bound function should now be a string, e.g. 'KEY_A', and functions can also be coerced into returning string constants - see return type for GetKeyPressed.

It's not a radical departure API-wise - rlt-01.pl should reflect the required changes from the end-user POV.

edit The main advantage of this is that you don't have to worry about importing constants into your namespace.

@perigrin perigrin marked this pull request as draft May 8, 2025 03:13
@perigrin
Copy link
Copy Markdown
Member

perigrin commented May 8, 2025

I've converted this to a draft so I don't forget that it's not ready to go in yet. I'll have a look sometime between now and TPRC and see what I can do with it.

This is not yet working - the enum constructor expects the occasional
aligning value, then a list of strings which it increments the value
for. I tried coercing all the values to arrayrefs with pair, but the
constructor is unhappy with this.

It should at least show off how this *should* work. The parameter to
your FFI bound function should now be a string, e.g. 'KEY_A', and
functions can also be coerced into returning string constants - see
return type for `GetKeyPressed`.

It's not a radical departure API-wise - rlt-01.pl should reflect the
required changes
@jbarrett
Copy link
Copy Markdown
Contributor Author

jbarrett commented Mar 9, 2026

Just revisiting this, with an eye to getting it working ... but looking again, I don't think this change is a good idea.

The specific "not working" problem I had was GetKeyPressed() returning a value which wasn't defined in the type. This crashes. Any function using this type always has to return something look-uppable in the enum, if this makes sense.

I don't think there's a way to do this robustly. OK to close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants