Skip to content

Instantly share code, notes, and snippets.

@SimonDanisch
Created June 11, 2014 13:30
Show Gist options
  • Save SimonDanisch/a675efcef9e3a04a8f50 to your computer and use it in GitHub Desktop.
Save SimonDanisch/a675efcef9e3a04a8f50 to your computer and use it in GitHub Desktop.
abstract Enum
macro GenEnums(list)
const result = {}
enumlist = Dict{Symbol, Dict{Int, Symbol}}()
tmp = list.args[2].args
tmp2 = tmp[2].args
enumdict1 = Dict{Int, Symbol}()
for elem in tmp2
if elem.head == :const
enumdict1[elem.args[1].args[2]] = elem.args[1].args[1]
end
end
enumlist[tmp[1]] = enumdict1
push!(result, quote
immutable $(tmp[1]) <: Enum
number::Int
name::Symbol
enumdict = $enumdict1
function $(tmp[1])(number::Int)
if !haskey(enumdict, number)
error("x is not a GLenum")
end
new(number, enumdict[number])
end
end
end)
esc(Expr(:block, result..., tmp2...))
end
@GenEnums begin
KEYS = begin
const KEY_SPACE = 32
const KEY_APOSTROPHE = 39 # '
const KEY_COMMA = 44 # ,
const KEY_MINUS = 45 # -
const KEY_PERIOD = 46 # .
const KEY_SLASH = 47 # /
const KEY_0 = 48
const KEY_1 = 49
const KEY_2 = 50
const KEY_3 = 51
const KEY_4 = 52
end
end
println(KEYS(32))
println(KEY_1)
#partof(KEY, x)
#KEY_SPACE == x
#println(GLEnum(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment