Mercurial Hosting > luan
diff src/luan/LuanException.java @ 783:4083f5a67c63
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 30 Aug 2016 12:00:38 -0600 |
parents | 655280eab1e2 |
children | 6a7c6879158d |
line wrap: on
line diff
--- a/src/luan/LuanException.java Tue Aug 30 01:29:33 2016 -0600 +++ b/src/luan/LuanException.java Tue Aug 30 12:00:38 2016 -0600 @@ -11,17 +11,14 @@ public LuanException(String msg,Throwable cause) { super(msg,cause); - initTable(); } public LuanException(String msg) { super(msg); - initTable(); } public LuanException(Throwable cause) { super(cause); - initTable(); } private LuanException(String msg,Throwable cause,int nonsense) { @@ -38,32 +35,31 @@ } public LuanTable table() { + if( table==null ) { + table = new LuanTable(); + table.rawPut( "java", this ); + LuanTable metatable = new LuanTable(); + table.setMetatable(metatable); + try { + table.rawPut( "get_message", new LuanJavaFunction( + LuanException.class.getMethod( "getMessage" ), this + ) ); + table.rawPut( "throw", new LuanJavaFunction( + LuanException.class.getMethod( "throwThis" ), this + ) ); + table.rawPut( "get_java_stack_trace_string", new LuanJavaFunction( + LuanException.class.getMethod( "getJavaStackTraceString" ), this + ) ); + metatable.rawPut( "__to_string", new LuanJavaFunction( + LuanException.class.getMethod( "getFullMessage" ), this + ) ); + } catch(NoSuchMethodException e) { + throw new RuntimeException(e); + } + } return table; } - private void initTable() { - table = new LuanTable(); - table.rawPut( "java", this ); - LuanTable metatable = new LuanTable(); - table.setMetatable(metatable); - try { - table.rawPut( "get_message", new LuanJavaFunction( - LuanException.class.getMethod( "getMessage" ), this - ) ); - table.rawPut( "throw", new LuanJavaFunction( - LuanException.class.getMethod( "throwThis" ), this - ) ); - table.rawPut( "get_java_stack_trace_string", new LuanJavaFunction( - LuanException.class.getMethod( "getJavaStackTraceString" ), this - ) ); - metatable.rawPut( "__to_string", new LuanJavaFunction( - LuanException.class.getMethod( "getFullMessage" ), this - ) ); - } catch(NoSuchMethodException e) { - throw new RuntimeException(e); - } - } - public void throwThis() throws LuanException { throw this; }