changeset 1164:1f9d34a6f308

remove assertions
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 07 Feb 2018 17:36:38 -0700
parents fef8f0742da9
children 668f29bc52ea
files conv.txt examples/blog/src/lib/Post.luan src/luan/Luan.java src/luan/host/main.luan src/luan/modules/BasicLuan.java src/luan/modules/Luan.luan src/luan/modules/Parsers.luan src/luan/modules/Rpc.luan src/luan/modules/Time.luan src/luan/modules/http/Implementation.luan src/luan/modules/http/impl/Http.luan src/luan/modules/http/tools/luan_threads.luan src/luan/modules/mail/Mail.luan website/src/manual.html.luan
diffstat 14 files changed, 51 insertions(+), 141 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/conv.txt	Wed Feb 07 17:36:38 2018 -0700
@@ -0,0 +1,11 @@
+headers lower case
+remove run_later
+remove Thread.global
+
+"request.header"
+"response.header"
+"request.parameter"
+"request.cookie"
+"set_cookie"
+"Thread.global"
+"assert"
--- a/examples/blog/src/lib/Post.luan	Tue Feb 06 22:04:47 2018 -0700
+++ b/examples/blog/src/lib/Post.luan	Wed Feb 07 17:36:38 2018 -0700
@@ -1,7 +1,7 @@
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
 local ipairs = Luan.ipairs or error()
-local assert_string = Luan.assert_string or error()
+local type = Luan.type or error()
 local Time = require "luan:Time.luan"
 local now = Time.now or error()
 local String = require "luan:String.luan"
@@ -21,8 +21,8 @@
 end
 
 function Post.new(this)
-	assert_string(this.subject)
-	assert_string(this.content)
+	type(this.subject)=="string" or error "subject must be string"
+	type(this.content)=="string" or error "content must be string"
 	this.date = this.date or now()
 
 	function this.save()
--- a/src/luan/Luan.java	Tue Feb 06 22:04:47 2018 -0700
+++ b/src/luan/Luan.java	Wed Feb 07 17:36:38 2018 -0700
@@ -8,6 +8,7 @@
 import java.util.Arrays;
 import java.util.Iterator;
 import luan.modules.BasicLuan;
+import luan.modules.Utils;
 import luan.impl.LuanCompiler;
 
 
@@ -223,6 +224,11 @@
 		}
 	}
 
+	public static LuanTable table(LuanTable v) throws LuanException {
+		Utils.checkNotNull(v);
+		return v;
+	}
+
 
 	private Luan() {}  // never
 }
--- a/src/luan/host/main.luan	Tue Feb 06 22:04:47 2018 -0700
+++ b/src/luan/host/main.luan	Wed Feb 07 17:36:38 2018 -0700
@@ -1,7 +1,7 @@
 java()
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
-local assert_string = Luan.assert_string or error()
+local type = Luan.type or error()
 local ipairs = Luan.ipairs or error()
 local try = Luan.try or error()
 local Io = require "luan:Io.luan"
@@ -43,8 +43,8 @@
 local fns = Rpc.functions
 
 local function get_dir(domain,password)
-	assert_string(domain)
-	assert_string(password)
+	type(domain)=="string" or error()
+	type(password)=="string" or error()
 	domain = lower(domain)
 	local dir = sites_dir.child(domain)
 	if dir.exists() then
@@ -96,8 +96,8 @@
 end
 
 function fns.create(domain,password)
-	assert_string(domain)
-	assert_string(password)
+	type(domain)=="string" or error()
+	type(password)=="string" or error()
 	domain = lower(domain)
 	local dir = sites_dir.child(domain)
 	dir.exists() and error "already exists"
@@ -155,7 +155,7 @@
 end
 
 function fns.exists(domain)
-	assert_string(domain)
+	type(domain)=="string" or error()
 	domain = lower(domain)
 	return sites_dir.child(domain).exists()
 end
@@ -164,7 +164,7 @@
 	local old_dir = get_dir(old_domain,password)
 	old_dir or error "domain not found"
 	old_dir = old_dir.parent()
-	assert_string(new_domain)
+	type(new_domain)=="string" or error()
 	new_domain = lower(new_domain)
 	local new_dir = sites_dir.child(new_domain)
 	new_dir.exists() and error "new_domain already exists"
--- a/src/luan/modules/BasicLuan.java	Tue Feb 06 22:04:47 2018 -0700
+++ b/src/luan/modules/BasicLuan.java	Wed Feb 07 17:36:38 2018 -0700
@@ -113,25 +113,6 @@
 		return tbl;
 	}
 
-	public static String assert_string(String v) throws LuanException {
-		Utils.checkNotNull(v);
-		return v;
-	}
-
-	public static Number assert_number(Number v) throws LuanException {
-		Utils.checkNotNull(v);
-		return v;
-	}
-
-	public static LuanTable assert_table(LuanTable v) throws LuanException {
-		Utils.checkNotNull(v);
-		return v;
-	}
-
-	public static boolean assert_boolean(boolean v) throws LuanException {
-		return v;
-	}
-
 	public static int assert_integer(int v) throws LuanException {
 		return v;
 	}
@@ -148,16 +129,6 @@
 		return v;
 	}
 
-	@LuanMethod public static byte[] assert_binary(byte[] v) throws LuanException {
-		Utils.checkNotNull(v);
-		return v;
-	}
-
-	public static LuanFunction assert_function(LuanFunction v) throws LuanException {
-		Utils.checkNotNull(v);
-		return v;
-	}
-
 	public static LuanFunction range(final double from,final double to,Double stepV) throws LuanException {
 		final double step = stepV==null ? 1.0 : stepV;
 		if( step == 0.0 )
--- a/src/luan/modules/Luan.luan	Tue Feb 06 22:04:47 2018 -0700
+++ b/src/luan/modules/Luan.luan	Wed Feb 07 17:36:38 2018 -0700
@@ -3,14 +3,6 @@
 
 local Luan = {}
 
-Luan.assert_binary = BasicLuan.assert_binary
-Luan.assert_boolean = BasicLuan.assert_boolean
-Luan.assert_function = BasicLuan.assert_function
-Luan.assert_integer = BasicLuan.assert_integer
-Luan.assert_long = BasicLuan.assert_long
-Luan.assert_number = BasicLuan.assert_number
-Luan.assert_string = BasicLuan.assert_string
-Luan.assert_table = BasicLuan.assert_table
 Luan.get_metatable = BasicLuan.get_metatable
 Luan.hash_code = BasicLuan.hash_code
 Luan.ipairs = BasicLuan.ipairs
@@ -40,10 +32,6 @@
 	Luan.new_error(message).throw()
 end
 
-function Luan.assert(v,message)
-	return v or Luan.error(message or "assertion failed!")
-end
-
 function Luan.eval(s,source_name)
 	return Luan.load( "return "..s, source_name or "eval" )()
 end
--- a/src/luan/modules/Parsers.luan	Tue Feb 06 22:04:47 2018 -0700
+++ b/src/luan/modules/Parsers.luan	Wed Feb 07 17:36:38 2018 -0700
@@ -11,22 +11,22 @@
 Parsers.csv_to_list = Csv.toList
 Parsers.theme_to_luan = Theme.toLuan
 
-local Luan = require "java:luan.Luan"
+local JavaLuan = require "java:luan.Luan"
 local JsonParser = require "java:luan.lib.json.JsonParser"
 local JsonToString = require "java:luan.lib.json.JsonToString"
 
 -- converts json string to luan object
 function Parsers.json_parse(obj)
-	return Luan.toLuan(JsonParser.parse(obj))
+	return JavaLuan.toLuan(JsonParser.parse(obj))
 end
 
 -- converts luan object to json string
 function Parsers.json_string(obj)
-	return JsonToString.toString(Luan.toJava(obj))
+	return JsonToString.toString(JavaLuan.toJava(obj))
 end
 
 function Parsers.json_compressed_string(obj)
-	return JsonToString.toCompressedString(Luan.toJava(obj))
+	return JsonToString.toCompressedString(JavaLuan.toJava(obj))
 end
 
 return Parsers
--- a/src/luan/modules/Rpc.luan	Tue Feb 06 22:04:47 2018 -0700
+++ b/src/luan/modules/Rpc.luan	Wed Feb 07 17:36:38 2018 -0700
@@ -14,7 +14,6 @@
 local set_metatable = Luan.set_metatable or error()
 local try = Luan.try or error()
 local ipairs = Luan.ipairs or error()
-local assert_table = Luan.assert_table or error()
 local type = Luan.type or error()
 local Io = require "luan:Io.luan"
 local Thread = require "luan:Thread.luan"
@@ -37,7 +36,7 @@
 end
 
 local function luan_args(list,binary_in)
-	list = assert_table(list)
+	list = JavaLuan.table(list)
 	for i,v in ipairs(list) do
 		list[i] = JavaLuan.toLuan(v)
 	end
--- a/src/luan/modules/Time.luan	Tue Feb 06 22:04:47 2018 -0700
+++ b/src/luan/modules/Time.luan	Wed Feb 07 17:36:38 2018 -0700
@@ -3,10 +3,11 @@
 java()
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
-local assert_long = Luan.assert_long or error()
 local ipairs = Luan.ipairs or error()
 local Math = require "luan:Math.luan"
 local floor = Math.floor or error()
+local Number = require "luan:Number.luan"
+local long = Number.long or error()
 local Table = require "luan:Table.luan"
 local System = require "java:java.lang.System"
 local Calendar = require "java:java.util.Calendar"
@@ -55,7 +56,7 @@
 end
 
 function Time.format(time,pattern)
-	time = assert_long(time)
+	time = long(time)
 	pattern = pattern or "yyyy-MM-dd HH:mm:ss"
 	local fmt = SimpleDateFormat.new(pattern)
 	set_time_zone(fmt)
--- a/src/luan/modules/http/Implementation.luan	Tue Feb 06 22:04:47 2018 -0700
+++ b/src/luan/modules/http/Implementation.luan	Wed Feb 07 17:36:38 2018 -0700
@@ -1,4 +1,4 @@
 return {
-	luan = "luan:http/jetty/"
---	luan = "luan:http/impl/"
+--	luan = "luan:http/jetty/"
+	luan = "luan:http/impl/"
 }
--- a/src/luan/modules/http/impl/Http.luan	Tue Feb 06 22:04:47 2018 -0700
+++ b/src/luan/modules/http/impl/Http.luan	Wed Feb 07 17:36:38 2018 -0700
@@ -1,7 +1,6 @@
 java()
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
-local assert_string = Luan.assert_string or error()
 local ipairs = Luan.ipairs or error()
 local pairs = Luan.pairs or error()
 local type = Luan.type or error()
@@ -15,7 +14,7 @@
 local matches = String.matches or error()
 local HttpServicer = require "java:luan.modules.http.impl.HttpServicer"
 local IoLuan = require "java:luan.modules.IoLuan"
-local LuanJava = require "java:luan.Luan"
+local JavaLuan = require "java:luan.Luan"
 local Response = require "java:luan.webserver.Response"
 local ResponseOutputStream = require "java:luan.webserver.ResponseOutputStream"
 local Status = require "java:luan.webserver.Status"
@@ -39,9 +38,9 @@
 		this.raw_path = java.rawPath or error()
 		this.path = java.path or error()
 		this.protocol = java.protocol or error()
-		this.headers = LuanJava.toLuan(java.headers)
-		this.parameters = LuanJava.toLuan(java.parameters)
-		this.cookies = LuanJava.toLuan(java.cookies)
+		this.headers = JavaLuan.toLuan(java.headers)
+		this.parameters = JavaLuan.toLuan(java.parameters)
+		this.cookies = JavaLuan.toLuan(java.cookies)
 	end
 	this.scheme = "http"
 
@@ -97,8 +96,8 @@
 		attributes = attributes or {}
 		local attrMap = HashMap.new()
 		for attr_name, attr_value in pairs(attributes) do
-			assert_string(attr_name)
-			assert_string(attr_value)
+			type(attr_name)=="string" or "cookie attribute name must be string"
+			type(attr_value)=="string" or "cookie attribute value must be string"
 			attrMap.put(attr_name,attr_value)
 		end
 		this.java.setCookie(name,value,attrMap)
@@ -137,8 +136,8 @@
 	local java = response.java or error()
 	java.status = Status.getStatus(response.status)
 	for name, value in pairs(response.headers) do
-		assert_string(name)
-		value = LuanJava.toJava(value)
+		type(name)=="string" or "header name must be string"
+		value = JavaLuan.toJava(value)
 		java.headers.put(name,value)
 	end
 	response.writer and response.writer.close()
--- a/src/luan/modules/http/tools/luan_threads.luan	Tue Feb 06 22:04:47 2018 -0700
+++ b/src/luan/modules/http/tools/luan_threads.luan	Wed Feb 07 17:36:38 2018 -0700
@@ -1,12 +1,12 @@
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
-local assert_table = Luan.assert_table or error()
 local Io = require "luan:Io.luan"
 local Time = require "luan:Time.luan"
 local Http = require "luan:http/Http.luan"
 java()
 local Thread = require "java:java.lang.Thread"
 local LuanException = require "java:luan.LuanException"
+local JavaLuan = require "java:luan.Luan"
 
 
 return function()
@@ -29,7 +29,7 @@
 		<%
 		local count = 0
 		for _, thread in Luan.ipairs(threads) do
-			local luan_trace = assert_table(LuanException.justLuan(thread.trace))
+			local luan_trace = JavaLuan.table(LuanException.justLuan(thread.trace))
 			if #luan_trace > 0 then
 				%>
 				<p><%=thread.string%> <%=thread.state%>
--- a/src/luan/modules/mail/Mail.luan	Tue Feb 06 22:04:47 2018 -0700
+++ b/src/luan/modules/mail/Mail.luan	Wed Feb 07 17:36:38 2018 -0700
@@ -1,15 +1,17 @@
 java()
 local Luan = require "luan:Luan.luan"
-local assert_table = Luan.assert_table
+local error = Luan.error
+local type = Luan.type or error()
 local System = require "java:java.lang.System"
 local SmtpCon = require "java:luan.modules.mail.SmtpCon"
 
+
 local Mail = {}
 
 System.setProperty( "mail.mime.charset", "UTF-8" )
 
 function Mail.Sender(params)
-	assert_table(params)
+	type(params)=="table" or error()
 	local smtpCon = SmtpCon.new(params)
 	return { send = smtpCon.send }
 end
--- a/website/src/manual.html.luan	Tue Feb 06 22:04:47 2018 -0700
+++ b/website/src/manual.html.luan	Wed Feb 07 17:36:38 2018 -0700
@@ -1804,73 +1804,6 @@
 The basic library provides basic functions to Luan that don't depend on other libaries.
 
 
-<h4 heading><a name="Luan.assert" href="#Luan.assert"><code>Luan.assert (v [, message])</code></a></h4>
-
-<p>
-Could be defined as:
-
-<pre>
-	function Luan.assert(v,message)
-		return v or <a href="#Luan.error">Luan.error</a>(message or "assertion failed!")
-	end
-</pre>
-
-
-<h4 heading><a name="Luan.assert_binary" href="#Luan.assert_binary"><code>Luan.assert_binary (v)</code></a></h4>
-
-<p>
-Could be defined as:
-
-<pre>
-	function Luan.assert_binary(v)
-		local v_type = Luan.type(v)
-		return v_type == "binary" and v or <a href="#Luan.error">Luan.error</a>("bad argument #1 (binary expected, got "..v_type..")")
-	end
-</pre>
-
-
-<h4 heading><a name="Luan.assert_boolean" href="#Luan.assert_boolean"><code>Luan.assert_boolean (v)</code></a></h4>
-
-<p>
-Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>boolean</code>.
-
-
-<h4 heading><a name="Luan.assert_function" href="#Luan.assert_function"><code>Luan.assert_function (v)</code></a></h4>
-
-<p>
-Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>function</code>.
-
-
-<h4 heading><a name="Luan.assert_integer" href="#Luan.assert_integer"><code>Luan.assert_integer (v)</code></a></h4>
-
-<p>
-Asserts that <code>v</code> can be converted to Java type <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html">Integer</a> and returns an Integer.
-
-
-<h4 heading><a name="Luan.assert_long" href="#Luan.assert_long"><code>Luan.assert_long (v)</code></a></h4>
-
-<p>
-Asserts that <code>v</code> can be converted to Java type <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Long.html">Long</a> and returns a Long.
-
-
-<h4 heading><a name="Luan.assert_number" href="#Luan.assert_number"><code>Luan.assert_number (v)</code></a></h4>
-
-<p>
-Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>number</code>.
-
-
-<h4 heading><a name="Luan.assert_string" href="#Luan.assert_string"><code>Luan.assert_string (v)</code></a></h4>
-
-<p>
-Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>string</code>.
-
-
-<h4 heading><a name="Luan.assert_table" href="#Luan.assert_table"><code>Luan.assert_table (v)</code></a></h4>
-
-<p>
-Like <a href="#Luan.assert_binary"><code>assert_binary</code></a> but for type <code>table</code>.
-
-
 <h4 heading><a name="Luan.do_file" href="#Luan.do_file"><code>Luan.do_file ([uri])</code></a></h4>
 
 <p>