2012-02-18 7 views
2

のC部に使用されるCythonコードで列挙Iが定義されているとcythonヘッダーファイルapi.pxdenumcdefctypedefを回転する動作になる場合、私もチェックして定義コード

ctypedef enum InstructionType: 
    default = 0 
    end_if = 1 
    end_loop = 2 
    backward_jump_here = 4 

(それしなかった)。

そして、私はいくつかのクラスFO __cinit__メソッドでこの列挙からの値を使用したい:

from api cimport Instruction, CLinVM, InstructionType 

# (...) some other classes 

cdef class EndIf(Noop): 
    def __cinit__(self): 
     self.type = InstructionType.end_if 

そして、私はコンパイルエラーを取得:ように列挙型を定義し、使用する

self.type = InstructionType.end_if 
          ^
------------------------------------------------------------ 
/home/(...)/instructions.pyx:149:35: 'InstructionType' is not a constant, 

任意の方法を?

答えて

2

C、C++、Cythonのいずれの型名でも列挙型定数にアクセスすることはできません。そのためにラッパー.pxdを作成する必要があります。

+0

この定数には、 'end_if'という名前でアクセスできます。ヒントありがとう! –