使用 PltScheme FFI 中的 _bitmask
这是 plt-scheme 包装库的一部分:
(define InputMask
(_bitmask '(NoEventMask = #x00000000
KeyPressMask = #x00000001
KeyReleaseMask = #x00000002
...
OwnerGrabButtonMask = #x01000000)
_long))
问题是我无法弄清楚如何访问位掩码(或枚举)中的字段。例如,如何获取 KeyPressMask 值?
This is a part of a plt-scheme wrapper library:
(define InputMask
(_bitmask '(NoEventMask = #x00000000
KeyPressMask = #x00000001
KeyReleaseMask = #x00000002
...
OwnerGrabButtonMask = #x01000000)
_long))
The thing is I cant figure out how to access fields in a bitmask (or enum for that matter). How can I get KeyPressMask value for example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不知道。添加 ctypes 很容易:要创建一个新的 ctype,您需要提供一个现有的 ctype 来构建,以及两个函数——一个将任何内容转换为现有类型,另一个将另一种方式转换。
现在,
_bitmask
类型就是这样做的 - 它构建在_int
上(但在您的情况下,它是在_long
上),并且两个翻译函数将符号列表转换为整数,并将整数转换为符号列表。一旦使用了这样的类型,您就不需要知道KeyPressMask
的值 - 您只需知道可以将'(KeyPressMask)
作为传递InputMask
输入到外部函数,并将其转换为适当的数字;并且您还知道,当您从具有InputMask
输出的函数获取结果值时,它将是可能包含KeyPressMask
的符号列表。最重要的是,在方案方面,您不处理数字——只处理符号列表。如果您确实由于某些不明原因需要访问这些值,那么您可以通过其他方式构建自己的ctype - 使用
make-ctype
(正如我上面概述的那样)应该很容易。You don't. Adding ctypes is easy: to make a new ctype, you need to provide an existing ctype to build on, and two functions -- one to translate whatever to the existing type, and one to translate the other way.
Now, the
_bitmask
type does just that -- it builds on_int
(but in your case, it's on_long
), and the two translation functions translate a list of symbols to an integer, and an integer to a list of symbols. Once such a type is used, you don't need to know the value ofKeyPressMask
-- you just know that you can pass'(KeyPressMask)
as anInputMask
input to the foreign function, and that will be translated to the appropriate number; and you also know that when you get the result value from a function that has anInputMask
output, then it will be a list of symbols that might containKeyPressMask
. The bottom line is that on the Scheme side you don't deal with numbers -- only with symbol lists.If you do need to access these values for some obscure reason, then you can build your own ctype in some other way -- using
make-ctype
(as I outlined above) should be very easy.