diff --git a/README.html b/README.html index 23febac1..76f2b526 100644 --- a/README.html +++ b/README.html @@ -35,11 +35,13 @@ Freely available under the terms of the · libraries · -building +luaj api · -downloads +building · -release notes +downloads +· +release notes
@@ -389,7 +391,110 @@ The Java ME platform does not include this library, and it cannot be made to wor
The lua connand line tool includes luajava. -
+ docs/api/index.html ++ +
+ org.luaj.vm2.LuaValue ++ +
+ call(); // invoke the function with no arguments + call(LuaValue arg1); // call the function with 1 argument + invoke(Varargs arg); // call the function with variable arguments, variable return values + get(int index); // get a table entry using an integer key + get(LuaValue key); // get a table entry using an arbitrary key, may be a LuaInteger + rawget(int index); // raw get without metatable calls + valueOf(int i); // return LuaValue corresponding to an integer + valueOf(String s); // return LuaValue corresponding to a String + toint(); // return value as a Java int + tojstring(); // return value as a Java String + isnil(); // is the value nil + NIL; // the value nil + NONE; // a Varargs instance with no values ++ +
+ org.luaj.vm2.Varargs ++ +
+ narg(); // return number of arguments + arg1(); // return the first argument + arg(int n); // return the nth argument + isnil(int n); // true if the nth argument is nil + checktable(int n); // return table or throw error + optlong(int n,long d); // return n if a long, d if no argument, or error if not a long ++ +See the Varargs API for a complete list. + +
+ org.luaj.vm2.lib.ZeroArgFunction + org.luaj.vm2.lib.OneArgFunction + org.luaj.vm2.lib.TwoArgFunction + org.luaj.vm2.lib.ThreeArgFunction + org.luaj.vm2.lib.VarArgFunction ++ +Each of these functions has an abstract method that must be implemented, +and argument fixup is done automatically by the classes as each Java function is invoked. + +
+For example, to implement a "hello, world" function, we could supply: +
+ pubic class hello extends ZeroArgFunction {
+ public LuaValue call() {
+ env.get("print").call(valueOf("hello, world"));
+ }
+ }
+
+
+The value env is the environment of the function, and is normally supplied
+by the instantiating object whenever default loading is used.
+
++Calling this function from lua could be done by: +
+ require( 'hello' )() ++ +while calling this function from Java would look like: +
+ new hello().call(); ++ +Note that in both the lua and Java case, extra arguments will be ignored, and the function will be called. +Also, no virtual machine instance is necessary to call the function. +To allow for arguments, or return multiple values, extend one of the other base classes. + +