Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Commit

Permalink
add the library Zlib (just a skeleton)
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Aug 15, 2009
1 parent ebbf856 commit e3dcacd
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/makefiles/root.in
Expand Up @@ -157,6 +157,7 @@ build: \
#IF(has_crypto): library/sha1.pbc \
library/struct.pbc \
library/uuid.pbc \
library/zlib.pbc \
$(GEN_PIR) \
$(GEN_PBC) \
src/yapp/Lua/parser.pm
Expand Down Expand Up @@ -299,6 +300,9 @@ library/struct.pbc: $(LIBPATH)/struct.pir
library/uuid.pbc: $(LIBPATH)/uuid.pir
-$(PARROT) --output=library/uuid.pbc $(LIBPATH)/uuid.pir

library/zlib.pbc: $(LIBPATH)/zlib.pir
-$(PARROT) --output=library/zlib.pbc $(LIBPATH)/zlib.pir

$(LIBPATH)/luabytecode_gen.pir: $(LIBPATH)/luabytecode.rules src/build/translator.pl
$(PERL) src/build/translator.pl $(LIBPATH)/luabytecode.rules \
--output $(LIBPATH)/luabytecode_gen.pir
Expand Down
126 changes: 126 additions & 0 deletions src/lib/zlib.pir
@@ -0,0 +1,126 @@
# Copyright (C) 2009, Parrot Foundation.
# $Id$

=head1 LuaZlib

=head2 Description

LuaZlib is a simple binding to the zlib library (http://www.zlib.net).

Currently, only the compress/uncompress functions have been implemented.

See original on L<http://luaforge.net/projects/luazlib/>

=head3 Functions

=over 4

=cut

.HLL 'lua'
.loadlib 'lua_group'
.namespace [ 'zlib' ]

.sub '__onload' :anon :load
# print "__onload zlib\n"
.const 'Sub' entry = 'luaopen_zlib'
set_hll_global 'luaopen_zlib', entry
.end

.sub 'luaopen_zlib'

# print "luaopen_zlib\n"

.local pmc _lua__GLOBAL
_lua__GLOBAL = get_hll_global '_G'

new $P1, 'LuaString'

.local pmc _zlib
new _zlib, 'LuaTable'
set $P1, 'zlib'
_lua__GLOBAL[$P1] = _zlib

$P2 = split "\n", <<'LIST'
compress
uncompress
gzuncompress
LIST
lua_register($P1, _zlib, $P2)

new $P2, 'LuaString'

set $P2, "Copyright (C) 2009, Parrot Foundation"
set $P1, "_COPYRIGHT"
_zlib[$P1] = $P2

set $P2, "Binding to the zlib library"
set $P1, "_DESCRIPTION"
_zlib[$P1] = $P2

set $P2, "LuaZlib 1.0.0"
set $P1, "_VERSION"
_zlib[$P1] = $P2

.return (_zlib)
.end


=item C<zlib.compress (src)>

=cut

.sub 'compress'
.param pmc src
.param pmc extra :slurpy
.local pmc res
$S1 = lua_checkstring(1, src)

new res, 'LuaString'
set res, $S0
.return (res)
.end


=item C<zlib.uncompress (src)>

=cut

.sub 'uncompress'
.param pmc src
.param pmc extra :slurpy
.local pmc res
$S1 = lua_checkstring(1, src)

new res, 'LuaString'
set res, $S0
.return (res)
.end


=item C<zlib.gzuncompress (src)>

=cut

.sub 'gzuncompress'
.param pmc src
.param pmc extra :slurpy
.local pmc res
$S1 = lua_checkstring(1, src)

new res, 'LuaString'
set res, $S0
.return (res)
.end


=back

=cut


# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:
43 changes: 43 additions & 0 deletions t/zlib.t
@@ -0,0 +1,43 @@
#! perl
# Copyright (C) 2009, Parrot Foundation.
# $Id$

=head1 LuaZlib
=head2 Synopsis
% perl t/zlib.t
=head2 Description
Tests LuaZlib
(implemented in F<languages/lua/src/lib/zlib.pir>).
=cut

use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../../../lib", "$FindBin::Bin";

use Parrot::Test tests => 1;
use Test::More;
use Parrot::Test::Lua;

language_output_is( 'lua', << 'CODE', << 'OUT', 'require zlib' );
require "zlib"
print(type(zlib))
print(zlib._VERSION)
CODE
table
LuaZlib 1.0.0
OUT


# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:

0 comments on commit e3dcacd

Please sign in to comment.