Skip to content

Instantly share code, notes, and snippets.

View Xliff's full-sized avatar
🏠
Working from home

Xliff Xliff

🏠
Working from home
View GitHub Profile

If you are trying to figure out a safe way to port C-code resembling this to perl6:

char **ptr=vc.user_comments;
while(*ptr){
    fprintf(stderr,"%s\n",*ptr);
    ++ptr;
}

SOLVED -- see below

Here is the Perl code in question:

# basic init
my $myhtml = myhtml_create();
myhtml_init($myhtml, 0, 1, 0);

# init tree

SOLVED -- See below.

OK. This boggles!

my @buffer;
# Returns float **
my $prebuff_ptr = vorbis_analysis_buffer($vd, READ);
my @pre_buffer := nativecast(CArray[CArray[num32]], $prebuff_ptr);

SOLVED -- See below.

I have the following code, in C:

buffer[0][i]=((readbuffer[i*4+1]<<8)|
    (0x00ff&(int)readbuffer[i*4]))/32768.f;
buffer[1][i]=((readbuffer[i*4+3]<<8)|
    (0x00ff&(int)readbuffer[i*4+2]))/32768.f;

OK, so I have the following test script:

use v6.c;
use Test;

#use base qw(ParentClass);
#
#sub new {
#    my $class = shift;

So I have the following routine:

method getAttributeNode($a) {
    my $ret = domGetAttrNode(self, $a);
    #my $retVal = $ret.clone;
    #xmlFree($ret);

    # cw: Returns CStruct allocated from libxml2!
    return $ret;

So I have this shared lib code:

/* testNodeSet.c */
#include <stdlib.h>

struct nodeStruct {
        int foo;
        int bar;
        int baz;

All the code needed to extract and XMLize my Winamp "History" media library with the forthcoming Winamp::ML module.

perl6 -Ilib -e 'use Winamp::ML; use Inline::Perl5; my $ml = Winamp::ML.new("t/recent"); my $p5 = Inline::Perl5.new; 
$p5.use("XML::Hash::XS"); my @r = $ml.get_records(:simple); @r = @r.map({ $_<lastplay> = $_<lastplay>.posix; $_; }); 
my $n1 = now; say "Retrieval: {$n1 - INIT now}"; say $p5.call("hash2xml", $_) for @r; say "Serialization: {now - $n1}"'

It's not perfect, but it works for me.

Stage start      :   0.000
Stage parse      :      9483 RMD: Loading settings CORE
     9483 RMD: Setting up default paths: . blib
     9483 RMD: going to load Perl6::BOOTSTRAP
     9483 RMD: Settings CORE loaded
  36  9483 RMD: Attempting 'Test' as a pragma
   6  9483 RMD:   'Test' is not a valid pragma
   1  9483 RMD: Attempting to load 'Test'
   1  9483 RMD:   Late loading 'Test'
use v6.c;
use nqp;
use NativeCall;
class A is repr('CStruct') {
has int32 $.one;
has int32 $.two;
has int32 $.three;