In order to create a BigDecimal from a C string in a Ruby extension, I'm doing this:
为了在Ruby扩展中从C字符串创建BigDecimal,我这样做:
rb_funcall(rb_path2class("BigDecimal"), rb_intern("new"), 1, rb_str_new("0.0777", 6));
// => BigDecimal.new("0.0777")
Is there a shorter way to do this?
有更短的方法吗?
Also, stupid question, but is there an 'official' documentation for the C API (ruby 1.9.3), or does it just come down to reading the headers?
同样,这是个愚蠢的问题,但是对于C API (ruby 1.9.3)是否有一个“官方”文档,或者仅仅是为了阅读标题?
2 个解决方案
#1
1
Unfortunately, the initialize
function, and pretty much the entire BigDecimal
C API, is declared as static and is thus not exposed.
不幸的是,初始化函数和几乎整个BigDecimal C API都被声明为静态的,因此不会被公开。
The best way to learn about the C implementation of Ruby, and its API, is to browse the source, especially the ext
directory. There is also the README.EXT file, which describes the general API.
了解Ruby及其API的C实现的最佳方式是浏览源代码,特别是ext目录。还有自述文件。描述通用API的EXT文件。
#2
2
I do not get what the problem really is. You do like it shorter? Write a wrapper.
我不知道真正的问题是什么。你喜欢短一点吗?编写一个包装器。
rb_object new_big_decimal(char * from) {
rb_funcall(rb_path2class("BigDecimal"), rb_intern("new"), 1, rb_str_new(from, 6));
}
Of course it may not be rb_object but something else, but what is the problem?
当然,它可能不是rb_object而是其他东西,但是问题是什么呢?
#1
1
Unfortunately, the initialize
function, and pretty much the entire BigDecimal
C API, is declared as static and is thus not exposed.
不幸的是,初始化函数和几乎整个BigDecimal C API都被声明为静态的,因此不会被公开。
The best way to learn about the C implementation of Ruby, and its API, is to browse the source, especially the ext
directory. There is also the README.EXT file, which describes the general API.
了解Ruby及其API的C实现的最佳方式是浏览源代码,特别是ext目录。还有自述文件。描述通用API的EXT文件。
#2
2
I do not get what the problem really is. You do like it shorter? Write a wrapper.
我不知道真正的问题是什么。你喜欢短一点吗?编写一个包装器。
rb_object new_big_decimal(char * from) {
rb_funcall(rb_path2class("BigDecimal"), rb_intern("new"), 1, rb_str_new(from, 6));
}
Of course it may not be rb_object but something else, but what is the problem?
当然,它可能不是rb_object而是其他东西,但是问题是什么呢?