Class LuaClosure

All Implemented Interfaces:
com.esotericsoftware.kryo.KryoSerializable

public class LuaClosure extends LuaFunction implements com.esotericsoftware.kryo.KryoSerializable
Extension of LuaFunction which executes lua bytecode.

A LuaClosure is a combination of a Prototype and a LuaValue to use as an environment for execution. Normally the LuaValue is a Globals in which case the environment will contain standard lua libraries.

There are three main ways LuaClosure instances are created:

To construct it directly, the Prototype is typically created via a compiler such as

 
 String script = "print( 'hello, world' )";
 InputStream is = new ByteArrayInputStream(script.getBytes());
 Prototype p = LuaC.instance.compile(is, "script");
 LuaValue globals = JsePlatform.standardGlobals();
 LuaClosure f = new LuaClosure(p, globals);
 f.call();
 

To construct it indirectly, the Globals.load(java.io.Reader, String) method may be used:

 
 Globals globals = JsePlatform.standardGlobals();
 LuaFunction f = globals.load(new StringReader(script), "script");
 LuaClosure c = f.checkclosure();  // This may fail if LuaJC is installed.
 c.call();
 

In this example, the "checkclosure()" may fail if direct lua-to-java-bytecode compiling using LuaJC is installed, because no LuaClosure is created in that case and the value returned is a LuaFunction but not a LuaClosure.

Since a LuaClosure is a LuaFunction which is a LuaValue, all the value operations can be used directly such as:

See Also: