Mercurial Hosting > luan
changeset 783:4083f5a67c63
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 30 Aug 2016 12:00:38 -0600 |
parents | 655280eab1e2 |
children | 6a7c6879158d |
files | src/luan/LuanException.java src/luan/LuanJavaFunction.java src/luan/modules/JavaLuan.java |
diffstat | 3 files changed, 26 insertions(+), 46 deletions(-) [+] |
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; }
--- a/src/luan/LuanJavaFunction.java Tue Aug 30 01:29:33 2016 -0600 +++ b/src/luan/LuanJavaFunction.java Tue Aug 30 12:00:38 2016 -0600 @@ -42,29 +42,13 @@ this.varArgCls = null; } } -/* - private LuanJavaFunction(LuanJavaFunction f) { - this.method = f.method; - this.rtnConverter = f.rtnConverter; - this.takesLuaState = f.takesLuaState; - this.argConverters = f.argConverters; - this.varArgCls = f.varArgCls; - } - @Override public LuanJavaFunction shallowClone() { - return obj==null ? this : new LuanJavaFunction(this); - } - - @Override public void deepenClone(LuanJavaFunction clone,DeepCloner cloner) { - clone.obj = cloner.get(obj); - } -*/ @Override public String toString() { return "java-function: " + method; } - public Class[] getParameterTypes() { - return method.getParameterTypes(); + public int getParameterCount() { + return argConverters.length; } @Override public Object call(LuanState luan,Object[] args) throws LuanException { @@ -115,7 +99,7 @@ } private void checkArgs(Object[] args) throws LuanException { - Class[] a = getParameterTypes(); + Class[] a = method.getParameterTypes(); int start = takesLuaState ? 1 : 0; for( int i=start; i<a.length; i++ ) { Class paramType = a[i];
--- a/src/luan/modules/JavaLuan.java Tue Aug 30 01:29:33 2016 -0600 +++ b/src/luan/modules/JavaLuan.java Tue Aug 30 12:00:38 2016 -0600 @@ -364,7 +364,7 @@ AmbiguousJavaFunction(List<LuanJavaFunction> fns) { for( LuanJavaFunction fn : fns ) { - Integer n = fn.getParameterTypes().length; + Integer n = fn.getParameterCount(); List<LuanJavaFunction> list = fnMap.get(n); if( list==null ) { list = new ArrayList<LuanJavaFunction>();