dev-resources.site
for different kinds of informations.
How to use zlib (a C library) from Perl with SPVM
Published at
2/22/2024
Categories
spvm
perl
zlib
c
Author
yukikimoto
Author
10 person written this
yukikimoto
open
How to use zlib (a C library) from Perl with SPVM.
See an example to bind zlib to SPVM
SPVM provides a way to bind C language libraries and call them from Perl.
When binding C libraries to Perl, you typically write XS, but SPVM offers an alternative approach.
MyZlib.spvm
class MyZlib {
native static method test : void ($ouf_file : string);
}
MyZlib.c
#include "spvm_native.h"
#include<stdio.h>
#include "zlib.h"
static const char* FILE_NAME = "MyZlib.c";
int32_t SPVM__MyZlib__test(SPVM_ENV* env, SPVM_VALUE* stack) {
void* obj_out_file = stack[0].oval;
if (!obj_out_file){
return env->die(env, stack, "$ouf_file must be defined.", __func__, FILE_NAME, __LINE__);
}
const char* out_file = env->get_chars(env, stack, obj_out_file);
char buf[]="0123456789abcdefghijklmnopqrstuvwxyz\n";
int cnt = 0;
gzFile zp;
zp = gzopen(out_file, "w9");
if(zp == NULL){
return env->die(env, stack, "gzopen failed.", "MyZlib.c", __func__, FILE_NAME, __LINE__);
}
for(cnt = 0; cnt < 100; cnt++){
gzputs(zp, buf);
}
gzclose(zp);
return 0;
}
MyZlib.config
use strict;
use warnings;
use SPVM::Builder::Config;
my $config = SPVM::Builder::Config->new_gnu99(file => __FILE__);
$config->add_lib('z');
$config;
zlib.pl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/lib";
use SPVM 'MyZlib';
my $out_file = "$ENV{HOME}/tmp/output.gz";
SPVM::MyZlib->test($out_file);
A compressed file "output.gz" will be output.
spvm Article's
30 articles in total
How to create Mac GUI applications in SPVM?
read article
How to create a parallel echo server using goroutines in SPVM?
read article
How to generate an executable file for an AI program using SPVM ?
read article
SPVM::R - A Port of The R Language Features.
read article
SPVM::Resource::Eigen released
read article
SPVM Documentation
read article
How to use OpenMP from Perl with SPVM.
read article
How to use zlib (a C library) from Perl with SPVM
currently reading
SPVM::Digest::MD5 - MD5
read article
SPVM::MIME::Base64 - Base64 Encoding/Decoding
read article
SPVM::MIME::QuotedPrint - Quoted-Printable encoding/decoding
read article
SPVM::Math - Mathematical Functions
read article
SPVM
read article
SPVM::Sys now supports symbolic links on Windows, adds Perl-compatible API.
read article
SPVM now supports object-oriented programming in Perl
read article
First release of SPVM::Resource::RE2 Resourcing the regular expression library Google RE2
read article
First release of SPVM::File::Temp and SPVM::File::Find
read article
SPVM::File::Path and SPVM::File::Glob are newly released.
read article
First release of SPVM::File::Copy and SPVM::FindBin
read article
First release of SPVM::File::Spec - complex regular expressions, file tests, SPVM::Cwd, inheritance
read article
SPVM::File::Basename is released. This is the first module of SPVM using regular expressions.
read article
SPVM improved Exchange API at v0.9684. Welcome to this easy world of type conversion!
read article
SPVM supported self Compiler in 0.9683.
read article
SPVM 0.9680 is released
read article
SPVM 0.9677 is released
read article
SPVM 0.9676 is released
read article
SPVM 0.9672 is released
read article
SPVM 0.9670 is released
read article
SPVM 0.9669 is released
read article
SPVM 0.9668 is released
read article
Featured ones: