开发者

SWIG: Ruby overloading problems

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

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.

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

Thank you


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 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜