Hypercosm / HIDL

Hypercosm Interface Description Language
https://hypercosm.dev/HIDL
0 stars 0 forks source link

`flags` type #7

Closed aDotInTheVoid closed 2 years ago

aDotInTheVoid commented 2 years ago

Roughly coresponds to a bitfield

Current enums are like

const (
   Var1 = iota
   Var2
   Var3
   )

We also want something

const (
  Var1 = 1 << ioto
  Var2
  Var3
  )

This should look like

  flags EntityProps {
    HasColision= 1 << 0
    HasGravity = 1 << 1
}

Unlike enums, flags must set all fields. The syntax for a field value is TDB

aDotInTheVoid commented 2 years ago

Another way to think about it:

both enums and flags are sets of labels and a coresponding unique number

For an enum, a valid value is exactly one of the numbers defined

For a flag, a valid value only has 1 in a position where at least one of the numbers that make up the flag has a 1.

Additionaly, enums have a huristic to create the values. flags dont