Ruby-FFI 在包装以大写字母开头的函数时生成常量?
我正在尝试用 Ruby-FFI 包装 C 库。但是,库中的函数名称以大写字母开头。因此,看起来 ffi 似乎正在尝试生成常量,当您尝试在运行时从 Ruby 访问它们时,您会收到一条错误消息,指出
NameError: uninitialized constant (name of function)
是否有一种方法可以为函数名称添加别名,以便在 Ruby 中您可以将它们作为方法访问:名称应该是小写的吗?
I am trying to wrap a C library with Ruby-FFI. However, the function names from the library start with capital letters. As a result, it seems as if ffi is trying to generate constants, and when you try access them at runtime from Ruby, you get an error saying
NameError: uninitialized constant (name of function)
Is there a way to alias function names so that in ruby you can access them as methods with lower case names as they ought to be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
等等,这里似乎显示了一个示例: https://github.com/ffi/ ffi/wiki/Windows-Examples
他们在这里所做的如下:
因此,attach_function 似乎允许您将别名作为第一个参数传递,后跟常用参数。尝试过这个,似乎有效。
Wait, it seems that an example is shown here: https://github.com/ffi/ffi/wiki/Windows-Examples
What they do here is the following:
So it seems that attach_function allows you to pass the alias as the first parameter, followed by the usual parameters. Tried this and it seems it works.