Update javadoc comments related to library inintialization.
This commit is contained in:
@@ -3,7 +3,15 @@ import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.lib.jse.JsePlatform;
|
||||
|
||||
/** Simple program showing the minimal Java program to launch a script. */
|
||||
/** Simple program showing the minimal Java program to launch a script.
|
||||
*
|
||||
* <p> In typical usage, a Globals object must be created to hold global state,
|
||||
* and it can be used to compile and load lua files into executable LuaValue
|
||||
* instances.
|
||||
*
|
||||
* @see Globals
|
||||
* @see LuaValue
|
||||
*/
|
||||
public class SampleJseMain {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
@@ -12,7 +20,7 @@ public class SampleJseMain {
|
||||
// create an environment to run in
|
||||
Globals globals = JsePlatform.standardGlobals();
|
||||
|
||||
// Use the convenience function on the globals to load a chunk.
|
||||
// Use the convenience function on Globals to load a chunk.
|
||||
LuaValue chunk = globals.loadfile(script);
|
||||
|
||||
// Use any of the "call()" or "invoke()" functions directly on the chunk.
|
||||
|
||||
@@ -5,11 +5,12 @@ import org.luaj.vm2.lib.jse.JsePlatform;
|
||||
|
||||
/** Simple toy program illustrating how to run Luaj in multiple threads.
|
||||
*
|
||||
* By creating separate Globals in each thread, scripts can be run in each thread.
|
||||
* <p>By creating separate Globals in each thread, scripts can be run in each thread.
|
||||
*
|
||||
* However note the following:
|
||||
* - type-related metatables such as LuaNumber.s_metatable are shared by all threads, so are not thread-safe.
|
||||
* - creating additional threads within a Java element called by lua could result in shared access to globals.
|
||||
* <p>However note the following:
|
||||
* <ul><li>type-related metatables such as LuaNumber.s_metatable are shared by all threads, so are not thread-safe.
|
||||
* </li><li>creating additional threads within a Java element called by lua could result in shared access to globals.
|
||||
* </li></ul>
|
||||
*/
|
||||
public class SampleMultiThreaded {
|
||||
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
/**
|
||||
* Sample luaj program that uses the LuaParser class for parsing, and intercepts the
|
||||
* generated ParseExceptions and fills in the file, line and column information where
|
||||
* the exception occurred.
|
||||
*/
|
||||
import java.io.*;
|
||||
|
||||
import org.luaj.vm2.ast.*;
|
||||
@@ -11,7 +6,13 @@ import org.luaj.vm2.ast.Stat.FuncDef;
|
||||
import org.luaj.vm2.ast.Stat.LocalFuncDef;
|
||||
import org.luaj.vm2.parser.*;
|
||||
|
||||
|
||||
/**
|
||||
* Sample luaj program that uses the LuaParser class for parsing, and intercepts the
|
||||
* generated ParseExceptions and fills in the file, line and column information where
|
||||
* the exception occurred.
|
||||
*
|
||||
* @see LuaParser
|
||||
*/
|
||||
public class SampleParser {
|
||||
|
||||
static public void main(String[] args) {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
import java.io.CharArrayReader;
|
||||
import java.io.CharArrayWriter;
|
||||
import java.io.Reader;
|
||||
@@ -16,22 +14,42 @@ import javax.script.SimpleBindings;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.lib.OneArgFunction;
|
||||
|
||||
/** Sample code that uses the JSE-223 pluggable scripting language interface
|
||||
* to instantiate and use luaj.
|
||||
*
|
||||
* <p>In this case, Globals are only indirectly constructed as a side effect
|
||||
* of using the scripting interface.
|
||||
*
|
||||
* <p>All features should be supported including compiled scripts.
|
||||
*
|
||||
* <p>Configuration is via system properties:
|
||||
* <ul><li><b>"org.luaj.luajc"</b> - set to "true" to use the LuaJC lua-to-Java-bytecode compiling.
|
||||
* Requires the bcel library to be on the class path.
|
||||
* </li><li><b>"org.luaj.debug"</b> - set to "true" to load the debug library,
|
||||
* which may provide better stack traces for closures.
|
||||
* </li></ul>
|
||||
*
|
||||
* <p> These flag values can be set on the command line or via code.
|
||||
*/
|
||||
public class ScriptEngineSample {
|
||||
|
||||
public static void main(String [] args) {
|
||||
// Set the property 'luaj.debug' before getting the engine to get
|
||||
// Set the property 'org.luaj.debug' before getting the engine to get
|
||||
// the debug libraries, which will be slower, but may provide stack traces
|
||||
// when luaJC is not used.
|
||||
// System.setProperty("luaj.debug", "true");
|
||||
// when luaJC is not used.
|
||||
// This can also be set on the command line using -Dorg.luaj.debug=true
|
||||
// System.setProperty("org.luaj.debug", "true");
|
||||
|
||||
// Set the property 'org.luaj.luajc' before getting the engine to enable
|
||||
// the lua-to-java bytecode compiler, which requires the bcel library
|
||||
// to be on the class path.
|
||||
// This can also be set on the command line using -Dorg.luaj.luajc=true
|
||||
// org.luaj.vm2.luajc.LuaJC.install();
|
||||
|
||||
ScriptEngineManager sem = new ScriptEngineManager();
|
||||
ScriptEngine e = sem.getEngineByName("luaj");
|
||||
ScriptEngineFactory f = e.getFactory();
|
||||
|
||||
// uncomment to enable the lua-to-java bytecode compiler
|
||||
// (requires bcel library in class path)
|
||||
// org.luaj.vm2.luajc.LuaJC.install();
|
||||
|
||||
System.out.println( "Engine name: " +f.getEngineName() );
|
||||
System.out.println( "Engine Version: " +f.getEngineVersion() );
|
||||
System.out.println( "LanguageName: " +f.getLanguageName() );
|
||||
|
||||
Reference in New Issue
Block a user