Author: fperrad Date: Mon Feb 26 02:43:45 2007 New Revision: 17189 Modified: trunk/languages/lua/lib/luapackage.pir trunk/languages/lua/t/package.t
Log: [Lua] - implement require (step 2) - and add tests Modified: trunk/languages/lua/lib/luapackage.pir ============================================================================== --- trunk/languages/lua/lib/luapackage.pir (original) +++ trunk/languages/lua/lib/luapackage.pir Mon Feb 26 02:43:45 2007 @@ -1,4 +1,4 @@ -# Copyright (C) 2006, The Perl Foundation. +# Copyright (C) 2006-2007, The Perl Foundation. # $Id$ =head1 NAME @@ -79,7 +79,7 @@ _package[$P1] = $P0 new $P0, .LuaTable - set $P1, 'preloaded' + set $P1, 'preload' _package[$P1] = $P0 .end @@ -128,7 +128,7 @@ $S0 .= name $S0 .= "' from file '" $S0 .= filename - $S0 .= ":\n\t" + $S0 .= "':\n\t" $S0 .= msg error($S0) .end @@ -299,9 +299,6 @@ When you require a module C<modname> and C<package.loaded[modname]> is not false, C<require> simply returns the value stored there. -NOT YET IMPLEMENTED. - - =item C<package.loadlib (libname, funcname)> Dynamically links the host program with the C library C<libname>. Inside @@ -343,22 +340,19 @@ the search for a Lua loader for module C<foo> will try to load the files C<./foo.lua>, C<./foo.lc>, and C</usr/local/foo/init.lua>, in that order. -NOT YET IMPLEMENTED. - +STILL INCOMPLETE. =item C<package.pirpath> The path used by C<require> to search for a PIR loader. -NOT YET IMPLEMENTED. - +STILL INCOMPLETE. =item C<package.preload> A table to store loaders for specific modules (see C<require>). -NOT YET IMPLEMENTED. - +STILL INCOMPLETE. =item C<package.seeall (module)> @@ -378,6 +372,7 @@ =head1 AUTHORS +Francois Perrad =cut Modified: trunk/languages/lua/t/package.t ============================================================================== --- trunk/languages/lua/t/package.t (original) +++ trunk/languages/lua/t/package.t Mon Feb 26 02:43:45 2007 @@ -25,10 +25,10 @@ use FindBin; use lib "$FindBin::Bin"; -use Parrot::Test tests => 4; +use Parrot::Test tests => 7; use Test::More; -language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'require' ); +language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'function require' ); local m = require "io" m.write("hello world\n") CODE @@ -73,7 +73,7 @@ CODE close $X; -language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'require' ); +language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'function require' ); m = require "complex" assert(m == complex) print(complex.i.r, complex.i.i) @@ -81,12 +81,23 @@ 0 1 OUTPUT -language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'require (no module)' ); +language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function require (no module)' ); require "no_module" CODE /module 'no_module' not found:\n/ OUTPUT +unlink('../foo.lua') if ( -f '../foo.lua' ); +open $X, '>', '../foo.lua'; +print {$X} '?syntax error?'; +close $X; + +language_output_like( 'lua', << 'CODE', << 'OUTPUT', 'function require (syntax error)'); +require "foo" +CODE +/error loading module 'foo' from file '.*foo.lua':\n/ +OUTPUT + language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'table package.loaded' ); t = {} for k in pairs(package.loaded) do @@ -108,6 +119,20 @@ table OUTPUT +language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'table package.path' ); +print(type(package.path)) +CODE +string +OUTPUT + +language_output_is( 'lua', << 'CODE', << 'OUTPUT', 'table package.preload' ); +print(type(package.preload)) +print(# package.preload) +CODE +table +0 +OUTPUT + # Local Variables: # mode: cperl # cperl-indent-level: 4