changeset 1277:5ba660381bd5

fix Io.print()
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 11 Dec 2018 03:38:43 -0700
parents 623dfe0e2e73
children d83f6cc558de
files conv.txt src/luan/cmd_line.luan src/luan/host/main.luan src/luan/modules/Io.luan src/luan/modules/TableLuan.java src/luan/modules/http/tools/Shell.luan website/src/manual.html.luan
diffstat 7 files changed, 29 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/conv.txt	Mon Dec 10 15:04:09 2018 -0700
+++ b/conv.txt	Tue Dec 11 03:38:43 2018 -0700
@@ -1,3 +1,4 @@
+"Io.print()"
 "Luan.values"
 remove "as_table"
 
--- a/src/luan/cmd_line.luan	Mon Dec 10 15:04:09 2018 -0700
+++ b/src/luan/cmd_line.luan	Tue Dec 11 03:38:43 2018 -0700
@@ -4,6 +4,8 @@
 local load_file = Luan.load_file or error()
 local try = Luan.try or error()
 local Table = require "luan:Table.luan"
+local pack = Table.pack or error()
+local unpack = Table.unpack or error()
 local Io = require "luan:Io.luan"
 local print = Io.print or error()
 
@@ -21,7 +23,10 @@
 	try {
 		function()
 			local main_file = load_file(file)
-			print( main_file( Table.unpack(Luan.arg) ) )
+			local rtn = pack( main_file( unpack(Luan.arg) ) )
+			if rtn.n > 0 then
+				print( unpack(rtn) )
+			end
 		end
 		catch = function(e)
 --			java(); e.java.printStackTrace();
--- a/src/luan/host/main.luan	Mon Dec 10 15:04:09 2018 -0700
+++ b/src/luan/host/main.luan	Tue Dec 11 03:38:43 2018 -0700
@@ -5,7 +5,6 @@
 local ipairs = Luan.ipairs or error()
 local try = Luan.try or error()
 local Io = require "luan:Io.luan"
-local print = Io.print or error()
 local Rpc = require "luan:Rpc.luan"
 local Thread = require "luan:Thread.luan"
 local String = require "luan:String.luan"
--- a/src/luan/modules/Io.luan	Mon Dec 10 15:04:09 2018 -0700
+++ b/src/luan/modules/Io.luan	Tue Dec 11 03:38:43 2018 -0700
@@ -28,6 +28,7 @@
 local values = Luan.values or error()
 local load = Luan.load or error()
 local Table = require "luan:Table.luan"
+local pack = Table.pack or error()
 local unpack = Table.unpack or error()
 local String = require "luan:String.luan"
 local encode = String.encode or error()
@@ -49,6 +50,8 @@
 	if #list > 0 then
 		list[#list] = '\n'
 		out.write( unpack(list) )
+	else
+		out.write('\n')
 	end
 end
 
@@ -101,7 +104,10 @@
 						fn = load(line,"stdin",env)
 					end
 				}
-				Io.print( fn() )
+				local rtn = pack( fn() )
+				if rtn.n > 0 then
+					Io.print( unpack(rtn) )
+				end
 			end
 			catch = function(e)
 				Io.print(e)
--- a/src/luan/modules/TableLuan.java	Mon Dec 10 15:04:09 2018 -0700
+++ b/src/luan/modules/TableLuan.java	Tue Dec 11 03:38:43 2018 -0700
@@ -92,7 +92,13 @@
 
 	@LuanMethod public static Object[] unpack(LuanTable tbl,Integer iFrom,Integer iTo) throws LuanException {
 		int from = iFrom!=null ? iFrom : 1;
-		int to = iTo!=null ? iTo : tbl.length();
+		int to;
+		if( iTo != null ) {
+			to = iTo;
+		} else {
+			Integer n = Luan.asInteger( tbl.get("n") );
+			to = n!=null ? n : tbl.length();
+		}
 		List<Object> list = new ArrayList<Object>();
 		for( int i=from; i<=to; i++ ) {
 			list.add( tbl.get(i) );
--- a/src/luan/modules/http/tools/Shell.luan	Mon Dec 10 15:04:09 2018 -0700
+++ b/src/luan/modules/http/tools/Shell.luan	Tue Dec 11 03:38:43 2018 -0700
@@ -6,6 +6,9 @@
 local try = Luan.try or error()
 local String = require "luan:String.luan"
 local concat = String.concat or error()
+local Table = require "luan:Table.luan"
+local pack = Table.pack or error()
+local unpack = Table.unpack or error()
 local Time = require "luan:Time.luan"
 local Thread = require "luan:Thread.luan"
 local Io = require "luan:Io.luan"
@@ -51,7 +54,10 @@
 					line = load(cmd,"<web_shell>",env)
 				end
 			}
-			print( line() )
+			local rtn = pack( line() )
+			if rtn.n > 0  then
+				print( unpack(rtn) )
+			end
 		end
 		catch = function(e)
 			Io.print_to(Io.stderr,e)
--- a/website/src/manual.html.luan	Mon Dec 10 15:04:09 2018 -0700
+++ b/website/src/manual.html.luan	Tue Dec 11 03:38:43 2018 -0700
@@ -2751,7 +2751,7 @@
 </pre>
 
 <p>
-By default, <code>i</code> is&nbsp;1 and <code>j</code> is <code>#list</code>.
+By default, <code>i</code> is 1 and <code>j</code> is <code>list.n or #list</code>.