Tag: 内联

用RubyInline声明类方法

我的test_func.rb有以下几行代码 require ‘inline’ class TestFunc inline do |builder| builder.c ‘ int testfunc() { return 0; }’ end end 我只能从一个对象而不是类调用该函数。 我可以称之为, obj = TestFunc.new obj.testfunc() 但是我应该怎么声明我可以打电话给, TestFunc.testfunc()

Ruby内联 – 返回双值

require ‘inline’ class InlineTest inline(:C) do |builder| builder.c ‘ VALUE arr_distance(VALUE arr1, VALUE arr2){ long arr1_len = RARRAY_LEN(arr1); long arr2_len = RARRAY_LEN(arr2); if(arr1_len == 0 || arr2_len == 0){ return 0.0; } else{ long i, j; int count = 0; VALUE *c_arr1 = RARRAY_PTR(arr1); VALUE *c_arr2 = RARRAY_PTR(arr2); for(i = 0; i < arr1_len; i++){ […]