Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何包装C函数并传递其参数?_Ruby_Ruby C Extension - Fatal编程技术网

Ruby 如何包装C函数并传递其参数?

Ruby 如何包装C函数并传递其参数?,ruby,ruby-c-extension,Ruby,Ruby C Extension,我必须使用Ruby来包装这个C函数 Abc_Obj_t * Abc_NtkCreateNodeAnd( Abc_Ntk_t * pNtk, Vec_Ptr_t * vFanins ) { Abc_Obj_t * pNode; int i; assert( Abc_NtkIsLogic(pNtk) || Abc_NtkIsNetlist(pNtk) ); pNode = Abc_NtkCreateNode( pNtk ); for ( i = 0; i < vFan

我必须使用Ruby来包装这个C函数

Abc_Obj_t * Abc_NtkCreateNodeAnd( Abc_Ntk_t * pNtk, Vec_Ptr_t * vFanins )
{
  Abc_Obj_t * pNode;
  int i;
  assert( Abc_NtkIsLogic(pNtk) || Abc_NtkIsNetlist(pNtk) );
  pNode = Abc_NtkCreateNode( pNtk );   
  for ( i = 0; i < vFanins->nSize; i++ )
    Abc_ObjAddFanin( pNode, (Abc_Obj_t *)vFanins->pArray[i] );
    if ( Abc_NtkHasSop(pNtk) )
      pNode->pData = Abc_SopCreateAnd( (Mem_Flex_t *)pNtk->pManFunc, Vec_PtrSize(vFanins), NULL );
    else if ( Abc_NtkHasBdd(pNtk) )
      pNode->pData = Extra_bddCreateAnd( (DdManager *)pNtk->pManFunc, Vec_PtrSize(vFanins) ), Cudd_Ref((DdNode *)pNode->pData); 
    else if ( Abc_NtkHasAig(pNtk) )
      pNode->pData = Hop_CreateAnd( (Hop_Man_t *)pNtk->pManFunc, Vec_PtrSize(vFanins) ); 
    else
      assert( 0 );
  return pNode;
}

我想使用Ruby传递参数并直接调用C函数。有可能吗?

重读你的问题,我不知道你在问什么。您的代码示例看起来不错(前提是您有匹配的
数据\u Wrap\u Struct
等),但不是完整的故事。请您添加您希望如何从Ruby调用您的方法,包括如何构造参数。谢谢你的回复。我已经开始工作了。
static VALUE Abc_NtkCreateNode_And(VALUE self, VALUE netw ,VALUE vfan_ins)
{
  Abc_Ntk_t *netw_str;
  Vec_Ptr_t *vfan_ins_str;
  Data_Get_Struct(netw, Abc_Ntk_t, netw_str);
  Data_Get_Struct(vfan_ins, Abc_Ntk_t, vfan_ins_str );
  Abc_Obj_t *network = Abc_NtkCreateNodeAnd(netw_str,vfan_ins_str);
  return make_Network(network);
}