ProjectIgnis / scrapiyard

Documentation files for EDOPro's Card Scripting API
GNU Affero General Public License v3.0
4 stars 4 forks source link

Enums as Types #26

Open that-hatter opened 7 months ago

that-hatter commented 7 months ago

Should Enums be usable as Types? e.g.:

parameters:
  - name: loc
    type: [ Location ]
    description: The location to check.

instead of using int and linking to the enum in the description:

parameters:
  - name: loc
    type: [ int ]
    description: The [Location](/api/enums/Location) to check.

This means the signature of Card.IsLocation in the site would be displayed as Card.IsLocation(Card c, Location loc) instead of Card.IsLocation(Card c, int loc).

Pros:

Cons:

feeshstick commented 7 months ago

you can still display it as int. As all enum entries are Integer. imo. they should be used as types.


if you want to go really fancy and intend to confuse users, do something like this

IntExpression<E, Op> ::= E | IntExpression<E, Op> Op E
type: [ IntExpression<Location, Op.Pipe | Op.Plus> ]
that-hatter commented 7 months ago

I don't think it's a good idea to use enums as types then not display them as such. Sort of defeats the purpose.

feeshstick commented 7 months ago

I don't think it's a good idea to use enums as types then not display them as such. Sort of defeats the purpose.

I think it does make sense to display them as types which extend int to avoid your concern of confusion. You could create a type / extend the enum to allow for certain operations like '+' or '|' afaik, there's no enum that can be used in combination of a value defined in another enum. but if there is, it could be defined as new type combining the enums with allowed operations.