SWIG:Ruby重载问题 [英] SWIG: Ruby overloading problems

查看:260
本文介绍了SWIG:Ruby重载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 sinatra Web应用程序和一个我可以在sinatra(红宝石)中需要"的C ++库.使用swig创建的绑定.

I have a sinatra web application and a C++ library that I can 'require' in sinatra (ruby) using bindings created by swig.

我还有第二个非常相似的库,其中的函数名与第一个相似.当我都需要它们时,首先加载"wins"的对象,即对模棱两可的函数名称的调用始终映射到该库.

I also have a second -very similar- library, in which the function names are partially the same as in the first one. When I require them both, the one that is loaded first 'wins', i.e. calls to the ambiguous function names are always mapped to this library.

原因是'require'只加载尚未加载的内容,而'load'无论如何都重新加载.但是,加载"似乎不适用于.so文件,仅适用于ruby源文件.有帮助吗?

The reason is that 'require' does only load stuff that is not already loaded, whereas 'load' reloads no matter what. However, 'load' seems not to be applicable to .so files, only to ruby source files. Any help?

谢谢

推荐答案

require在$数组中查找以确定模块是否

require looks in $" array to determine if a module should be reloaded. You could try deleting it and requiring. Not sure if this will work for your use case, though, as it seems that the namespace still can be left polluted.

irb(main):001:0> require 'mysql'
=> true
irb(main):002:0> require 'mysql'
=> false
irb(main):003:0> $".delete('mysql.so')
=> "mysql.so"
irb(main):004:0> require 'mysql'
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant MysqlRes
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant MysqlField
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant MysqlError
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant VERSION
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant OPT_CONNECT_TIMEOUT
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant OPT_COMPRESS
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant OPT_NAMED_PIPE
<snip>
=> true 

这篇关于SWIG:Ruby重载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆