diff --git a/cldc11/src/se/krka/kahlua/cldc11/MathLib.java b/cldc11/src/se/krka/kahlua/cldc11/MathLib.java index 94c3140..9751887 100644 --- a/cldc11/src/se/krka/kahlua/cldc11/MathLib.java +++ b/cldc11/src/se/krka/kahlua/cldc11/MathLib.java @@ -393,11 +393,7 @@ private static int ldexp(LuaCallFrame callFrame, int nArguments) { return 1; } - - - - - public static final double EPS = 1e-15; + private static final double EPS = 1e-15; /* * Simple implementation of the taylor expansion of @@ -502,19 +498,19 @@ public static double ipow(double base, int exponent) { // constants - static final double sq2p1 = 2.414213562373095048802e0; - static final double sq2m1 = .414213562373095048802e0; - static final double p4 = .161536412982230228262e2; - static final double p3 = .26842548195503973794141e3; - static final double p2 = .11530293515404850115428136e4; - static final double p1 = .178040631643319697105464587e4; - static final double p0 = .89678597403663861959987488e3; - static final double q4 = .5895697050844462222791e2; - static final double q3 = .536265374031215315104235e3; - static final double q2 = .16667838148816337184521798e4; - static final double q1 = .207933497444540981287275926e4; - static final double q0 = .89678597403663861962481162e3; - static final double PIO2 = 1.5707963267948966135E0; + private static final double sq2p1 = 2.414213562373095048802e0; + private static final double sq2m1 = .414213562373095048802e0; + private static final double p4 = .161536412982230228262e2; + private static final double p3 = .26842548195503973794141e3; + private static final double p2 = .11530293515404850115428136e4; + private static final double p1 = .178040631643319697105464587e4; + private static final double p0 = .89678597403663861959987488e3; + private static final double q4 = .5895697050844462222791e2; + private static final double q3 = .536265374031215315104235e3; + private static final double q2 = .16667838148816337184521798e4; + private static final double q1 = .207933497444540981287275926e4; + private static final double q0 = .89678597403663861962481162e3; + private static final double PIO2 = 1.5707963267948966135E0; // reduce private static double mxatan(double arg) diff --git a/core/src/se/krka/kahlua/stdlib/BaseLib.java b/core/src/se/krka/kahlua/stdlib/BaseLib.java index 482ace0..466b62d 100644 --- a/core/src/se/krka/kahlua/stdlib/BaseLib.java +++ b/core/src/se/krka/kahlua/stdlib/BaseLib.java @@ -179,7 +179,7 @@ private int rawequal(LuaCallFrame callFrame, int nArguments) { Object o1 = callFrame.get(0); Object o2 = callFrame.get(1); - callFrame.push(KahluaUtil.toBoolean(KahluaUtil.luaEquals(o1, o2))); + callFrame.push(KahluaUtil.toBoolean(luaEquals(o1, o2))); return 1; } @@ -460,5 +460,16 @@ private static int bytecodeloader(LuaCallFrame callFrame, int nArguments) { return callFrame.push("Could not find the bytecode for '" + modname + "' in classpath"); } - + /** @exclude */ + public static boolean luaEquals(Object a, Object b) { + if (a == null || b == null) { + return a == b; + } + if (a instanceof Double && b instanceof Double) { + Double ad = (Double) a; + Double bd = (Double) b; + return ad.doubleValue() == bd.doubleValue(); + } + return a == b; + } } diff --git a/core/src/se/krka/kahlua/stdlib/CoroutineLib.java b/core/src/se/krka/kahlua/stdlib/CoroutineLib.java index 3997309..b11db34 100644 --- a/core/src/se/krka/kahlua/stdlib/CoroutineLib.java +++ b/core/src/se/krka/kahlua/stdlib/CoroutineLib.java @@ -167,7 +167,7 @@ private int resume(LuaCallFrame callFrame, int nArguments) { return 0; } - public static int yield(LuaCallFrame callFrame, int nArguments) { + private static int yield(LuaCallFrame callFrame, int nArguments) { Coroutine t = callFrame.coroutine; Coroutine parent = t.parent; diff --git a/core/src/se/krka/kahlua/stdlib/RandomLib.java b/core/src/se/krka/kahlua/stdlib/RandomLib.java index 8024df6..9cd0daf 100644 --- a/core/src/se/krka/kahlua/stdlib/RandomLib.java +++ b/core/src/se/krka/kahlua/stdlib/RandomLib.java @@ -54,7 +54,7 @@ public int call(LuaCallFrame callFrame, int nArguments) { } private int randomSeed(LuaCallFrame callFrame, int nArguments) { - Random random = getRandom(callFrame, nArguments); + Random random = getRandom(callFrame, "seed"); Object o = callFrame.get(1); int hashCode = o == null ? 0 : o.hashCode(); random.setSeed(hashCode); @@ -62,41 +62,33 @@ private int randomSeed(LuaCallFrame callFrame, int nArguments) { } private int random(LuaCallFrame callFrame, int nArguments) { - Random random = getRandom(callFrame, nArguments); - - if (nArguments <= 1) { - return callFrame.push(KahluaUtil.toDouble(random.nextDouble())); - } - - double tmp = KahluaUtil.getDoubleArg(callFrame, 2, names[RANDOM]); - int m = (int) tmp; - int n; - if (nArguments == 2) { - n = m; - m = 1; - } else { - tmp = KahluaUtil.getDoubleArg(callFrame, 3, names[RANDOM]); - n = (int) tmp; - } + Random random = getRandom(callFrame, "random"); + + Double min = KahluaUtil.getOptionalNumberArg(callFrame, 2); + Double max = KahluaUtil.getOptionalNumberArg(callFrame, 3); + if (min == null) { + return callFrame.push(KahluaUtil.toDouble(random.nextDouble())); + } + int m = min.intValue(); + int n; + if (max == null) { + n = m; + m = 1; + } else { + n = max.intValue(); + } return callFrame.push(KahluaUtil.toDouble(m + random.nextInt(n - m + 1))); } - private Random getRandom(LuaCallFrame callFrame, int nArguments) { - Random random = null; - if (nArguments > 0) { - Object o = callFrame.get(0); - if (o instanceof Random) { - random = (Random) o; - } - } - if (random == null) { - KahluaUtil.fail("First argument must be an object of type random."); - } - return random; + private Random getRandom(LuaCallFrame callFrame, String name) { + Object obj = KahluaUtil.getArg(callFrame, 1, name); + if (!(obj instanceof Random)) { + KahluaUtil.fail("First argument to " + name + " must be an object of type random."); + } + return (Random) obj; } private int newRandom(LuaCallFrame callFrame) { - Random random = new Random(); - return callFrame.push(random); + return callFrame.push(new Random()); } } diff --git a/core/src/se/krka/kahlua/stdlib/StringLib.java b/core/src/se/krka/kahlua/stdlib/StringLib.java index 6ff657a..5b0383b 100644 --- a/core/src/se/krka/kahlua/stdlib/StringLib.java +++ b/core/src/se/krka/kahlua/stdlib/StringLib.java @@ -52,10 +52,10 @@ public final class StringLib implements JavaFunction { private static final int CAP_POSITION = ( -2 ); private static final String[] names; - private static final StringLib[] functions; + private static final StringLib[] functions; // NOTE: String.class won't work in J2ME - so this is used as a workaround - public static final Class STRING_CLASS = "".getClass(); + private static final Class STRING_CLASS = "".getClass(); static { names = new String[NUM_FUNCTIONS]; @@ -76,6 +76,7 @@ public final class StringLib implements JavaFunction { } } + /** @exclude */ private final int methodId; public StringLib(int index) { this.methodId = index; @@ -808,6 +809,7 @@ public static double roundToSignificantNumbers(double x, int precision) { * Original code that this was adapted from is copyright (c) 2008 groundspeak, inc. */ + /** @exclude */ public static class MatchState { public final LuaCallFrame callFrame; public final StringPointer src_init; /* init of source string */ @@ -827,6 +829,7 @@ public MatchState(LuaCallFrame callFrame, StringPointer srcInit, int endIndex) { public int level; /* total number of captures (finished or unfinished) */ + /** @exclude */ public static class Capture { public StringPointer init; public int len; @@ -844,6 +847,7 @@ public Object getCapture(int i) { } } + /** @exclude */ public static class StringPointer { private final String string; private int index = 0; @@ -1413,11 +1417,12 @@ private static int gsub(LuaCallFrame cf, int nargs) { pattern.postIncrString ( 1 ); } - String replType = KahluaUtil.type(repl); - if (!(replType == KahluaUtil.TYPE_FUNCTION || - replType == KahluaUtil.TYPE_STRING || - replType == KahluaUtil.TYPE_TABLE)) { - KahluaUtil.fail(("string/function/table expected, got "+replType)); + if (!(repl instanceof Double || + repl instanceof String || + repl instanceof LuaClosure || + repl instanceof JavaFunction || + repl instanceof KahluaTable )) { + KahluaUtil.fail(("string/function/table expected, got " + repl)); } MatchState ms = new MatchState(cf, src.getClone(), src.length()); @@ -1448,9 +1453,9 @@ private static int gsub(LuaCallFrame cf, int nargs) { } private static void addValue(MatchState ms, Object repl, StringBuffer b, StringPointer src, StringPointer e) { - String type = KahluaUtil.type(repl); - if (type == KahluaUtil.TYPE_NUMBER || type == KahluaUtil.TYPE_STRING) { - b.append(addString(ms, repl, src, e)); + String replString = KahluaUtil.rawTostring(repl); + if (replString != null) { + b.append(addString(ms, replString, src, e)); } else { Object captures = ms.getCapture(0); String match; @@ -1460,10 +1465,10 @@ private static void addValue(MatchState ms, Object repl, StringBuffer b, StringP match = src.getStringSubString(e.getIndex() - src.getIndex()); } Object res = null; - if (type == KahluaUtil.TYPE_FUNCTION) { - res = ms.callFrame.coroutine.thread.call(repl, match, null, null); - } else if (type == KahluaUtil.TYPE_TABLE) { + if (repl instanceof KahluaTable) { res = ((KahluaTable)repl).rawget(match); + } else { + res = ms.callFrame.coroutine.thread.call(repl, match, null, null); } if (res == null) { res = match; @@ -1472,11 +1477,10 @@ private static void addValue(MatchState ms, Object repl, StringBuffer b, StringP } } - private static String addString(MatchState ms, Object repl, StringPointer s, StringPointer e) { - String replTemp = KahluaUtil.tostring(repl, ms.callFrame.coroutine.thread); - StringPointer replStr = new StringPointer(replTemp); + private static String addString(MatchState ms, String repl, StringPointer s, StringPointer e) { + StringPointer replStr = new StringPointer(repl); StringBuffer buf = new StringBuffer(); - for (int i = 0; i < replTemp.length(); i++) { + for (int i = 0; i < repl.length(); i++) { char c = replStr.getChar(i); if (c != L_ESC) { buf.append(c); diff --git a/core/src/se/krka/kahlua/vm/JavaFunction.java b/core/src/se/krka/kahlua/vm/JavaFunction.java index 8e552c3..6a4f1ce 100644 --- a/core/src/se/krka/kahlua/vm/JavaFunction.java +++ b/core/src/se/krka/kahlua/vm/JavaFunction.java @@ -25,16 +25,21 @@ of this software and associated documentation files (the "Software"), to deal public interface JavaFunction { /** - * General contract.
- *
- * Input:
- * callFrame = the frame that contains all the arguments, and where all the results should be put.
- * nArguments = number of function arguments
- * callFrame.get(i) = an argument (0 <= i < nArgs)
- * - * @param callFrame - the current callframe for the function + * This interface defines functions which the Kahlua engine can call. + * + * General contract: + *
+	 *  callFrame.get(i) = an argument (0 <= i < nArguments)
+ *
+ * Return (possibly) values to lua by calling: + *
+	 *  callFrame.push(value1);
+	 *  callFrame.push(value2);
+	 *  return 2; // number of pushed values
+	 * 
+ * @param callFrame - the frame that contains all the arguments and where all the results should be put. * @param nArguments - number of function arguments - * @return N - number of return values. The top N objects on the stack are considered the return values + * @return N, number of return values. The top N objects on the stack are considered the return values. */ public abstract int call(LuaCallFrame callFrame, int nArguments); } diff --git a/core/src/se/krka/kahlua/vm/KahluaThread.java b/core/src/se/krka/kahlua/vm/KahluaThread.java index 5e4065a..bb9abe4 100644 --- a/core/src/se/krka/kahlua/vm/KahluaThread.java +++ b/core/src/se/krka/kahlua/vm/KahluaThread.java @@ -21,91 +21,52 @@ of this software and associated documentation files (the "Software"), to deal */ package se.krka.kahlua.vm; +import se.krka.kahlua.stdlib.BaseLib; + import java.io.PrintStream; public class KahluaThread { - /** @exclude */ - public static final int FIELDS_PER_FLUSH = 50; - /** @exclude */ - public static final int OP_MOVE = 0; - /** @exclude */ - public static final int OP_LOADK = 1; - /** @exclude */ - public static final int OP_LOADBOOL = 2; - /** @exclude */ - public static final int OP_LOADNIL = 3; - /** @exclude */ - public static final int OP_GETUPVAL = 4; - /** @exclude */ - public static final int OP_GETGLOBAL = 5; - /** @exclude */ - public static final int OP_GETTABLE = 6; - /** @exclude */ - public static final int OP_SETGLOBAL = 7; - /** @exclude */ - public static final int OP_SETUPVAL = 8; - /** @exclude */ - public static final int OP_SETTABLE = 9; - /** @exclude */ - public static final int OP_NEWTABLE = 10; - /** @exclude */ - public static final int OP_SELF = 11; - /** @exclude */ - public static final int OP_ADD = 12; - /** @exclude */ - public static final int OP_SUB = 13; - /** @exclude */ - public static final int OP_MUL = 14; - /** @exclude */ - public static final int OP_DIV = 15; - /** @exclude */ - public static final int OP_MOD = 16; - /** @exclude */ - public static final int OP_POW = 17; - /** @exclude */ - public static final int OP_UNM = 18; - /** @exclude */ - public static final int OP_NOT = 19; - /** @exclude */ - public static final int OP_LEN = 20; - /** @exclude */ - public static final int OP_CONCAT = 21; - /** @exclude */ - public static final int OP_JMP = 22; - /** @exclude */ - public static final int OP_EQ = 23; - /** @exclude */ - public static final int OP_LT = 24; - /** @exclude */ - public static final int OP_LE = 25; - /** @exclude */ - public static final int OP_TEST = 26; - /** @exclude */ - public static final int OP_TESTSET = 27; - /** @exclude */ - public static final int OP_CALL = 28; - /** @exclude */ - public static final int OP_TAILCALL = 29; - /** @exclude */ - public static final int OP_RETURN = 30; - /** @exclude */ - public static final int OP_FORLOOP = 31; - /** @exclude */ - public static final int OP_FORPREP = 32; - /** @exclude */ - public static final int OP_TFORLOOP = 33; - /** @exclude */ - public static final int OP_SETLIST = 34; - /** @exclude */ - public static final int OP_CLOSE = 35; - /** @exclude */ - public static final int OP_CLOSURE = 36; - /** @exclude */ - public static final int OP_VARARG = 37; - /** @exclude */ + private static final int FIELDS_PER_FLUSH = 50; + private static final int OP_MOVE = 0; + private static final int OP_LOADK = 1; + private static final int OP_LOADBOOL = 2; + private static final int OP_LOADNIL = 3; + private static final int OP_GETUPVAL = 4; + private static final int OP_GETGLOBAL = 5; + private static final int OP_GETTABLE = 6; + private static final int OP_SETGLOBAL = 7; + private static final int OP_SETUPVAL = 8; + private static final int OP_SETTABLE = 9; + private static final int OP_NEWTABLE = 10; + private static final int OP_SELF = 11; + private static final int OP_ADD = 12; + private static final int OP_SUB = 13; + private static final int OP_MUL = 14; + private static final int OP_DIV = 15; + private static final int OP_MOD = 16; + private static final int OP_POW = 17; + private static final int OP_UNM = 18; + private static final int OP_NOT = 19; + private static final int OP_LEN = 20; + private static final int OP_CONCAT = 21; + private static final int OP_JMP = 22; + private static final int OP_EQ = 23; + private static final int OP_LT = 24; + private static final int OP_LE = 25; + private static final int OP_TEST = 26; + private static final int OP_TESTSET = 27; + private static final int OP_CALL = 28; + private static final int OP_TAILCALL = 29; + private static final int OP_RETURN = 30; + private static final int OP_FORLOOP = 31; + private static final int OP_FORPREP = 32; + private static final int OP_TFORLOOP = 33; + private static final int OP_SETLIST = 34; + private static final int OP_CLOSE = 35; + private static final int OP_CLOSURE = 36; + private static final int OP_VARARG = 37; private static final int MAX_INDEX_RECURSION = 100; - /** @exclude */ private static final String meta_ops[]; static { meta_ops = new String[38]; @@ -123,9 +84,7 @@ public class KahluaThread { /** @exclude */ public Coroutine currentCoroutine; - /** @exclude */ private final PrintStream out; - /** @exclude */ private final Platform platform; public KahluaThread(Platform platform, KahluaTable environment) { @@ -555,7 +514,7 @@ private final void luaMainloop() { } if (metafun == null && opcode == OP_EQ) { - resBool = KahluaUtil.luaEquals(bo, co); + resBool = BaseLib.luaEquals(bo, co); } else { if (metafun == null) { KahluaUtil.fail((meta_op + " not defined for operand")); diff --git a/core/src/se/krka/kahlua/vm/KahluaUtil.java b/core/src/se/krka/kahlua/vm/KahluaUtil.java index 5ceba1d..4134199 100644 --- a/core/src/se/krka/kahlua/vm/KahluaUtil.java +++ b/core/src/se/krka/kahlua/vm/KahluaUtil.java @@ -4,27 +4,24 @@ import java.io.InputStream; public class KahluaUtil { - public static final Object WORKER_THREAD_KEY = new Object(); - public static final String TYPE_NIL = "nil"; - public static final String TYPE_STRING = "string"; - public static final String TYPE_NUMBER = "number"; - public static final String TYPE_BOOLEAN = "boolean"; - public static final String TYPE_FUNCTION = "function"; - public static final String TYPE_TABLE = "table"; - public static final String TYPE_COROUTINE = "coroutine"; - public static final String TYPE_USERDATA = "userdata"; - - public static boolean luaEquals(Object a, Object b) { - if (a == null || b == null) { - return a == b; - } - if (a instanceof Double && b instanceof Double) { - Double ad = (Double) a; - Double bd = (Double) b; - return ad.doubleValue() == bd.doubleValue(); - } - return a == b; - } + /** @exclude */ + private static final Object WORKER_THREAD_KEY = new Object(); + /** @exclude */ + private static final String TYPE_NIL = "nil"; + /** @exclude */ + private static final String TYPE_STRING = "string"; + /** @exclude */ + private static final String TYPE_NUMBER = "number"; + /** @exclude */ + private static final String TYPE_BOOLEAN = "boolean"; + /** @exclude */ + private static final String TYPE_FUNCTION = "function"; + /** @exclude */ + private static final String TYPE_TABLE = "table"; + /** @exclude */ + private static final String TYPE_COROUTINE = "coroutine"; + /** @exclude */ + private static final String TYPE_USERDATA = "userdata"; public static double fromDouble(Object o) { return ((Double) o).doubleValue(); @@ -122,6 +119,9 @@ public static KahluaThread getWorkerThread(Platform platform, KahluaTable env) { return (KahluaThread) workerThread; } + public static void setWorkerThread(KahluaTable env, KahluaThread thread) { + env.rawset(WORKER_THREAD_KEY, thread); + } public static KahluaTable getOrCreateTable(Platform platform, KahluaTable env, String name) { @@ -317,7 +317,7 @@ public static Object getArg(LuaCallFrame callFrame, int n, String function) { if (res == null) { throw new RuntimeException("missing argument #" + n + "to '" + function + "'"); } - return callFrame.get(n - 1); + return res; } public static int len(KahluaTable kahluaTable, int low, int high) { diff --git a/j2se/src/se/krka/kahlua/integration/LuaFail.java b/j2se/src/se/krka/kahlua/integration/LuaFail.java index a156749..0a0eb07 100644 --- a/j2se/src/se/krka/kahlua/integration/LuaFail.java +++ b/j2se/src/se/krka/kahlua/integration/LuaFail.java @@ -25,6 +25,7 @@ of this software and associated documentation files (the "Software"), to deal import se.krka.kahlua.vm.KahluaUtil; +/** @exclude */ public class LuaFail extends LuaReturn { LuaFail(Object[] returnValues) { super(returnValues); diff --git a/j2se/src/se/krka/kahlua/integration/LuaReturn.java b/j2se/src/se/krka/kahlua/integration/LuaReturn.java index 312b9dc..d1acbad 100644 --- a/j2se/src/se/krka/kahlua/integration/LuaReturn.java +++ b/j2se/src/se/krka/kahlua/integration/LuaReturn.java @@ -25,6 +25,7 @@ of this software and associated documentation files (the "Software"), to deal import java.util.AbstractList; public abstract class LuaReturn extends AbstractList { + /** @exclude */ protected final Object[] returnValues; protected LuaReturn(Object[] returnValues) { @@ -54,12 +55,12 @@ public Object getThird() { } @Override - public Object get(int index) { - int n = size(); - if (index < 0 || index >= n) { - throw new IndexOutOfBoundsException("The index " + index + " is outside the bounds [" + 0 + public Object get(int index) { + int n = size(); + if (index < 0 || index >= n) { + throw new IndexOutOfBoundsException("The index " + index + " is outside the bounds [" + 0 + ", " + n + ")"); - } + } return returnValues[index + 1]; } diff --git a/j2se/src/se/krka/kahlua/integration/LuaSuccess.java b/j2se/src/se/krka/kahlua/integration/LuaSuccess.java index 44a80bf..c94e024 100644 --- a/j2se/src/se/krka/kahlua/integration/LuaSuccess.java +++ b/j2se/src/se/krka/kahlua/integration/LuaSuccess.java @@ -22,6 +22,7 @@ of this software and associated documentation files (the "Software"), to deal package se.krka.kahlua.integration; +/** @exclude */ public class LuaSuccess extends LuaReturn { LuaSuccess(Object[] returnValues) { super(returnValues); diff --git a/j2se/src/se/krka/kahlua/integration/expose/AnnotationUtil.java b/j2se/src/se/krka/kahlua/integration/expose/AnnotationUtil.java index 535f528..db38b1e 100644 --- a/j2se/src/se/krka/kahlua/integration/expose/AnnotationUtil.java +++ b/j2se/src/se/krka/kahlua/integration/expose/AnnotationUtil.java @@ -25,6 +25,7 @@ of this software and associated documentation files (the "Software"), to deal import java.lang.annotation.Annotation; import java.lang.reflect.Method; +/** @exclude */ public class AnnotationUtil { public static T getAnnotation(Method method, Class annotation) { return getAnnotation(method.getDeclaringClass(), method.getName(), method.getParameterTypes(), annotation); diff --git a/j2se/src/se/krka/kahlua/integration/expose/ClassDebugInformation.java b/j2se/src/se/krka/kahlua/integration/expose/ClassDebugInformation.java index 4bbebdb..bb4f532 100644 --- a/j2se/src/se/krka/kahlua/integration/expose/ClassDebugInformation.java +++ b/j2se/src/se/krka/kahlua/integration/expose/ClassDebugInformation.java @@ -33,6 +33,7 @@ of this software and associated documentation files (the "Software"), to deal import java.lang.reflect.*; import java.util.*; +/** @exclude */ public class ClassDebugInformation { private final Map methods = new HashMap(); diff --git a/j2se/src/se/krka/kahlua/integration/expose/LuaJavaClassExposer.java b/j2se/src/se/krka/kahlua/integration/expose/LuaJavaClassExposer.java index 0adc918..95fb45f 100644 --- a/j2se/src/se/krka/kahlua/integration/expose/LuaJavaClassExposer.java +++ b/j2se/src/se/krka/kahlua/integration/expose/LuaJavaClassExposer.java @@ -39,9 +39,11 @@ of this software and associated documentation files (the "Software"), to deal /** * A tool to automatically expose java classes and - * methods to a lua thread - * NOTE: This tool requires annotations (java 1.5 or higher) to work - * and is therefore not supported in J2ME. + * methods to a lua thread. + * + * NOTE: This tool requires annotations and reflection + * (java 1.5 or higher) to work + * and is therefore not supported in CLDC. */ public class LuaJavaClassExposer { private final static Object DEBUGINFO_KEY = new Object(); diff --git a/j2se/src/se/krka/kahlua/integration/expose/LuaJavaInvoker.java b/j2se/src/se/krka/kahlua/integration/expose/LuaJavaInvoker.java index 3f739aa..01038d4 100644 --- a/j2se/src/se/krka/kahlua/integration/expose/LuaJavaInvoker.java +++ b/j2se/src/se/krka/kahlua/integration/expose/LuaJavaInvoker.java @@ -31,6 +31,8 @@ of this software and associated documentation files (the "Software"), to deal import se.krka.kahlua.vm.LuaCallFrame; /** + * This is a JavaFunction that is an adapter for Java methods. + * *
  * Various variants:
  *
diff --git a/j2se/src/se/krka/kahlua/integration/expose/MethodArguments.java b/j2se/src/se/krka/kahlua/integration/expose/MethodArguments.java
index 434a53b..3182934 100644
--- a/j2se/src/se/krka/kahlua/integration/expose/MethodArguments.java
+++ b/j2se/src/se/krka/kahlua/integration/expose/MethodArguments.java
@@ -22,6 +22,7 @@ of this software and associated documentation files (the "Software"), to deal
 
 package se.krka.kahlua.integration.expose;
 
+/** @exclude */
 public class MethodArguments {
     private ReturnValues returnValues;
     private Object self;
diff --git a/j2se/src/se/krka/kahlua/integration/expose/MethodDebugInformation.java b/j2se/src/se/krka/kahlua/integration/expose/MethodDebugInformation.java
index c6066a5..8152c23 100644
--- a/j2se/src/se/krka/kahlua/integration/expose/MethodDebugInformation.java
+++ b/j2se/src/se/krka/kahlua/integration/expose/MethodDebugInformation.java
@@ -24,6 +24,7 @@ of this software and associated documentation files (the "Software"), to deal
 
 import java.util.List;
 
+/** @exclude */
 public class MethodDebugInformation {
     private final String luaName;
     private final boolean isMethod;
diff --git a/j2se/src/se/krka/kahlua/integration/expose/MethodParameter.java b/j2se/src/se/krka/kahlua/integration/expose/MethodParameter.java
index 0c168eb..5a57eb7 100644
--- a/j2se/src/se/krka/kahlua/integration/expose/MethodParameter.java
+++ b/j2se/src/se/krka/kahlua/integration/expose/MethodParameter.java
@@ -22,6 +22,7 @@ of this software and associated documentation files (the "Software"), to deal
 
 package se.krka.kahlua.integration.expose;
 
+/** @exclude */
 public class MethodParameter {
     private final String name;
     private final String type;
diff --git a/j2se/src/se/krka/kahlua/integration/expose/MultiLuaJavaInvoker.java b/j2se/src/se/krka/kahlua/integration/expose/MultiLuaJavaInvoker.java
index 4998a8f..310402c 100644
--- a/j2se/src/se/krka/kahlua/integration/expose/MultiLuaJavaInvoker.java
+++ b/j2se/src/se/krka/kahlua/integration/expose/MultiLuaJavaInvoker.java
@@ -30,6 +30,7 @@ of this software and associated documentation files (the "Software"), to deal
 import java.util.Comparator;
 import java.util.List;
 
+/** @exclude */
 public class MultiLuaJavaInvoker implements JavaFunction {
     private final List invokers = new ArrayList();
     private static final Comparator COMPARATOR = new Comparator() {
diff --git a/j2se/src/se/krka/kahlua/integration/expose/ReturnValues.java b/j2se/src/se/krka/kahlua/integration/expose/ReturnValues.java
index 3c740f7..8b39ab7 100644
--- a/j2se/src/se/krka/kahlua/integration/expose/ReturnValues.java
+++ b/j2se/src/se/krka/kahlua/integration/expose/ReturnValues.java
@@ -35,13 +35,13 @@ public class ReturnValues {
 		this.callFrame = callFrame;
 	}
 	
-	public ReturnValues push(Object o) {
-        args += callFrame.push(manager.fromJavaToLua(o));
+	public ReturnValues push(Object obj) {
+        args += callFrame.push(manager.fromJavaToLua(obj));
         return this;
 	}
 	
-	public ReturnValues push(Object... params) {
-		for (Object o: params) {
+	public ReturnValues push(Object... objects) {
+		for (Object o: objects) {
 			push(o);
 		}
 		return this;
diff --git a/j2se/src/se/krka/kahlua/integration/expose/TypeUtil.java b/j2se/src/se/krka/kahlua/integration/expose/TypeUtil.java
index 2e64130..0fe6759 100644
--- a/j2se/src/se/krka/kahlua/integration/expose/TypeUtil.java
+++ b/j2se/src/se/krka/kahlua/integration/expose/TypeUtil.java
@@ -26,6 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+/** @exclude */
 public class TypeUtil {
     private static final Pattern pattern = Pattern.compile("([\\.a-z0-9]*)\\.([A-Za-z][A-Za-z0-9_]*)");
     public static String removePackages(String s) {
diff --git a/j2se/src/se/krka/kahlua/integration/expose/caller/AbstractCaller.java b/j2se/src/se/krka/kahlua/integration/expose/caller/AbstractCaller.java
index 92ab2d9..8c33bd2 100644
--- a/j2se/src/se/krka/kahlua/integration/expose/caller/AbstractCaller.java
+++ b/j2se/src/se/krka/kahlua/integration/expose/caller/AbstractCaller.java
@@ -4,6 +4,7 @@
 
 import java.util.Arrays;
 
+/** @exclude */
 public abstract class AbstractCaller implements Caller {
     protected final Class[] parameters;
     protected final boolean needsMultipleReturnValues;
diff --git a/j2se/src/se/krka/kahlua/integration/expose/caller/Caller.java b/j2se/src/se/krka/kahlua/integration/expose/caller/Caller.java
index 3af9a71..3fae0de 100644
--- a/j2se/src/se/krka/kahlua/integration/expose/caller/Caller.java
+++ b/j2se/src/se/krka/kahlua/integration/expose/caller/Caller.java
@@ -26,6 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
 
 import java.lang.reflect.InvocationTargetException;
 
+/** @exclude */
 public interface Caller {
 	void call(Object self, ReturnValues rv, Object[] params) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException;
 	
diff --git a/j2se/src/se/krka/kahlua/integration/expose/caller/ConstructorCaller.java b/j2se/src/se/krka/kahlua/integration/expose/caller/ConstructorCaller.java
index 355911f..3b98222 100644
--- a/j2se/src/se/krka/kahlua/integration/expose/caller/ConstructorCaller.java
+++ b/j2se/src/se/krka/kahlua/integration/expose/caller/ConstructorCaller.java
@@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal
 import se.krka.kahlua.integration.expose.ReturnValues;
 import se.krka.kahlua.integration.processor.DescriptorUtil;
 
+/** @exclude */
 public class ConstructorCaller extends AbstractCaller {
 
 	private final Constructor constructor;
diff --git a/j2se/src/se/krka/kahlua/integration/expose/caller/MethodCaller.java b/j2se/src/se/krka/kahlua/integration/expose/caller/MethodCaller.java
index deadf1e..0d55dfc 100644
--- a/j2se/src/se/krka/kahlua/integration/expose/caller/MethodCaller.java
+++ b/j2se/src/se/krka/kahlua/integration/expose/caller/MethodCaller.java
@@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal
 import se.krka.kahlua.integration.expose.ReturnValues;
 import se.krka.kahlua.integration.processor.DescriptorUtil;
 
+/** @exclude */
 public class MethodCaller extends AbstractCaller {
 
 	private final Method method;
diff --git a/j2se/src/se/krka/kahlua/integration/processor/ClassParameterInformation.java b/j2se/src/se/krka/kahlua/integration/processor/ClassParameterInformation.java
index 50cf563..13712b5 100644
--- a/j2se/src/se/krka/kahlua/integration/processor/ClassParameterInformation.java
+++ b/j2se/src/se/krka/kahlua/integration/processor/ClassParameterInformation.java
@@ -33,6 +33,7 @@ of this software and associated documentation files (the "Software"), to deal
 import java.util.HashMap;
 import java.util.Map;
 
+/** @exclude */
 public class ClassParameterInformation implements Serializable {
 	private static final long serialVersionUID = 7634190901254143200L;
 
diff --git a/j2se/src/se/krka/kahlua/integration/processor/DescriptorUtil.java b/j2se/src/se/krka/kahlua/integration/processor/DescriptorUtil.java
index 9e16642..26ea2ad 100644
--- a/j2se/src/se/krka/kahlua/integration/processor/DescriptorUtil.java
+++ b/j2se/src/se/krka/kahlua/integration/processor/DescriptorUtil.java
@@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
 import java.lang.reflect.Method;
 import java.util.List;
 
+/** @exclude */
 public class DescriptorUtil {
     public static String getDescriptor(
             String methodName,
diff --git a/j2se/src/se/krka/kahlua/integration/processor/LuaDebugDataProcessor.java b/j2se/src/se/krka/kahlua/integration/processor/LuaDebugDataProcessor.java
index 283c257..eb9b088 100644
--- a/j2se/src/se/krka/kahlua/integration/processor/LuaDebugDataProcessor.java
+++ b/j2se/src/se/krka/kahlua/integration/processor/LuaDebugDataProcessor.java
@@ -36,6 +36,7 @@ of this software and associated documentation files (the "Software"), to deal
 import java.util.Map.Entry;
 
 
+/** @exclude */
 public class LuaDebugDataProcessor implements Processor, ElementVisitor {
 
 	private HashMap classes;
diff --git a/j2se/src/se/krka/kahlua/integration/processor/MethodParameterInformation.java b/j2se/src/se/krka/kahlua/integration/processor/MethodParameterInformation.java
index 50a3d8d..f101ce1 100644
--- a/j2se/src/se/krka/kahlua/integration/processor/MethodParameterInformation.java
+++ b/j2se/src/se/krka/kahlua/integration/processor/MethodParameterInformation.java
@@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
 import java.util.List;
 
 
+/** @exclude */
 public class MethodParameterInformation implements Serializable {
     public static final MethodParameterInformation EMPTY = new MethodParameterInformation(Collections.EMPTY_LIST);
 	private static final long serialVersionUID = -3059552311721486815L;
diff --git a/j2se/src/se/krka/kahlua/j2se/J2SEPlatform.java b/j2se/src/se/krka/kahlua/j2se/J2SEPlatform.java
index 04d0ac8..78253e7 100644
--- a/j2se/src/se/krka/kahlua/j2se/J2SEPlatform.java
+++ b/j2se/src/se/krka/kahlua/j2se/J2SEPlatform.java
@@ -59,8 +59,8 @@ public KahluaTable newEnvironment() {
 
     private KahluaThread setupWorkerThread(KahluaTable env) {
         BlockingKahluaThread thread = new BlockingKahluaThread(this, env);
-        env.rawset(KahluaUtil.WORKER_THREAD_KEY, thread);
-        return thread;
+		KahluaUtil.setWorkerThread(env, thread);
+		return thread;
     }
 
 }
diff --git a/j2se/src/se/krka/kahlua/profiler/FakeStacktraceElement.java b/j2se/src/se/krka/kahlua/profiler/FakeStacktraceElement.java
index db9bfc7..11432b7 100644
--- a/j2se/src/se/krka/kahlua/profiler/FakeStacktraceElement.java
+++ b/j2se/src/se/krka/kahlua/profiler/FakeStacktraceElement.java
@@ -1,5 +1,6 @@
 package se.krka.kahlua.profiler;
 
+/** @exclude */
 public class FakeStacktraceElement implements StacktraceElement {
 	private final String name;
 	private final String type;
diff --git a/j2se/src/se/krka/kahlua/profiler/JavaStacktraceElement.java b/j2se/src/se/krka/kahlua/profiler/JavaStacktraceElement.java
index 8b8635e..365055f 100644
--- a/j2se/src/se/krka/kahlua/profiler/JavaStacktraceElement.java
+++ b/j2se/src/se/krka/kahlua/profiler/JavaStacktraceElement.java
@@ -2,6 +2,7 @@
 
 import se.krka.kahlua.vm.JavaFunction;
 
+/** @exclude */
 public class JavaStacktraceElement implements StacktraceElement {
 	private final JavaFunction javaFunction;
 
diff --git a/j2se/src/se/krka/kahlua/profiler/LuaStacktraceElement.java b/j2se/src/se/krka/kahlua/profiler/LuaStacktraceElement.java
index 2e34984..40f7f8e 100644
--- a/j2se/src/se/krka/kahlua/profiler/LuaStacktraceElement.java
+++ b/j2se/src/se/krka/kahlua/profiler/LuaStacktraceElement.java
@@ -2,6 +2,7 @@
 
 import se.krka.kahlua.vm.Prototype;
 
+/** @exclude */
 public class LuaStacktraceElement implements StacktraceElement {
 	private final int pc;
 	private final Prototype prototype;
diff --git a/j2se/src/se/krka/kahlua/profiler/Sampler.java b/j2se/src/se/krka/kahlua/profiler/Sampler.java
index 7efffab..d16e38b 100644
--- a/j2se/src/se/krka/kahlua/profiler/Sampler.java
+++ b/j2se/src/se/krka/kahlua/profiler/Sampler.java
@@ -8,6 +8,12 @@
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
+/**
+ * A sampler holds a timer task which periodically
+ * inspects the current call frame stack of a Kahlua thread.
+ *
+ * For each sample taken, the sampler provides it to the profiler.
+ */
 public class Sampler {
     private static final AtomicInteger NEXT_ID = new AtomicInteger();
 
@@ -17,6 +23,12 @@ public class Sampler {
 	private final Profiler profiler;
 
 
+	/**
+	 *
+	 * @param thread the Kahlua thread to measure.
+	 * @param period the number of milliseconds between each sample.
+	 * @param profiler the profiler which should receive the samples.
+	 */
     public Sampler(KahluaThread thread, long period, Profiler profiler) {
 		this.thread = thread;
 		this.period = period;
diff --git a/j2se/src/se/krka/kahlua/profiler/StacktraceCounter.java b/j2se/src/se/krka/kahlua/profiler/StacktraceCounter.java
index 47c5d89..9bf4a96 100644
--- a/j2se/src/se/krka/kahlua/profiler/StacktraceCounter.java
+++ b/j2se/src/se/krka/kahlua/profiler/StacktraceCounter.java
@@ -2,6 +2,7 @@
 
 import java.util.*;
 
+/** @exclude */
 public class StacktraceCounter {
 	private final Map children = new HashMap();
 	private long time = 0;
diff --git a/j2se/src/se/krka/kahlua/profiler/StacktraceElement.java b/j2se/src/se/krka/kahlua/profiler/StacktraceElement.java
index 1d8b505..a185e8f 100644
--- a/j2se/src/se/krka/kahlua/profiler/StacktraceElement.java
+++ b/j2se/src/se/krka/kahlua/profiler/StacktraceElement.java
@@ -1,7 +1,7 @@
 package se.krka.kahlua.profiler;
 
+/** @exclude */
 public interface StacktraceElement {
-	public String name();
-
+	String name();
 	String type();
 }
diff --git a/j2se/src/se/krka/kahlua/profiler/StacktraceNode.java b/j2se/src/se/krka/kahlua/profiler/StacktraceNode.java
index d26f9aa..2e91f82 100644
--- a/j2se/src/se/krka/kahlua/profiler/StacktraceNode.java
+++ b/j2se/src/se/krka/kahlua/profiler/StacktraceNode.java
@@ -3,6 +3,7 @@
 import java.util.*;
 import java.io.PrintWriter;
 
+/** @exclude */
 public class StacktraceNode {
     private final long time;
 	private final StacktraceElement element;
diff --git a/j2se/src/se/krka/kahlua/require/Require.java b/j2se/src/se/krka/kahlua/require/Require.java
index 7ff9dff..b48d0c8 100644
--- a/j2se/src/se/krka/kahlua/require/Require.java
+++ b/j2se/src/se/krka/kahlua/require/Require.java
@@ -46,8 +46,7 @@ public int call(LuaCallFrame callFrame, int nArguments) {
         KahluaTable env = callFrame.getEnvironment();
         Map states = (Map) callFrame.coroutine.thread.tableGet(env, this);
 
-        KahluaUtil.luaAssert(nArguments >= 1, "not enough args");
-        String path = (String) callFrame.get(0);
+		String path = KahluaUtil.getStringArg(callFrame, 1, "require");
 
         Result result = states.get(path);
         if (result == null) {