-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto-convert Java-Array to Lua-Table;fix the incorrection of java Num…
…ber to lua issue
- Loading branch information
Showing
28 changed files
with
105 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: com.naef.jnlua.console.LuaConsole | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
* $Id: Converter.java 121 2012-01-22 01:40:14Z [email protected] $ | ||
* See LICENSE.txt for license terms. | ||
*/ | ||
|
||
package com.naef.jnlua; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,11 @@ | |
* $Id: DefaultConverter.java 161 2012-10-06 13:53:02Z [email protected] $ | ||
* See LICENSE.txt for license terms. | ||
*/ | ||
|
||
package com.naef.jnlua; | ||
|
||
import com.naef.jnlua.util.AbstractTableList; | ||
import com.naef.jnlua.util.AbstractTableMap; | ||
import sun.misc.FloatingDecimal; | ||
|
||
import java.lang.reflect.Array; | ||
import java.math.BigDecimal; | ||
|
@@ -24,12 +24,10 @@ public class DefaultConverter implements Converter { | |
* Raw byte array. | ||
*/ | ||
private static final boolean RAW_BYTE_ARRAY = Boolean.parseBoolean(System.getProperty(DefaultConverter.class.getPackage().getName() + ".rawByteArray")); | ||
|
||
/** | ||
* Static instance. | ||
*/ | ||
private static final DefaultConverter INSTANCE = new DefaultConverter(); | ||
|
||
/** | ||
* Boolean distance map. | ||
*/ | ||
|
@@ -221,26 +219,44 @@ public void convert(LuaState luaState, Boolean booleanValue) { | |
}; | ||
JAVA_OBJECT_CONVERTERS.put(Boolean.class, booleanConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Boolean.TYPE, booleanConverter); | ||
JavaObjectConverter<Number> numberConverter = new JavaObjectConverter<Number>() { | ||
JavaObjectConverter<Number> doubleConverter = new JavaObjectConverter<Number>() { | ||
@Override | ||
public void convert(LuaState luaState, Number number) { | ||
luaState.pushNumber(number.doubleValue()); | ||
Double d=number.doubleValue(); | ||
switch (number.getClass().getSimpleName()) { | ||
case "Double": | ||
luaState.pushNumber((Double)number); | ||
break; | ||
case "Float": | ||
luaState.pushNumber(new FloatingDecimal((Float)number).doubleValue()); | ||
break; | ||
case "BigInteger": | ||
if(number.toString().equals(new BigInteger(d.toString()))) luaState.pushNumber(d); | ||
else luaState.pushString(number.toString()); | ||
break; | ||
case "BigDecimal": | ||
if(number.toString().equals(new BigDecimal(d).toString())) luaState.pushNumber(d); | ||
else luaState.pushString(number.toString()); | ||
break; | ||
default: | ||
luaState.pushNumber(d);; | ||
} | ||
} | ||
}; | ||
JAVA_OBJECT_CONVERTERS.put(Byte.class, numberConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Byte.TYPE, numberConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Short.class, numberConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Short.TYPE, numberConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Integer.class, numberConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Integer.TYPE, numberConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Long.class, numberConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Long.TYPE, numberConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Float.class, numberConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Float.TYPE, numberConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Double.class, numberConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Double.TYPE, numberConverter); | ||
JAVA_OBJECT_CONVERTERS.put(BigInteger.class, numberConverter); | ||
JAVA_OBJECT_CONVERTERS.put(BigDecimal.class, numberConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Byte.class, doubleConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Byte.TYPE, doubleConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Short.class, doubleConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Short.TYPE, doubleConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Integer.class, doubleConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Integer.TYPE, doubleConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Long.class, doubleConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Long.TYPE, doubleConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Double.class, doubleConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Double.TYPE, doubleConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Float.class, doubleConverter); | ||
JAVA_OBJECT_CONVERTERS.put(Float.TYPE, doubleConverter); | ||
JAVA_OBJECT_CONVERTERS.put(BigInteger.class, doubleConverter); | ||
JAVA_OBJECT_CONVERTERS.put(BigDecimal.class, doubleConverter); | ||
JavaObjectConverter<Character> characterConverter = new JavaObjectConverter<Character>() { | ||
@Override | ||
public void convert(LuaState luaState, Character character) { | ||
|
@@ -256,6 +272,19 @@ public void convert(LuaState luaState, String string) { | |
} | ||
}; | ||
JAVA_OBJECT_CONVERTERS.put(String.class, stringConverter); | ||
final JavaObjectConverter<Object[]> arrayConverter = new JavaObjectConverter<Object[]>() { | ||
@Override | ||
public void convert(LuaState luaState, Object[] obj) { | ||
luaState.newTable(obj.length, 0); | ||
for (int i = 0; i < obj.length; i++) { | ||
luaState.getConverter().convertJavaObject(luaState, obj[i]); | ||
luaState.rawSet(-2, i + 1); | ||
} | ||
} | ||
}; | ||
|
||
JAVA_OBJECT_CONVERTERS.put(Object[].class, arrayConverter); | ||
|
||
if (!RAW_BYTE_ARRAY) { | ||
JavaObjectConverter<byte[]> byteArrayConverter = new JavaObjectConverter<byte[]>() { | ||
@Override | ||
|
@@ -523,6 +552,13 @@ public void convertJavaObject(LuaState luaState, Object object) { | |
javaObjectConverter.convert(luaState, object); | ||
return; | ||
} | ||
|
||
if (object instanceof Object[]) { | ||
JavaObjectConverter<Object[]> converter = (JavaObjectConverter<Object[]>) JAVA_OBJECT_CONVERTERS.get(Object[].class); | ||
converter.convert(luaState, (Object[]) object); | ||
return; | ||
} | ||
|
||
if (object instanceof JavaFunction) { | ||
luaState.pushJavaFunction((JavaFunction) object); | ||
return; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
* $Id: DefaultJavaReflector.java 174 2013-07-28 20:46:22Z [email protected] $ | ||
* See LICENSE.txt for license terms. | ||
*/ | ||
|
||
package com.naef.jnlua; | ||
|
||
import java.beans.BeanInfo; | ||
|
@@ -23,7 +22,6 @@ public class DefaultJavaReflector implements JavaReflector { | |
private static final DefaultJavaReflector INSTANCE = new DefaultJavaReflector(); | ||
private static final Object JAVA_FUNCTION_TYPE = new Object(); | ||
private static final Object[] EMPTY_ARGUMENTS = new Object[0]; | ||
|
||
// -- State | ||
private Map<Class<?>, Map<String, Accessor>> accessors = new HashMap<Class<?>, Map<String, Accessor>>(); | ||
private ReadWriteLock accessorLock = new ReentrantReadWriteLock(); | ||
|
@@ -572,7 +570,6 @@ public String toString() { | |
private static class InvocableProxy implements Invocable { | ||
// -- Static | ||
private static final Class<?>[] PARAMETER_TYPES = new Class<?>[]{LuaValueProxy.class}; | ||
|
||
// -- State | ||
private Class<?> interfaze; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
* $Id: JavaFunction.java 121 2012-01-22 01:40:14Z [email protected] $ | ||
* See LICENSE.txt for license terms. | ||
*/ | ||
|
||
package com.naef.jnlua; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
* $Id: JavaModule.java 121 2012-01-22 01:40:14Z [email protected] $ | ||
* See LICENSE.txt for license terms. | ||
*/ | ||
|
||
package com.naef.jnlua; | ||
|
||
import com.naef.jnlua.JavaReflector.Metamethod; | ||
|
@@ -538,7 +537,6 @@ private static class LuaMap implements JavaReflector, TypedJavaObject { | |
// -- Static | ||
private static final JavaFunction INDEX = new Index(); | ||
private static final JavaFunction NEW_INDEX = new NewIndex(); | ||
|
||
// -- State | ||
private Map<Object, Object> map; | ||
|
||
|
@@ -639,7 +637,6 @@ private static class LuaList implements JavaReflector, TypedJavaObject { | |
private static final JavaFunction INDEX = new Index(); | ||
private static final JavaFunction NEW_INDEX = new NewIndex(); | ||
private static final JavaFunction LENGTH = new Length(); | ||
|
||
// -- State | ||
private List<Object> list; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
* $Id: JavaReflector.java 121 2012-01-22 01:40:14Z [email protected] $ | ||
* See LICENSE.txt for license terms. | ||
*/ | ||
|
||
package com.naef.jnlua; | ||
|
||
/** | ||
|
@@ -38,94 +37,58 @@ public enum Metamethod { | |
/** | ||
* <code>__index</code> metamethod. | ||
*/ | ||
INDEX, | ||
|
||
/** | ||
INDEX, /** | ||
* <code>__newindex</code> metamethod. | ||
*/ | ||
NEWINDEX, | ||
|
||
/** | ||
NEWINDEX, /** | ||
* <code>__len</code> metamethod. | ||
*/ | ||
LEN, | ||
|
||
/** | ||
LEN, /** | ||
* <code>__eq</code> metamethod. | ||
*/ | ||
EQ, | ||
|
||
/** | ||
EQ, /** | ||
* <code>__lt</code> metamethod. | ||
*/ | ||
LT, | ||
|
||
/** | ||
LT, /** | ||
* <code>__le</code> metamethod. | ||
*/ | ||
LE, | ||
|
||
/** | ||
LE, /** | ||
* <code>__unm</code> metamethod. | ||
*/ | ||
UNM, | ||
|
||
/** | ||
UNM, /** | ||
* <code>__add</code> metamethod. | ||
*/ | ||
ADD, | ||
|
||
/** | ||
ADD, /** | ||
* <code>__sub</code> metamethod. | ||
*/ | ||
SUB, | ||
|
||
/** | ||
SUB, /** | ||
* <code>__mul</code> metamethod. | ||
*/ | ||
MUL, | ||
|
||
/** | ||
MUL, /** | ||
* <code>__div</code> metamethod. | ||
*/ | ||
DIV, | ||
|
||
/** | ||
DIV, /** | ||
* <code>__mod</code> metamethod. | ||
*/ | ||
MOD, | ||
|
||
/** | ||
MOD, /** | ||
* <code>__pow</code> metamethod. | ||
*/ | ||
POW, | ||
|
||
/** | ||
POW, /** | ||
* <code>__concat</code> metamethod. | ||
*/ | ||
CONCAT, | ||
|
||
/** | ||
CONCAT, /** | ||
* <code>__call</code> metamethod. | ||
*/ | ||
CALL, | ||
|
||
/** | ||
CALL, /** | ||
* <code>__tostring</code> metamethod. | ||
*/ | ||
TOSTRING, | ||
|
||
/** | ||
TOSTRING, /** | ||
* <code>__javafields</code> metamethod. | ||
*/ | ||
JAVAFIELDS, | ||
|
||
/** | ||
JAVAFIELDS, /** | ||
* <code>__javamethods</code> metamethod. | ||
*/ | ||
JAVAMETHODS, | ||
|
||
/** | ||
JAVAMETHODS, /** | ||
* <code>__javaproperties</code> metamethod. | ||
*/ | ||
JAVAPROPERTIES; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
* $Id: LuaError.java 154 2012-02-01 20:40:01Z [email protected] $ | ||
* See LICENSE.txt for license terms. | ||
*/ | ||
|
||
package com.naef.jnlua; | ||
|
||
import java.io.PrintWriter; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
* $Id: LuaException.java 121 2012-01-22 01:40:14Z [email protected] $ | ||
* See LICENSE.txt for license terms. | ||
*/ | ||
|
||
package com.naef.jnlua; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
* $Id$ | ||
* See LICENSE.txt for license terms. | ||
*/ | ||
|
||
package com.naef.jnlua; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
* $Id: LuaMemoryAllocationException.java 121 2012-01-22 01:40:14Z [email protected] $ | ||
* See LICENSE.txt for license terms. | ||
*/ | ||
|
||
package com.naef.jnlua; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
* $Id: LuaMessageHandlerException.java 121 2012-01-22 01:40:14Z [email protected] $ | ||
* See LICENSE.txt for license terms. | ||
*/ | ||
|
||
package com.naef.jnlua; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
* $Id: LuaRuntimeException.java 121 2012-01-22 01:40:14Z [email protected] $ | ||
* See LICENSE.txt for license terms. | ||
*/ | ||
|
||
package com.naef.jnlua; | ||
|
||
import java.io.PrintStream; | ||
|
@@ -21,7 +20,6 @@ public class LuaRuntimeException extends LuaException { | |
// -- Static | ||
private static final long serialVersionUID = 1L; | ||
private static final LuaStackTraceElement[] EMPTY_LUA_STACK_TRACE = new LuaStackTraceElement[0]; | ||
|
||
// -- State | ||
private LuaStackTraceElement[] luaStackTrace; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
* $Id: LuaStackTraceElement.java 121 2012-01-22 01:40:14Z [email protected] $ | ||
* See LICENSE.txt for license terms. | ||
*/ | ||
|
||
package com.naef.jnlua; | ||
|
||
/** | ||
|
Oops, something went wrong.