用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()
使用Inline::C#c_singleton
而不是Inline::C#c
:
require 'inline' class TestFunc inline do |builder| builder.c_singleton ' int testfunc() { return 0; }' end end TestFunc.testfunc() # => 0
根据文件:
c_singleton :与c相同,但添加了一个类函数。