Author: fperrad
Date: Mon Feb  6 23:06:44 2006
New Revision: 11464

Modified:
   trunk/languages/lua/lib/luaos.pir
   trunk/languages/lua/t/lib/os.t
Log:
Lua :
- add function os.rename
- and tests

Modified: trunk/languages/lua/lib/luaos.pir
==============================================================================
--- trunk/languages/lua/lib/luaos.pir   (original)
+++ trunk/languages/lua/lib/luaos.pir   Mon Feb  6 23:06:44 2006
@@ -226,6 +226,7 @@ B<nil>, plus a string describing the err
     .param pmc filename
     .local pmc ret
     $S0 = checkstring(filename)
+    $S1 = $S0
     new $P0, .OS
     push_eh _handler
     $P0."rm"($S0)
@@ -238,11 +239,11 @@ _handler:
     .local pmc e
     .local string s
     .get_results (e, s)
-    concat $S0, ": "
-    concat $S0, s
+    concat $S1, ": "
+    concat $S1, s
     new nil, .LuaNil
     new msg, .LuaString
-    msg = $S0
+    msg = $S1
     .return (nil, msg)
 .end
 
@@ -251,16 +252,33 @@ _handler:
 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.              
-
 =cut
 
 .sub _os_rename :anon
     .param pmc oldname
     .param pmc newname
+    .local pmc ret
     $S0 = checkstring(oldname)
+    $S2 = $S0
     $S1 = checkstring(newname)
-    not_implemented()
+    new $P0, .File
+    push_eh _handler
+    $P0."rename"($S0, $S1)
+    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 $S2, ": "
+    concat $S2, s
+    new nil, .LuaNil
+    new msg, .LuaString
+    msg = $S2
+    .return (nil, msg)
 .end
 
 =item C<os.setlocale (locale [, category])>

Modified: trunk/languages/lua/t/lib/os.t
==============================================================================
--- trunk/languages/lua/t/lib/os.t      (original)
+++ trunk/languages/lua/t/lib/os.t      Mon Feb  6 23:06:44 2006
@@ -18,7 +18,7 @@ Tests Lua Operating System Library

 

 =cut

 

-use Parrot::Test tests => 7;

+use Parrot::Test tests => 11;

 use Test::More;

 

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

@@ -162,6 +162,69 @@ nil

 file.rm: No such file or directory

 OUTPUT

 

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

+print X "file to rename";

+close X;

+

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

+.namespace [ "Lua" ]

+.HLL "Lua", "lua_group"

+.sub _main

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

+    .local pmc _G

+    _G = global "_G"

+    .const .LuaString key1 = "os"

+    .local pmc os

+    os = _G[key1]

+    .const .LuaString key2 = "rename"

+    .local pmc fct1

+    fct1 = os[key2]

+    .const .LuaString arg1 = "file.old"

+    .const .LuaString arg2 = "file.new"

+    .local pmc ret1

+    ret1 = fct1(arg1, arg2)

+    print ret1

+    print "\n"

+    end

+.end

+CODE

+true

+OUTPUT

+

+ok(!-e "../file.old", "Test that old file is missing");

+ok(-e "../file.new", "Test that new file is here");

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

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

+

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

+.namespace [ "Lua" ]

+.HLL "Lua", "lua_group"

+.sub _main

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

+    .local pmc _G

+    _G = global "_G"

+    .const .LuaString key1 = "os"

+    .local pmc os

+    os = _G[key1]

+    .const .LuaString key2 = "rename"

+    .local pmc fct1

+    fct1 = os[key2]

+    .const .LuaString arg1 = "file.old"

+    .const .LuaString arg2 = "file.new"

+    .local pmc ret1

+    .local pmc msg1

+    (ret1, msg1) = fct1(arg1, arg2)

+    print ret1

+    print "\n"

+    print msg1

+    print "\n"

+    end

+.end

+CODE

+nil

+file.old: No such file or directory

+OUTPUT

+

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

 .namespace [ "Lua" ]

 .HLL "Lua", "lua_group"

Reply via email to