changeset 554:18504c41b0be

move debug() to Io and remove Debug module; Io.print() now doesn't print newline if there is nothing to be printed;
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 18 Jun 2015 03:30:18 -0600
parents b1256e2d19a3
children e25ba7a2e816
files core/src/luan/cmd_line.luan core/src/luan/modules/Debug.luan core/src/luan/modules/Io.luan http/src/luan/modules/http/Shell_mod.luan scripts/test.luan
diffstat 5 files changed, 53 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
diff -r b1256e2d19a3 -r 18504c41b0be core/src/luan/cmd_line.luan
--- a/core/src/luan/cmd_line.luan	Thu Jun 18 03:14:07 2015 -0600
+++ b/core/src/luan/cmd_line.luan	Thu Jun 18 03:30:18 2015 -0600
@@ -1,17 +1,17 @@
 local Luan = require "luan:Luan"
-local ipairs = Luan.ipairs
-local load_file = Luan.load_file
-local try = Luan.try
+local error = Luan.error
+local ipairs = Luan.ipairs or error()
+local load_file = Luan.load_file or error()
+local try = Luan.try or error()
 local Table = require "luan:Table"
 local Io = require "luan:Io"
-local print = Io.print
-local Debug = require "luan:Debug"
+local print = Io.print or error()
 
 
 local args = {...}
 if #args == 0 then
 	print(Luan.VERSION)
-	Debug.debug("> ")
+	Io.debug("> ")
 else
 	local file = args[1]
 	Luan.arg = {}
@@ -21,7 +21,7 @@
 	try {
 		function()
 			local main_file = load_file(file,true)
-			Debug.print_if_something( main_file( Table.unpack(Luan.arg) ) )
+			print( main_file( Table.unpack(Luan.arg) ) )
 		end;
 		catch = function(e)
 --			java(); e.java.printStackTrace(); return
diff -r b1256e2d19a3 -r 18504c41b0be core/src/luan/modules/Debug.luan
--- a/core/src/luan/modules/Debug.luan	Thu Jun 18 03:14:07 2015 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-local Luan = require "luan:Luan"
-local load = Luan.load
-local try = Luan.try
-local Io = require "luan:Io"
-local print = Io.print
-local Table = require "luan:Table"
-
-local M = {}
-
-function M.print_if_something(...)
-	if Table.pack(...).n > 0 then
-		print(...)
-	end
-end
-
-function M.debug(prompt)
-	prompt = prompt or "luan_debug> "
-	local function console()
-		return Io.read_console_line(prompt)
-	end
-	local env = {}
-	for line in console do
-		try {
-			function()
-				local fn = load(line,"stdin",env,true)
-				M.print_if_something( fn() )
-			end;
-			catch = function(e)
-				print(e)
-			end;
-		}
-	end
-end
-
-return M
diff -r b1256e2d19a3 -r 18504c41b0be core/src/luan/modules/Io.luan
--- a/core/src/luan/modules/Io.luan	Thu Jun 18 03:14:07 2015 -0600
+++ b/core/src/luan/modules/Io.luan	Thu Jun 18 03:30:18 2015 -0600
@@ -14,17 +14,19 @@
 
 
 local Luan = require "luan:Luan"
-local to_string = Luan.to_string
-local type = Luan.type
-local try = Luan.try
-local ipairs = Luan.ipairs
-local pairs = Luan.pairs
-local values = Luan.values
+local error = Luan.error
+local to_string = Luan.to_string or error()
+local type = Luan.type or error()
+local try = Luan.try or error()
+local ipairs = Luan.ipairs or error()
+local pairs = Luan.pairs or error()
+local values = Luan.values or error()
+local load = Luan.load or error()
 local Table = require "luan:Table"
-local unpack = Table.unpack
+local unpack = Table.unpack or error()
 local String = require "luan:String"
-local encode = String.encode
-local matches = String.matches
+local encode = String.encode or error()
+local matches = String.matches or error()
 
 
 function M.print_to(out,...)
@@ -33,9 +35,7 @@
 		list[#list+1] = to_string(v)
 		list[#list+1] = '\t'
 	end
-	if #list == 0 then
-		out.write( '\n' )
-	else
+	if #list > 0 then
 		list[#list] = '\n'
 		out.write( unpack(list) )
 	end
@@ -122,4 +122,27 @@
 	end
 end
 
+
+-- debug
+
+function M.debug(prompt)
+	prompt = prompt or "luan_debug> "
+	local function console()
+		return M.read_console_line(prompt)
+	end
+	local env = {}
+	for line in console do
+		try {
+			function()
+				local fn = load(line,"stdin",env,true)
+				M.print( fn() )
+			end;
+			catch = function(e)
+				M.print(e)
+			end;
+		}
+	end
+end
+
+
 return M
diff -r b1256e2d19a3 -r 18504c41b0be http/src/luan/modules/http/Shell_mod.luan
--- a/http/src/luan/modules/http/Shell_mod.luan	Thu Jun 18 03:14:07 2015 -0600
+++ b/http/src/luan/modules/http/Shell_mod.luan	Thu Jun 18 03:30:18 2015 -0600
@@ -1,10 +1,10 @@
 local Luan = require "luan:Luan"
-local ipairs = Luan.ipairs
-local load = Luan.load
-local try = Luan.try
+local error = Luan.error
+local ipairs = Luan.ipairs or error()
+local load = Luan.load or error()
+local try = Luan.try or error()
 local Io = require "luan:Io"
-local print = Io.print
-local Debug = require "luan:Debug"
+local print = Io.print or error()
 local Http = require "luan:http/Http"
 local Html = require "luan:Html"
 
@@ -29,7 +29,7 @@
 			try {
 				function()
 					local line = load(cmd,"<web_shell>",M.env,true)
-					Debug.print_if_something( line() )
+					print( line() )
 				end;
 				catch = function(e)
 					Io.print_to(Io.stderr,e)
diff -r b1256e2d19a3 -r 18504c41b0be scripts/test.luan
--- a/scripts/test.luan	Thu Jun 18 03:14:07 2015 -0600
+++ b/scripts/test.luan	Thu Jun 18 03:30:18 2015 -0600
@@ -1,5 +1,4 @@
 local Binary = require "luan:Binary"
-local Debug = require "luan:Debug"
 local Html = require "luan:Html"
 local Io = require "luan:Io"
 local Luan = require "luan:Luan"
@@ -19,11 +18,11 @@
 local Stripe = require "luan:stripe/Stripe"
 
 local error = Luan.error
-local range = Luan.range
-local trim = String.trim
-local find = String.find
-local init = Http_test.init
-local get_page = Http_test.get_page
+local range = Luan.range or error()
+local trim = String.trim or error()
+local find = String.find or error()
+local init = Http_test.init or error()
+local get_page = Http_test.get_page or error()
 local Ab_testing = require "luan:lucene/Ab_testing"