Created
January 6, 2020 16:04
-
-
Save kkraus14/1ad8c5decabfd994633ef7f71dad3bc8 to your computer and use it in GitHub Desktop.
Cython Scoped Enum Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace foo { | |
enum class bar : int { | |
spam, | |
cheese, | |
parrot | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cython: profile=False | |
# distutils: language = c++ | |
# cython: embedsignature = True | |
# cython: language_level = 3 | |
cdef extern from "enum_test.hpp" namespace "foo" nogil: | |
ctypedef enum bar: | |
spam "foo::bar::spam" | |
cheese "foo::bar::cheese" | |
parrot "foo::bar::cheese" | |
cdef void f(bar arg): | |
pass | |
f(bar.spam) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from setuptools import setup, Extension | |
from Cython.Build import cythonize | |
ext = cythonize( | |
[ | |
Extension( | |
'enum_test', | |
sources=['enum_test.pyx'], | |
depends=['enum_test.pyx'], | |
language='c++', | |
extra_compile_args=["-std=c++14"], | |
) | |
] | |
) | |
setup(name='enum_test', | |
ext_modules = ext, | |
zip_safe=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment