Skip to content

Instantly share code, notes, and snippets.

@kkraus14
Created January 6, 2020 16:04
Show Gist options
  • Save kkraus14/1ad8c5decabfd994633ef7f71dad3bc8 to your computer and use it in GitHub Desktop.
Save kkraus14/1ad8c5decabfd994633ef7f71dad3bc8 to your computer and use it in GitHub Desktop.
Cython Scoped Enum Example
namespace foo {
enum class bar : int {
spam,
cheese,
parrot
};
}
# 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)
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