<commit_before><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
<title>Getting Started with LuaJ</title>
<link rel="stylesheet" type="text/css" href="http://sourceforge.net/dbimage.php?id=196140">
<link rel="stylesheet" type="text/css" href="http://sourceforge.net/dbimage.php?id=196141">
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-1">
</head>

<body>

<hr>
<h1>
<a href="README.html"><img src="http://sourceforge.net/dbimage.php?id=196139" alt="" border="0"></a>

Getting Started with LuaJ

</h1>
<NAME>, <NAME>, Version 1.0
<p>
<small>
Copyright &copy; 2007-2009 Luaj.org.
Freely available under the terms of the
<a href="http://sourceforge.net/dbimage.php?id=196142">Luaj license</a>.
</small>
<hr>
<p>

<a href="#1">examples</a>
&middot;
<a href="#2">concepts</a>
&middot;
<a href="#3">libraries</a>
&middot;
<a href="#4">building</a>
&middot;
<a href="#5">downloads</a>

<!-- ====================================================================== -->
<p>

<h1>1 - <a name="1">Simple Examples</a></h1>

<h2>Run a script in J2SE</h2>

<p>
From the main distribution directory line type:

<pre>
	java -cp luaj-j2se-1.0.jar lua src/test/res/test4.lua
</pre>

<p>
You should see the following output:
<pre>
	40
</pre>

<h2>Compile a script in J2SE</h2>

<p>
From the main distribution directory line type:

<pre>
	java -cp luaj-j2se-${VER}.jar luac src/test/res/test4.lua
	java -cp luaj-j2se-${VER}.jar lua luac.out
</pre>

<p>
The compiled output should run and produce the same result.

<h2>Run a script in a Java Application</h2>

<p>
The following pattern is used within J2SE

<pre>
	import org.luaj.platform.*;
	import org.luaj.vm.*;

	String script = "main.lua";
	Platform.setInstance( new J2sePlatform() );
	LuaState vm = Platform.newLuaState();
	org.luaj.compiler.LuaC.install();
	vm.getglobal( "dofile" );
	vm.pushstring( script );
	vm.call( 1, 0 );
</pre>

<p>
A simple example may be found in
<pre>
	src/sample/SampleJ2seMain.java
</pre>

<p>
You must include the library <b>lib/luaj-j2se-${VER}.jar</b> in your class path.

<h2>Run a script in a MIDlet</h2>

<p>
The following pattern is used within MIDlets:

<pre>
	import org.luaj.platform.*;
	import org.luaj.vm.*;

	String script = "main.lua";
	Platform.setInstance( new J2meMidp20Cldc11Platform( midlet ) );
	LuaState vm = Platform.newLuaState();
	org.luaj.compiler.LuaC.install();
	vm.getglobal( "dofile" );
	vm.pushstring( script );
	vm.call( 1, 0 );
</pre>

<p>
The file must be a resource within within the midlet jar for <em>dofile()</em> to find it.
Any files included via <em>require()</em> must also be part of the midlet resources.

<p>
A simple example may be found in
<pre>
	src/sample/SampleMIDlet.java
</pre>

<p>
You must include the library <b>lib/luaj-j2me-${VER}.jar</b> in your midlet jar.
They can be obfuscated if desired.

<h2>Including the compiler</h2>

By default, the compiler is not included to minimize footprint.

<p>
To include it, include the following after the Platform is created,
but before the script is executed:
<pre>
	org.luaj.compiler.LuaC.install();
</pre>

<p>
To omit the compiler, omit this line from your startup code. 

<h2>Run a script using JSR-233 Dynamic Scripting</h2>

<p>
The standard use of JSR-233 scripting engines may be used:

<pre>
	ScriptEngineManager mgr = new ScriptEngineManager();
	ScriptEngine e = mgr.getEngineByExtension(".lua");
	e.put("x", 25);
	e.eval("y = math.sqrt(x)");
	System.out.println( "y="+e.get("y") );
</pre>

<p>
All standard aspects of script engines including compiled statements should be supported.

<p>
You must include the library <b>lib/luaj-j2se-${VER}.jar</b> in your class path.

<p>
A working example may be found in
<pre>
	src/script/ScriptEngineSample.java
</pre>


<h1>2 - <a name="2">Concepts</a></h1>

<h2>Platforms</h2>
A Platform is required to set up basic filesystem behavior as well as
contolling mappings to underlying math functions.

<h3>J2sePlatform</h3>

This platform is used to set up the basic environment for a J2SE application.
The default search path is the current directory,
and the math operations include all those supported by J2SE.

<h3>J2mePlatform</h3>

This platform is used to set up the basic environment for a J2ME application.
The default search path is limited to the jar resources,
and the math operations are limited to those supported by J2ME.<commit_msg>Replace ${VER} with 1.0<commit_after><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
<title>Getting Started with LuaJ</title>
<link rel="stylesheet" type="text/css" href="http://sourceforge.net/dbimage.php?id=196140">
<link rel="stylesheet" type="text/css" href="http://sourceforge.net/dbimage.php?id=196141">
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-1">
</head>

<body>

<hr>
<h1>
<a href="README.html"><img src="http://sourceforge.net/dbimage.php?id=196139" alt="" border="0"></a>

Getting Started with LuaJ

</h1>
<NAME>, <NAME>, Version 1.0
<p>
<small>
Copyright &copy; 2007-2009 Luaj.org.
Freely available under the terms of the
<a href="http://sourceforge.net/dbimage.php?id=196142">Luaj license</a>.
</small>
<hr>
<p>

<a href="#1">examples</a>
&middot;
<a href="#2">concepts</a>
&middot;
<a href="#3">libraries</a>
&middot;
<a href="#4">building</a>
&middot;
<a href="#5">downloads</a>

<!-- ====================================================================== -->
<p>

<h1>1 - <a name="1">Simple Examples</a></h1>

<h2>Run a script in J2SE</h2>

<p>
From the main distribution directory line type:

<pre>
	java -cp luaj-j2se-1.0.jar lua src/test/res/test4.lua
</pre>

<p>
You should see the following output:
<pre>
	40
</pre>

<h2>Compile a script in J2SE</h2>

<p>
From the main distribution directory line type:

<pre>
	java -cp luaj-j2se-1.0.jar luac src/test/res/test4.lua
	java -cp luaj-j2se-1.0.jar lua luac.out
</pre>

<p>
The compiled output should run and produce the same result.

<h2>Run a script in a Java Application</h2>

<p>
The following pattern is used within J2SE

<pre>
	import org.luaj.platform.*;
	import org.luaj.vm.*;

	String script = "main.lua";
	Platform.setInstance( new J2sePlatform() );
	LuaState vm = Platform.newLuaState();
	org.luaj.compiler.LuaC.install();
	vm.getglobal( "dofile" );
	vm.pushstring( script );
	vm.call( 1, 0 );
</pre>

<p>
A simple example may be found in
<pre>
	src/sample/SampleJ2seMain.java
</pre>

<p>
You must include the library <b>lib/luaj-j2se-1.0.jar</b> in your class path.

<h2>Run a script in a MIDlet</h2>

<p>
The following pattern is used within MIDlets:

<pre>
	import org.luaj.platform.*;
	import org.luaj.vm.*;

	String script = "main.lua";
	Platform.setInstance( new J2meMidp20Cldc11Platform( midlet ) );
	LuaState vm = Platform.newLuaState();
	org.luaj.compiler.LuaC.install();
	vm.getglobal( "dofile" );
	vm.pushstring( script );
	vm.call( 1, 0 );
</pre>

<p>
The file must be a resource within within the midlet jar for <em>dofile()</em> to find it.
Any files included via <em>require()</em> must also be part of the midlet resources.

<p>
A simple example may be found in
<pre>
	src/sample/SampleMIDlet.java
</pre>

<p>
You must include the library <b>lib/luaj-j2me-1.0.jar</b> in your midlet jar.
They can be obfuscated if desired.

<h2>Including the compiler</h2>

By default, the compiler is not included to minimize footprint.

<p>
To include it, include the following after the Platform is created,
but before the script is executed:
<pre>
	org.luaj.compiler.LuaC.install();
</pre>

<p>
To omit the compiler, omit this line from your startup code. 

<h2>Run a script using JSR-233 Dynamic Scripting</h2>

<p>
The standard use of JSR-233 scripting engines may be used:

<pre>
	ScriptEngineManager mgr = new ScriptEngineManager();
	ScriptEngine e = mgr.getEngineByExtension(".lua");
	e.put("x", 25);
	e.eval("y = math.sqrt(x)");
	System.out.println( "y="+e.get("y") );
</pre>

<p>
All standard aspects of script engines including compiled statements should be supported.

<p>
You must include the library <b>lib/luaj-j2se-1.0.jar</b> in your class path.

<p>
A working example may be found in
<pre>
	src/script/ScriptEngineSample.java
</pre>


<h1>2 - <a name="2">Concepts</a></h1>

<h2>Platforms</h2>
A Platform is required to set up basic filesystem behavior as well as
contolling mappings to underlying math functions.

<h3>J2sePlatform</h3>

This platform is used to set up the basic environment for a J2SE application.
The default search path is the current directory,
and the math operations include all those supported by J2SE.

<h3>J2mePlatform</h3>

This platform is used to set up the basic environment for a J2ME application.
The default search path is limited to the jar resources,
and the math operations are limited to those supported by J2ME.
{'fraction_non_alphanumeric': 0.16070820565202587, 'fraction_numerical': 0.027919645897173988, 'mean_word_length': 4.48692403486924, 'pattern_counts': {'":': 0, '<': 223, '<?xml version=': 0, '>': 223, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '165914', 'n_tokens_mistral': 3369, 'n_tokens_neox': 3207, 'n_words': 1020}