Author: fperrad
Date: Thu Jan  5 03:59:11 2006
New Revision: 10904

Modified:
   trunk/languages/lua/lib/luaos.pir
   trunk/languages/lua/t/lib/os.t
Log:
Lua : add function os.remove

Modified: trunk/languages/lua/lib/luaos.pir
==============================================================================
--- trunk/languages/lua/lib/luaos.pir   (original)
+++ trunk/languages/lua/lib/luaos.pir   Thu Jan  5 03:59:11 2006
@@ -210,12 +210,30 @@ L0:
 Deletes the file with the given name. If this function fails, it returns
 B<nil>, plus a string describing the error.
 
-NOT YET IMPLEMENTED.
-
 =cut
 
 .sub _os_remove @ANON
-    not_implemented()
+    .param pmc filename
+    .local pmc ret
+    $S0 = checkstring(filename)
+    new $P0, .OS
+    push_eh _handler
+    $P0."rm"($S0)
+    new ret, .LuaBoolean
+    ret = 1
+    .return (ret)
+_handler:
+    .local pmc nil
+    .local pmc msg
+    .local pmc e
+    .local string s
+    .get_results (e, s)
+    concat $S0, ": "
+    concat $S0, s
+    new nil, .LuaNil
+    new msg, .LuaString
+    msg = $S0
+    .return (nil, msg)
 .end
 
 =item C<os.rename (oldname, newname)>
@@ -223,7 +241,7 @@ NOT YET IMPLEMENTED.
 Renames file named C<oldname> to C<newname>. If this function fails, it
 returns B<nil>, plus a string describing the error.
 
-NOT YET IMPLEMENTED.
+NOT YET IMPLEMENTED.              
 
 =cut
 

Modified: trunk/languages/lua/t/lib/os.t
==============================================================================
--- trunk/languages/lua/t/lib/os.t      (original)
+++ trunk/languages/lua/t/lib/os.t      Thu Jan  5 03:59:11 2006
@@ -18,7 +18,7 @@ Tests Lua Operating System Library

 

 =cut

 

-use Parrot::Test tests => 2;

+use Parrot::Test tests => 5;

 use Test::More;

 

 pir_output_is(<< 'CODE', << 'OUTPUT', "function execute");

@@ -91,4 +91,76 @@ nil

 GETENV_PARROT

 OUTPUT

 

+open X, "> ../file.rm";

+print X "file to remove";

+close X;

+

+pir_output_is(<< 'CODE', << 'OUTPUT', "function remove");

+.namespace [ "Lua" ]

+.HLL "Lua", "lua_group"

+.sub _main

+    load_bytecode "languages/lua/lib/luaos.pbc"

+    .local pmc _G

+    _G = global "_G"

+    .local pmc key1

+    key1 = new .LuaString

+    key1 = "os"

+    .local pmc os

+    os = new .LuaTable

+    os = _G[key1]

+    .local pmc key2

+    key2 = new .LuaString

+    key2 = "remove"

+    .local pmc fct1

+    fct1 = os[key2]

+    .local pmc arg1

+    .local pmc ret1

+    new arg1, .LuaString

+    arg1 = "file.rm"

+    ret1 = fct1(arg1)

+    print ret1

+    print "\n"

+    end

+.end

+CODE

+true

+OUTPUT

+

+ok(!-e "../file.rm", "Test that rm removed the file");

+unlink("../file.rm") if (-e "../file.rm");

+

+pir_output_is(<< 'CODE', << 'OUTPUT', "function remove");

+.namespace [ "Lua" ]

+.HLL "Lua", "lua_group"

+.sub _main

+    load_bytecode "languages/lua/lib/luaos.pbc"

+    .local pmc _G

+    _G = global "_G"

+    .local pmc key1

+    key1 = new .LuaString

+    key1 = "os"

+    .local pmc os

+    os = new .LuaTable

+    os = _G[key1]

+    .local pmc key2

+    key2 = new .LuaString

+    key2 = "remove"

+    .local pmc fct1

+    fct1 = os[key2]

+    .local pmc arg1

+    .local pmc ret1

+    .local pmc msg1

+    new arg1, .LuaString

+    arg1 = "file.rm"

+    (ret1, msg1) = fct1(arg1)

+    print ret1

+    print "\n"

+    print msg1

+    print "\n"

+    end

+.end

+CODE

+nil

+file.rm: No such file or directory

+OUTPUT

 

Reply via email to