Mercurial Hosting > luan
changeset 517:8dcf9e12446b
add Luan.on_luan_close()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 27 May 2015 01:20:49 -0600 |
parents | 5752df8a67b5 |
children | a8445ce8879e |
files | core/src/luan/LuanException.java core/src/luan/LuanState.java core/src/luan/cmd_line.luan core/src/luan/modules/BasicLuan.java core/src/luan/modules/Luan.luan core/src/luan/modules/PickleServer.java http/src/luan/modules/http/LuanHandler.java http/src/luan/modules/http/NotFound.java lucene/src/luan/modules/lucene/Lucene.luan |
diffstat | 9 files changed, 36 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/core/src/luan/LuanException.java Tue May 26 20:59:05 2015 -0600 +++ b/core/src/luan/LuanException.java Wed May 27 01:20:49 2015 -0600 @@ -13,6 +13,7 @@ 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); for( StackTraceElement ste : bit.stackTrace() ) { LuanTable tbl = new LuanTable();
--- a/core/src/luan/LuanState.java Tue May 26 20:59:05 2015 -0600 +++ b/core/src/luan/LuanState.java Wed May 27 01:20:49 2015 -0600 @@ -13,6 +13,7 @@ final List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>(); private Map registry; + private final List<LuanFunction> onClose = new ArrayList<LuanFunction>(); protected LuanState() { registry = new HashMap(); @@ -32,6 +33,17 @@ return registry; } + public void onClose(LuanFunction fn) { + onClose.add(fn); + } + + public void close() throws LuanException { + for( LuanFunction fn : onClose ) { + call(fn); + } + onClose.clear(); + } + public static LuanState newInstance() { return LuanCompiler.newLuanState(); }
--- a/core/src/luan/cmd_line.luan Tue May 26 20:59:05 2015 -0600 +++ b/core/src/luan/cmd_line.luan Wed May 27 01:20:49 2015 -0600 @@ -24,7 +24,7 @@ Debug.print_if_something( main_file( Table.unpack(Luan.arg) ) ) end; catch = function(e) --- java(); e.printStackTrace(); return +-- java(); e.java.printStackTrace(); return Io.print_to(Io.stderr, e ) end; }
--- a/core/src/luan/modules/BasicLuan.java Tue May 26 20:59:05 2015 -0600 +++ b/core/src/luan/modules/BasicLuan.java Wed May 27 01:20:49 2015 -0600 @@ -225,4 +225,8 @@ } } + public static void on_luan_close(LuanState luan,LuanFunction fn) { + luan.onClose(fn); + } + }
--- a/core/src/luan/modules/Luan.luan Tue May 26 20:59:05 2015 -0600 +++ b/core/src/luan/modules/Luan.luan Wed May 27 01:20:49 2015 -0600 @@ -15,6 +15,7 @@ M.load = BasicLuan.load M.load_file = BasicLuan.load_file M.new_error = BasicLuan.new_error +M.on_luan_close = BasicLuan.on_luan_close M.pairs = BasicLuan.pairs M.pcall = BasicLuan.pcall M.range = BasicLuan.range
--- a/core/src/luan/modules/PickleServer.java Tue May 26 20:59:05 2015 -0600 +++ b/core/src/luan/modules/PickleServer.java Wed May 27 01:20:49 2015 -0600 @@ -46,19 +46,10 @@ //e.printStackTrace(); StringBuilder sb = new StringBuilder(); sb.append( "return false, " ); - sb.append( con.pickle(e.getMessage()) ); + sb.append( con.pickle(e.getFullMessage(con.luan)) ); sb.append( ", " ); sb.append( con.pickle(con.src) ); sb.append( '\n' ); -/* - Throwable cause = e.getCause(); - if( cause != null ) { - sb.append( "\nCaused by: " ); - StringWriter sw = new StringWriter(); - cause.printStackTrace(new PrintWriter(sw)); - sb.append( sw ); - } -*/ con.write( sb.toString() ); } } catch(LuanException e2) {
--- a/http/src/luan/modules/http/LuanHandler.java Tue May 26 20:59:05 2015 -0600 +++ b/http/src/luan/modules/http/LuanHandler.java Wed May 27 01:20:49 2015 -0600 @@ -22,7 +22,7 @@ this.luan = luan; } - public void handle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response) + @Override public void handle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response) throws IOException { if( target.endsWith("/") ) @@ -41,4 +41,16 @@ public void setWelcomeFile(String welcomeFile) { this.welcomeFile = welcomeFile; } + + @Override protected void doStop() throws Exception { + luan.close(); +//System.out.println("qqqqqqqqqqqqqqqqqqqq doStop "+this); + super.doStop(); + } +/* + @Override public void destroy() { +System.out.println("qqqqqqqqqqqqqqqqqqqq destroy "+this); + super.destroy(); + } +*/ }
--- a/http/src/luan/modules/http/NotFound.java Tue May 26 20:59:05 2015 -0600 +++ b/http/src/luan/modules/http/NotFound.java Wed May 27 01:20:49 2015 -0600 @@ -13,7 +13,7 @@ super(luan); } - public void handle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response) + @Override public void handle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response) throws IOException { super.handle("/not_found",baseRequest,request,response);
--- a/lucene/src/luan/modules/lucene/Lucene.luan Tue May 26 20:59:05 2015 -0600 +++ b/lucene/src/luan/modules/lucene/Lucene.luan Wed May 27 01:20:49 2015 -0600 @@ -28,6 +28,8 @@ index.map_field_name = java_index.map_field_name index.close = java_index.close + Luan.on_luan_close(index.close) + function index.save_document(doc) index.Writer( function(writer) writer.save_document(doc)