changeset 448:8b2db645b9b2

move Luan.to_number to String
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 04 May 2015 20:05:38 -0600
parents 0bd42e774c50
children e89bf64a0d05
files core/src/luan/modules/BasicLuan.java core/src/luan/modules/Luan.luan core/src/luan/modules/String.luan core/src/luan/modules/StringLuan.java lucene/src/luan/modules/lucene/Web_search.luan
diffstat 5 files changed, 14 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/modules/BasicLuan.java	Mon May 04 17:19:43 2015 -0600
+++ b/core/src/luan/modules/BasicLuan.java	Mon May 04 20:05:38 2015 -0600
@@ -103,21 +103,6 @@
 		throw luan.exception( "bad argument #1 to 'raw_len' (table or string expected)" );
 	}
 
-	public static Number to_number(Object v,Integer base) {
-		try {
-			if( base == null ) {
-				if( v instanceof Number )
-					return (Number)v;
-				if( v instanceof String )
-					return Double.valueOf((String)v);
-			} else {
-				if( v instanceof String )
-					return Long.valueOf((String)v,base);
-			}
-		} catch(NumberFormatException e) {}
-		return null;
-	}
-
 	public static String to_string(LuanState luan,Object v) throws LuanException {
 		return luan.toString(v);
 	}
--- a/core/src/luan/modules/Luan.luan	Mon May 04 17:19:43 2015 -0600
+++ b/core/src/luan/modules/Luan.luan	Mon May 04 20:05:38 2015 -0600
@@ -22,7 +22,6 @@
 raw_len = BasicLuan.raw_len
 raw_set = BasicLuan.raw_set
 set_metatable = BasicLuan.set_metatable
-to_number = BasicLuan.to_number
 to_string = BasicLuan.to_string
 try = BasicLuan.try_
 type = BasicLuan.type
--- a/core/src/luan/modules/String.luan	Mon May 04 17:19:43 2015 -0600
+++ b/core/src/luan/modules/String.luan	Mon May 04 20:05:38 2015 -0600
@@ -16,5 +16,6 @@
 reverse = StringLuan.reverse
 sub = StringLuan.sub
 to_binary = StringLuan.to_binary
+to_number = StringLuan.to_number
 trim = StringLuan.trim
 upper = StringLuan.upper
--- a/core/src/luan/modules/StringLuan.java	Mon May 04 17:19:43 2015 -0600
+++ b/core/src/luan/modules/StringLuan.java	Mon May 04 20:05:38 2015 -0600
@@ -239,4 +239,16 @@
 		return Luan.stringEncode(s);
 	}
 
+	public static Number to_number(LuanState luan,String s,Integer base) throws LuanException {
+		Utils.checkNotNull(luan,s);
+		try {
+			if( base == null ) {
+				return Double.valueOf(s);
+			} else {
+				return Long.valueOf(s,base);
+			}
+		} catch(NumberFormatException e) {}
+		return null;
+	}
+
 }
--- a/lucene/src/luan/modules/lucene/Web_search.luan	Mon May 04 17:19:43 2015 -0600
+++ b/lucene/src/luan/modules/lucene/Web_search.luan	Mon May 04 20:05:38 2015 -0600
@@ -1,6 +1,5 @@
 local Luan = require "luan:Luan"
 local load = Luan.load
-local to_number = Luan.to_number
 local pairs = Luan.pairs
 local ipairs = Luan.ipairs
 local range = Luan.range
@@ -130,7 +129,7 @@
 			return
 		end
 		local query = load(query_string,"<query>",{Query=index.query},true)()
-		local rows = to_number(Http.request.parameters.rows)
+		local rows = Http.request.parameters.rows.to_number()
 		local sort = load(Http.request.parameters.sort,"<sort>",{Query=index.query},true)()
 		index.Searcher( function(searcher)
 			local results, length, total_hits = searcher.search(query,rows,sort)