comparison src/luan/LuanException.java @ 1283:503bde9a7c80

add luan.require() and table.call()
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 21 Dec 2018 09:12:09 -0700
parents 2531942abaf3
children f41919741100
comparison
equal deleted inserted replaced
1282:2531942abaf3 1283:503bde9a7c80
31 clone.table = (LuanTable)cloner.clone(table); 31 clone.table = (LuanTable)cloner.clone(table);
32 } 32 }
33 33
34 public LuanTable table(LuanState luan) { 34 public LuanTable table(LuanState luan) {
35 if( table==null ) { 35 if( table==null ) {
36 table = new LuanTable(luan);
37 table.rawPut( "java", this );
38 LuanTable metatable = new LuanTable(luan);
39 table.setMetatable(metatable);
40 try { 36 try {
41 table.rawPut( "get_message", new LuanJavaFunction( 37 LuanTable Boot = (LuanTable)luan.require("luan:Boot.luan");
42 LuanException.class.getMethod( "getMessage" ), this 38 table = (LuanTable)Boot.call( "new_error_table", this );
43 ) ); 39 } catch(LuanException e) {
44 table.rawPut( "throw", new LuanJavaFunction(
45 LuanException.class.getMethod( "throwThis" ), this
46 ) );
47 table.rawPut( "get_stack_trace_string", new LuanJavaFunction(
48 LuanException.class.getMethod( "getLuanStackTraceString" ), this
49 ) );
50 table.rawPut( "get_java_stack_trace_string", new LuanJavaFunction(
51 LuanException.class.getMethod( "getJavaStackTraceString" ), this
52 ) );
53 metatable.rawPut( "__to_string", new LuanJavaFunction(
54 LuanException.class.getMethod( "__to_string", LuanTable.class ), this
55 ) );
56 } catch(NoSuchMethodException e) {
57 throw new RuntimeException(e); 40 throw new RuntimeException(e);
58 } 41 }
59 } 42 }
60 return table; 43 return table;
61 } 44 }
62 45
63 public void throwThis() throws LuanException { 46 public void throwThis() throws LuanException {
64 throw this; 47 throw this;
65 }
66
67 public String __to_string(LuanTable ignore) {
68 return getLuanStackTraceString();
69 } 48 }
70 49
71 public String getJavaStackTraceString() { 50 public String getJavaStackTraceString() {
72 return getJavaStackTraceString(this); 51 return getJavaStackTraceString(this);
73 } 52 }