Writing C Modules with Inline::C
    // loop over key/value pairs
    for (i = 1; i <= count; i++) {
      value = hv_iternextsv(hv, &key, &len);
     
      // push key and value
      Inline_Stack_Push(sv_2mortal(newSVpvn(key, len)));
      Inline_Stack_Push(sv_mortalcopy(value));
    }
    // done pusing on the stack
    Inline_Stack_Done;
  
    // free hv explicitly
    SvREFCNT_dec((SV *)hv);
       
    // return two SVs for each key in the hash
    Inline_Stack_Return(count * 2);
  }
  // G_SCALAR or G_VOID context   return a reference to the new hash
  Inline_Stack_Reset;
  Inline_Stack_Push(sv_2mortal(newRV_noinc((SV *)hv)));
  Inline_Stack_Done;
  Inline_Stack_Return(1);
}
This function returns a hash reference in scalar context and a list of key value 
pairs in list context:
# scalar context
$type_data = Gnome::MIME::type_data("text/html");
$program = $type_data >{open};
# list context
%type_data = Gnome::MIME::type_data("text/html");
$program = $type_data{open};
The code used is substantially similar to the XS version, and again the difference is 
largely a matter of the Inline::C macros used.
To start, the function begins with a void return type, which works similarly to a 
PPCODE block in XS in that it allows you to handle the return stack explicitly:
void type_data(gchar *type) {
24
249
9






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

web hosting perl

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved