Allow access to public members of private inner classes where possible
This commit is contained in:
@@ -47,12 +47,12 @@ import org.luaj.vm2.lib.DebugLib;
|
||||
* The behavior of coroutine threads matches closely the behavior
|
||||
* of C coroutine library. However, because of the use of Java threads
|
||||
* to manage call state, it is possible to yield from anywhere in luaj.
|
||||
* On the other hand, if a {@link LuaThread} is created, then yields
|
||||
* without ever entering a completed state, then the garbage collector
|
||||
* may not be able to determine that the thread needs to be collected,
|
||||
* and this could cause a memory and resource leak. It is recommended
|
||||
* that all coroutines that are created are resumed until they are in
|
||||
* a completed state.
|
||||
* <p>
|
||||
* Each Java thread wakes up at regular intervals and checks a weak reference
|
||||
* to determine if it can ever be resumed. If not, it throws
|
||||
* {@link OrphanedThread} which is an {@link java.lang.Error}.
|
||||
* Applications should not catch {@link OrphanedThread}, because it can break
|
||||
* the thread safety of luaj.
|
||||
*
|
||||
* @see LuaValue
|
||||
* @see JsePlatform
|
||||
@@ -64,7 +64,10 @@ public class LuaThread extends LuaValue {
|
||||
public static LuaValue s_metatable;
|
||||
|
||||
public static int coroutine_count = 0;
|
||||
|
||||
|
||||
/** Interval at which to check for lua threads that are no longer referenced.
|
||||
* This can be changed by Java startup code if desired.
|
||||
*/
|
||||
static long thread_orphan_check_interval = 30000;
|
||||
|
||||
private static final int STATUS_INITIAL = 0;
|
||||
|
||||
@@ -21,19 +21,20 @@
|
||||
******************************************************************************/
|
||||
package org.luaj.vm2;
|
||||
|
||||
|
||||
/**
|
||||
* Error sublcass that indicates a lua thread that is no longer referenced has been detected.
|
||||
*
|
||||
* The java thread in which this is thrown should correspond to a LuaThread being used as a
|
||||
* coroutine that could not possibly be resumed again because there are no more references
|
||||
* to the LuaThread with which it is associated. Rather than locking up resources forever,
|
||||
* this error is thrown, and should fall through all the way to the thread's run() method.
|
||||
*
|
||||
* Java code mixed with the luaj vm should not catch this error because it may occur when
|
||||
* the coroutine is not running, so any processing done during error handling could break
|
||||
* the thread-safety of the application because other lua processing could be going on in
|
||||
* a different thread.
|
||||
/**
|
||||
* {@link java.lang.Error} sublcass that indicates a lua thread that is no
|
||||
* longer referenced has been detected.
|
||||
* <p>
|
||||
* The java thread in which this is thrown should correspond to a
|
||||
* {@link LuaThread} being used as a coroutine that could not possibly be
|
||||
* resumed again because there are no more references to the LuaThread with
|
||||
* which it is associated. Rather than locking up resources forever, this error
|
||||
* is thrown, and should fall through all the way to the thread's {@link Thread.run}() method.
|
||||
* <p>
|
||||
* Java code mixed with the luaj vm should not catch this error because it may
|
||||
* occur when the coroutine is not running, so any processing done during error
|
||||
* handling could break the thread-safety of the application because other lua
|
||||
* processing could be going on in a different thread.
|
||||
*/
|
||||
public class OrphanedThread extends Error {
|
||||
|
||||
|
||||
@@ -76,9 +76,17 @@ class JavaClass extends JavaInstance implements CoerceJavaToLua.Coercion {
|
||||
if ( fields == null ) {
|
||||
Map m = new HashMap();
|
||||
Field[] f = ((Class)m_instance).getFields();
|
||||
for ( int i=0; i<f.length; i++ )
|
||||
if ( Modifier.isPublic(f[i].getModifiers()) )
|
||||
m.put( LuaValue.valueOf(f[i].getName()), f[i] );
|
||||
for ( int i=0; i<f.length; i++ ) {
|
||||
Field fi = f[i];
|
||||
if ( Modifier.isPublic(fi.getModifiers()) ) {
|
||||
m.put( LuaValue.valueOf(fi.getName()), fi );
|
||||
try {
|
||||
if (!fi.isAccessible())
|
||||
fi.setAccessible(true);
|
||||
} catch (SecurityException s) {
|
||||
}
|
||||
}
|
||||
}
|
||||
fields = m;
|
||||
}
|
||||
return (Field) fields.get(key);
|
||||
|
||||
@@ -63,6 +63,11 @@ class JavaMethod extends JavaMember {
|
||||
private JavaMethod(Method m) {
|
||||
super( m.getParameterTypes(), m.getModifiers() );
|
||||
this.method = m;
|
||||
try {
|
||||
if (!m.isAccessible())
|
||||
m.setAccessible(true);
|
||||
} catch (SecurityException s) {
|
||||
}
|
||||
}
|
||||
|
||||
public LuaValue call() {
|
||||
|
||||
Reference in New Issue
Block a user