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. -

5 - Building and Testing

+

5 - LuaJ API

+ +

API Javadoc

+The distribution now contains javadoc for the main classes in the LuaJ API. +
+	 docs/api/index.html
+
+ +

LuaValue and Varargs

+All lua value manipulation is now organized around +LuaValue +which exposes the majority of interfaces used for lua computation. +
+	 org.luaj.vm2.LuaValue
+
+ +

Common Functions

+LuaValue exposes functions for each of the operations in LuaJ. +Some commonly used functions and constants include: +
+	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	 
+
+ +

Varargs

+The interface Varargs provides an abstraction for +both a variable argument list and multiple return values. +For convenience, LuaValue implements Varargs so a single value can be supplied anywhere +variable arguments are expected. +
+	 org.luaj.vm2.Varargs
+
+ +

Common Functions

+Varargs exposes functions for accessing elements, and coercing them to specific types: +
+	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. + +

LibFunction

+The simplest way to implement a function is to choose a base class based on the number of arguments to the function. +LuaJ provides 5 base classes for this purpose, depending if the function has 0, 1, 2, 3 or variable arguments, +and if it provide multiple return values. +
+	 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. + +

Closures

+Closures still exist in this framework, but are optional, and are only used to implement lua bytecode execution. + +

6 - Building and Testing

Building the jars

An ant file is included in the root directory which builds the libraries by default. @@ -424,7 +529,7 @@ A build script for running unit tests and producing code coverage statistics is It relies on the cobertura code coverage library. -

6 - Downloads

+

7 - Downloads

Downloads and Project Pages

Downloads for version 1.0.3 are currently hosted on SourceForge. @@ -442,7 +547,7 @@ and LuaForge: LuaForge Luaj Project Area -

7 - Release Notes

+

8 - Release Notes

Main Changes by Version