changeset 531:f99c79b0b426

change LuanException.getFullMessage() to not require LuanState
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 27 May 2015 22:01:40 -0600
parents 7366101be4c4
children 9bf9ad733827
files core/src/luan/LuanException.java core/src/luan/modules/PickleServer.java http/src/luan/modules/http/LuanHandler.java
diffstat 3 files changed, 11 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/LuanException.java	Wed May 27 21:50:44 2015 -0600
+++ b/core/src/luan/LuanException.java	Wed May 27 22:01:40 2015 -0600
@@ -13,8 +13,9 @@
 
 	LuanException(LuanBit bit,Object msg) throws LuanException {
 		this( bit.luan.toString(msg), msg instanceof Throwable ? (Throwable)msg : null );
-		table.rawPut("java",this);
-		table.rawPut("message",msg);
+		table.rawPut( "java", this );
+		table.rawPut( "message", msg );
+		table.rawPut( "message_string", bit.luan.toString(msg) );
 		for( StackTraceElement ste : bit.stackTrace() ) {
 			LuanTable tbl = new LuanTable();
 			tbl.rawPut( "source", ste.call.source.name );
@@ -29,7 +30,7 @@
 				LuanException.class.getMethod( "throwThis" ), this
 			) );
 			metatable.rawPut( "__to_string", new LuanJavaFunction(
-				LuanException.class.getMethod( "__to_string", LuanState.class, LuanTable.class ), null
+				LuanException.class.getMethod( "__to_string", LuanTable.class ), null
 			) );
 		} catch(NoSuchMethodException e) {
 			throw new RuntimeException(e);
@@ -53,19 +54,16 @@
 		throw this;
 	}
 
-	public String getFullMessage(LuanState luan) {
-		try {
-			return __to_string(luan,table);
-		} catch(LuanException e) {
-			throw new RuntimeException(e);
-		}
+	public String getFullMessage() {
+		return __to_string(table);
 	}
 
-	public static String __to_string(LuanState luan,LuanTable table) throws LuanException {
+	public static String __to_string(LuanTable table) {
 		StringBuilder buf = new StringBuilder();
 
 		Object msg = table.rawGet("message");
-		buf.append( luan.toString(msg) );
+		String msgStr = (String)table.rawGet("message_string");
+		buf.append( msgStr );
 
 		for( int i = table.rawLength(); i>=1; i-- ) {
 			LuanTable tbl = (LuanTable)table.rawGet(i);
--- a/core/src/luan/modules/PickleServer.java	Wed May 27 21:50:44 2015 -0600
+++ b/core/src/luan/modules/PickleServer.java	Wed May 27 22:01:40 2015 -0600
@@ -46,7 +46,7 @@
 //e.printStackTrace();
 				StringBuilder sb = new StringBuilder();
 				sb.append( "return false, " );
-				sb.append( con.pickle(e.getFullMessage(con.luan)) );
+				sb.append( con.pickle(e.getFullMessage()) );
 				sb.append( ", " );
 				sb.append( con.pickle(con.src) );
 				sb.append( '\n' );
--- a/http/src/luan/modules/http/LuanHandler.java	Wed May 27 21:50:44 2015 -0600
+++ b/http/src/luan/modules/http/LuanHandler.java	Wed May 27 22:01:40 2015 -0600
@@ -31,7 +31,7 @@
 			if( !HttpServicer.service(luan,request,response,"site:"+target) )
 				return;
 		} catch(LuanException e) {
-			String err = e.getFullMessage(luan);
+			String err = e.getFullMessage();
 			logger.error(err);
 			response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,err);
 		}