Compare commits
26 Commits
master
...
fabrice-du
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12ef701595 | ||
|
|
e54b0c3d57 | ||
|
|
91735791f0 | ||
|
|
3fad817099 | ||
|
|
65a5088092 | ||
|
|
113c3a9b97 | ||
|
|
1b8d7c7485 | ||
|
|
f364bb0189 | ||
|
|
f680cce336 | ||
|
|
b0df2ddcb0 | ||
|
|
2207f7f2e2 | ||
|
|
8df7dd717c | ||
|
|
a40e6862f4 | ||
|
|
33b6428031 | ||
|
|
ee08260ce2 | ||
|
|
393cf23775 | ||
|
|
970cfc579a | ||
|
|
7aa0389f6f | ||
|
|
c09d652874 | ||
|
|
3c863714b4 | ||
|
|
bfb7da97cf | ||
|
|
1aa90eb7fa | ||
|
|
610833f025 | ||
|
|
9e1a62662a | ||
|
|
314ffd6a23 | ||
|
|
7395234ccf |
19
.classpath
Normal file
19
.classpath
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src/core"/>
|
||||||
|
<classpathentry excluding="org/luaj/vm2/luajc/antlr/|org/luaj/vm2/luajc/lst/|org/luaj/vm2/luajc/JavaCodeGenerator.java" kind="src" path="src/jse"/>
|
||||||
|
<classpathentry kind="src" path="src/jme"/>
|
||||||
|
<classpathentry kind="src" path="test/java"/>
|
||||||
|
<classpathentry kind="src" path="test/junit"/>
|
||||||
|
<classpathentry kind="src" path="test/lua"/>
|
||||||
|
<classpathentry kind="src" path="examples/jse"/>
|
||||||
|
<classpathentry kind="src" path="examples/jme"/>
|
||||||
|
<classpathentry kind="src" path="examples/lua"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
|
||||||
|
<classpathentry kind="lib" path="lib/midpapi20.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/cldcapi11.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/bcel-5.2.jar"/>
|
||||||
|
<classpathentry kind="var" path="JRE_LIB"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,3 +13,4 @@ jit/
|
|||||||
*.zip
|
*.zip
|
||||||
docs
|
docs
|
||||||
*.0
|
*.0
|
||||||
|
.java-version
|
||||||
|
|||||||
10
.idea/.gitignore
generated
vendored
10
.idea/.gitignore
generated
vendored
@@ -1,10 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Ignored default folder with query files
|
|
||||||
/queries/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
16
.idea/compiler.xml
generated
16
.idea/compiler.xml
generated
@@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<annotationProcessing>
|
|
||||||
<profile name="Maven default annotation processors profile" enabled="true">
|
|
||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
|
||||||
<outputRelativeToContentRoot value="true" />
|
|
||||||
<module name="core" />
|
|
||||||
<module name="jme" />
|
|
||||||
<module name="jse" />
|
|
||||||
<module name="maven-example" />
|
|
||||||
</profile>
|
|
||||||
</annotationProcessing>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
7
.idea/discord.xml
generated
7
.idea/discord.xml
generated
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="DiscordProjectSettings">
|
|
||||||
<option name="show" value="PROJECT_FILES" />
|
|
||||||
<option name="description" value="" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
13
.idea/encodings.xml
generated
13
.idea/encodings.xml
generated
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Encoding">
|
|
||||||
<file url="file://$PROJECT_DIR$/core/src/main/java" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/core/src/main/resources" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/jme/src/main/java" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/jme/src/main/resources" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/jse/src/main/java" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/jse/src/main/resources" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
|
||||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
25
.idea/jarRepositories.xml
generated
25
.idea/jarRepositories.xml
generated
@@ -1,25 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RemoteRepositoriesConfiguration">
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Central Repository" />
|
|
||||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="oac" />
|
|
||||||
<option name="name" value="oac" />
|
|
||||||
<option name="url" value="https://repo.open-autonomous-connection.org/api/packages/open-autonomous-connection/maven" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Maven Central repository" />
|
|
||||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="jboss.community" />
|
|
||||||
<option name="name" value="JBoss Community repository" />
|
|
||||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
|
||||||
</remote-repository>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
9
.idea/luaj.iml
generated
9
.idea/luaj.iml
generated
@@ -1,9 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$" />
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
18
.idea/misc.xml
generated
18
.idea/misc.xml
generated
@@ -1,18 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="MavenProjectsManager">
|
|
||||||
<option name="originalFiles">
|
|
||||||
<list>
|
|
||||||
<option value="$PROJECT_DIR$/examples/maven/pom.xml" />
|
|
||||||
<option value="$PROJECT_DIR$/core/pom.xml" />
|
|
||||||
<option value="$PROJECT_DIR$/jme/pom.xml" />
|
|
||||||
<option value="$PROJECT_DIR$/jse/pom.xml" />
|
|
||||||
<option value="$PROJECT_DIR$/pom.xml" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="25" project-jdk-type="JavaSDK">
|
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
17
.project
Normal file
17
.project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>luaj-vm</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
93
README.md
93
README.md
@@ -1,12 +1,43 @@
|
|||||||
# This is a fork!
|
# This is a fork!
|
||||||
|
|
||||||
|
Compile with: `ant` or `ant jar-jse`
|
||||||
|
|
||||||
|
(this will build only the project for Java Standard Edition)
|
||||||
|
|
||||||
|
Then test with: `./luaj`
|
||||||
|
|
||||||
|
(or `luaj.bat` on Windows)
|
||||||
|
|
||||||
|
If you need JME support (Java Micro Edition, specifically for mobiles),
|
||||||
|
this fork is not recommended.
|
||||||
|
|
||||||
|
You can try `ant all` or `ant jar-jme`, but there is no guarantee that it
|
||||||
|
will even compile (though that may be fixed in a future version).
|
||||||
|
The `TODO` file can contain information about some known issues.
|
||||||
|
|
||||||
|
This fork aims to fix some issues met with luaj 3.0.2, still present in
|
||||||
|
[luaj/luaj](https://github.com/luaj/luaj) at
|
||||||
|
this time of writing.
|
||||||
|
|
||||||
|
Building the version 3.0.2 with recent versions of ant (e.g. 1.10.11) and
|
||||||
|
JDK (8+) seems no longer possible.
|
||||||
|
|
||||||
|
The `build.xml` file of this fork has been refactored in order to separate
|
||||||
|
jme and jse targets, and to upgrade the jse target to more recent versions
|
||||||
|
of the JDK (namely 1.8+).
|
||||||
|
|
||||||
|
It is now possible to build the jse target alone with: `ant jar-jse`
|
||||||
|
|
||||||
|
The `jar-jme` target from 3.0.2 won't be supported until contributors
|
||||||
|
experienced with JME be ready to join the project.
|
||||||
|
|
||||||
|
The interpreter can be tested with `luaj` (on POSIX systems) or `luaj.bat`
|
||||||
|
(on Windows systems). These commands can be passed arguments.
|
||||||
|
|
||||||
|
# Original README.md
|
||||||
|
|
||||||
<div style="border: 1px dotted red; margin: 1.em 0.5em; font-weight: bold; color: red;">
|
<div style="border: 1px dotted red; margin: 1.em 0.5em; font-weight: bold; color: red;">
|
||||||
This repository has been forked from https://github.com/luaj/luaj.<br />
|
This repository has been forked from the original CVS sources of Luaj.
|
||||||
The commit history has been converted to make sure that the original work of
|
|
||||||
James Roseborough and Ian Farmer and fork work of luaj/luaj is not lost.
|
|
||||||
</div>
|
|
||||||
<h3>Original repository fork notice:</h3>
|
|
||||||
<div style="border: 1px dotted red; margin: 1.em 0.5em; font-weight: bold; color: red;">
|
|
||||||
The original repository has been forked from the original CVS sources of Luaj.
|
|
||||||
The commit history has been converted to make sure that the original work of
|
The commit history has been converted to make sure that the original work of
|
||||||
James Roseborough and Ian Farmer is not lost.
|
James Roseborough and Ian Farmer is not lost.
|
||||||
Unfortunately, I was not able to contact either James or Ian to hand over
|
Unfortunately, I was not able to contact either James or Ian to hand over
|
||||||
@@ -254,7 +285,7 @@ A simple hello, world example in luaj is:
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
import org.luaj.vm2.*;
|
import org.luaj.vm2.*;
|
||||||
import org.luaj.vm2.libs.jse.*;
|
import org.luaj.vm2.lib.jse.*;
|
||||||
|
|
||||||
Globals globals = JsePlatform.standardGlobals();
|
Globals globals = JsePlatform.standardGlobals();
|
||||||
LuaValue chunk = globals.load("print 'hello, world'");
|
LuaValue chunk = globals.load("print 'hello, world'");
|
||||||
@@ -296,7 +327,7 @@ For MIDlets the <em>JmePlatform</em> is used instead:
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
import org.luaj.vm2.*;
|
import org.luaj.vm2.*;
|
||||||
import org.luaj.vm2.libs.jme.*;
|
import org.luaj.vm2.lib.jme.*;
|
||||||
|
|
||||||
Globals globals = JmePlatform.standardGlobals();
|
Globals globals = JmePlatform.standardGlobals();
|
||||||
LuaValue chunk = globals.loadfile("examples/lua/hello.lua");
|
LuaValue chunk = globals.loadfile("examples/lua/hello.lua");
|
||||||
@@ -317,6 +348,10 @@ A simple example may be found in
|
|||||||
You must include the library <b>luaj-jme-3.0.2.jar</b> in your midlet jar.
|
You must include the library <b>luaj-jme-3.0.2.jar</b> in your midlet jar.
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
An ant script to build and run the midlet is in
|
||||||
|
<pre>
|
||||||
|
<a href="build-midlet.xml">build-midlet.xml</a>
|
||||||
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
You must install the wireless toolkit and define <em>WTK_HOME</em> for this script to work.
|
You must install the wireless toolkit and define <em>WTK_HOME</em> for this script to work.
|
||||||
@@ -424,6 +459,7 @@ Applets in browsers should use the JsePlatform. The permissions model in applet
|
|||||||
highly restrictive, so a specialization of the <a href="#luajava">Luajava</a> library must be used that
|
highly restrictive, so a specialization of the <a href="#luajava">Luajava</a> library must be used that
|
||||||
uses default class loading. This is illustrated in the sample Applet
|
uses default class loading. This is illustrated in the sample Applet
|
||||||
<a href="examples/jse/SampleApplet.java">examples/jse/SampleApplet.java</a>,
|
<a href="examples/jse/SampleApplet.java">examples/jse/SampleApplet.java</a>,
|
||||||
|
which can be built using <a href="build-applet.xml">build-applet.xml</a>.
|
||||||
|
|
||||||
|
|
||||||
<h3>JmePlatform</h3>
|
<h3>JmePlatform</h3>
|
||||||
@@ -442,6 +478,7 @@ In particular Globals.finder is overridden to load as resources, so scripts shou
|
|||||||
colocated with class files in the MIDlet jar file. <a href="#luajava">Luajava</a> cannot be used.
|
colocated with class files in the MIDlet jar file. <a href="#luajava">Luajava</a> cannot be used.
|
||||||
Camples code is in
|
Camples code is in
|
||||||
<a href="examples/jme/SampleMIDlet.java">examples/jme/SampleMIDlet.java</a>,
|
<a href="examples/jme/SampleMIDlet.java">examples/jme/SampleMIDlet.java</a>,
|
||||||
|
which can be built using <a href="build-midlet.xml">build-midlet.xml</a>.
|
||||||
|
|
||||||
|
|
||||||
<h2>Thread Safety</h2>
|
<h2>Thread Safety</h2>
|
||||||
@@ -566,7 +603,7 @@ create globals that contain the debug library in addition to the other standard
|
|||||||
|
|
||||||
To install dynamically from lua use java-class-based require:</em>:
|
To install dynamically from lua use java-class-based require:</em>:
|
||||||
<pre>
|
<pre>
|
||||||
require 'org.luaj.vm2.libs.DebugLib'
|
require 'org.luaj.vm2.lib.DebugLib'
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
The <em>lua</em> command line utility includes the <em>debug</em> library by default.
|
The <em>lua</em> command line utility includes the <em>debug</em> library by default.
|
||||||
@@ -666,11 +703,11 @@ The simplest way to implement a function is to choose a base class based on the
|
|||||||
LuaJ provides 5 base classes for this purpose, depending if the function has 0, 1, 2, 3 or variable arguments,
|
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.
|
and if it provide multiple return values.
|
||||||
<pre>
|
<pre>
|
||||||
<a href="http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/ZeroArgFunction.html">org.luaj.vm2.libs.ZeroArgFunction</a>
|
<a href="http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/ZeroArgFunction.html">org.luaj.vm2.lib.ZeroArgFunction</a>
|
||||||
<a href="http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/OneArgFunction.html">org.luaj.vm2.libs.OneArgFunction</a>
|
<a href="http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/OneArgFunction.html">org.luaj.vm2.lib.OneArgFunction</a>
|
||||||
<a href="http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/TwoArgFunction.html">org.luaj.vm2.libs.TwoArgFunction</a>
|
<a href="http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/TwoArgFunction.html">org.luaj.vm2.lib.TwoArgFunction</a>
|
||||||
<a href="http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/ThreeArgFunction.html">org.luaj.vm2.libs.ThreeArgFunction</a>
|
<a href="http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/ThreeArgFunction.html">org.luaj.vm2.lib.ThreeArgFunction</a>
|
||||||
<a href="http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/VarArgFunction.html">org.luaj.vm2.libs.VarArgFunction</a>
|
<a href="http://luaj.org/luaj/3.0/api/org/luaj/vm2/lib/VarArgFunction.html">org.luaj.vm2.lib.VarArgFunction</a>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
Each of these functions has an abstract method that must be implemented,
|
Each of these functions has an abstract method that must be implemented,
|
||||||
@@ -724,7 +761,7 @@ in the environment that can be called from lua.
|
|||||||
A complete example of Java code for a simple toy library is in <a href="examples/jse/hyperbolic.java">examples/jse/hyperbolic.java</a>
|
A complete example of Java code for a simple toy library is in <a href="examples/jse/hyperbolic.java">examples/jse/hyperbolic.java</a>
|
||||||
<pre>
|
<pre>
|
||||||
import org.luaj.vm2.LuaValue;
|
import org.luaj.vm2.LuaValue;
|
||||||
import org.luaj.vm2.libs.*;
|
import org.luaj.vm2.lib.*;
|
||||||
|
|
||||||
public class hyperbolic extends TwoArgFunction {
|
public class hyperbolic extends TwoArgFunction {
|
||||||
|
|
||||||
@@ -883,6 +920,10 @@ Unit test scripts can be found in these locations
|
|||||||
<h2>Code coverage</h2>
|
<h2>Code coverage</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
A build script for running unit tests and producing code coverage statistics is in
|
||||||
|
<pre>
|
||||||
|
<a href="build-coverage.xml">build-coverage.xml</a>
|
||||||
|
</pre>
|
||||||
|
|
||||||
It relies on the cobertura code coverage library.
|
It relies on the cobertura code coverage library.
|
||||||
|
|
||||||
@@ -941,6 +982,7 @@ and at <a href="http://luaj.sourceforge.net/api/2.0/index.html">http://luaj.sour
|
|||||||
<li>Add explicit Globals object to manage global state, especially to imrpove thread safety </li>
|
<li>Add explicit Globals object to manage global state, especially to imrpove thread safety </li>
|
||||||
<li>Drop support for lua source to java surce (lua2java) in favor of direct java bytecode output (luajc) </li>
|
<li>Drop support for lua source to java surce (lua2java) in favor of direct java bytecode output (luajc) </li>
|
||||||
<li>Remove compatibility functions like table.getn(), table.maxn(), table.foreach(), and math.log10() </li>
|
<li>Remove compatibility functions like table.getn(), table.maxn(), table.foreach(), and math.log10() </li>
|
||||||
|
<li>Add ability to create runnable jar file from lua script with sample build file build-app.xml </li>
|
||||||
<li>Supply environment as second argument to LibFunction when loading via require() </li>
|
<li>Supply environment as second argument to LibFunction when loading via require() </li>
|
||||||
<li>Fix bug 3597515 memory leak due to string caching by simplifying caching logic.</li>
|
<li>Fix bug 3597515 memory leak due to string caching by simplifying caching logic.</li>
|
||||||
<li>Fix bug 3565008 so that short substrings are backed by short arrays.</li>
|
<li>Fix bug 3565008 so that short substrings are backed by short arrays.</li>
|
||||||
@@ -1023,10 +1065,7 @@ and at <a href="http://luaj.sourceforge.net/api/2.0/index.html">http://luaj.sour
|
|||||||
<li>debug code may not be completely removed by some obfuscators
|
<li>debug code may not be completely removed by some obfuscators
|
||||||
<li>tail calls are not tracked in debug information
|
<li>tail calls are not tracked in debug information
|
||||||
<li>mixing different versions of luaj in the same java vm is not supported
|
<li>mixing different versions of luaj in the same java vm is not supported
|
||||||
<li>LuaJ runs on the host VM garbage collector, so object lifetime, weak reference timing, and finalization behavior are not identical to native Lua
|
|
||||||
<li>the <code>__gc</code> metamethod is not supported as a reliable Lua finalization mechanism
|
|
||||||
<li>values associated with weak keys may linger longer than expected
|
<li>values associated with weak keys may linger longer than expected
|
||||||
<li>cascading weak-table collection can require multiple host GC cycles
|
|
||||||
<li>behavior of luaj when a SecurityManager is used has not been fully characterized
|
<li>behavior of luaj when a SecurityManager is used has not been fully characterized
|
||||||
<li>negative zero is treated as identical to integer value zero throughout luaj
|
<li>negative zero is treated as identical to integer value zero throughout luaj
|
||||||
<li>lua compiled into java bytecode using luajc cannot use string.dump() or xpcall()
|
<li>lua compiled into java bytecode using luajc cannot use string.dump() or xpcall()
|
||||||
@@ -1034,22 +1073,6 @@ and at <a href="http://luaj.sourceforge.net/api/2.0/index.html">http://luaj.sour
|
|||||||
<li>shared metatables for string, bool, etc are shared across Globals instances in the same class loader
|
<li>shared metatables for string, bool, etc are shared across Globals instances in the same class loader
|
||||||
<li>orphaned threads will not be collected unless garbage collection is run and sufficient time elapses
|
<li>orphaned threads will not be collected unless garbage collection is run and sufficient time elapses
|
||||||
</ul>
|
</ul>
|
||||||
<h3>Garbage Collection And Resources</h3>
|
|
||||||
LuaJ does not implement the same garbage collector semantics as native Lua. Garbage collection is delegated to the host JVM or CLDC runtime, so <code>collectgarbage()</code> is only a hint and should not be used as a resource-management primitive.
|
|
||||||
<p>
|
|
||||||
In particular:
|
|
||||||
<ul>
|
|
||||||
<li>Do not rely on garbage collection to close files, sockets, database handles, or other resources.
|
|
||||||
<li>Always call <code>close()</code> explicitly on files and iterators that own files.
|
|
||||||
<li><code>io.lines(filename)</code> opens a file implicitly. If iteration is abandoned early, that file may remain open until explicitly collected by the host runtime.
|
|
||||||
<li>Prefer <code>local f = assert(io.open(...))</code> together with <code>f:lines()</code> and an explicit <code>f:close()</code> when deterministic cleanup matters.
|
|
||||||
<li>For implicit line iterators that need deterministic early cleanup, use <code>io.linesx(filename)</code> and call <code>iterator:close()</code>.
|
|
||||||
<li><code>file:linesx()</code> provides the same closable iterator API for already-open files.
|
|
||||||
<li>On Windows, leaked file handles can prevent rename or delete operations until the process exits.
|
|
||||||
<li>On JME/CLDC, finalization support may be absent, so explicit close is mandatory.
|
|
||||||
</ul>
|
|
||||||
<p>
|
|
||||||
Short-lived locals may also remain reachable longer than expected because host stack/register reuse is implementation-dependent. If prompt reclamation matters, isolate temporary allocations in functions and clear large references explicitly instead of assuming block exit is enough.
|
|
||||||
<h3>File Character Encoding</h3>
|
<h3>File Character Encoding</h3>
|
||||||
Source files can be considered encoded in UTF-8 or ISO-8859-1 and results should be as expected,
|
Source files can be considered encoded in UTF-8 or ISO-8859-1 and results should be as expected,
|
||||||
with literal string contianing quoted characters compiling to the same byte sequences as the input.
|
with literal string contianing quoted characters compiling to the same byte sequences as the input.
|
||||||
|
|||||||
20
TODO
Normal file
20
TODO
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
The current version doesn't compile with:
|
||||||
|
ant jar-jme|all
|
||||||
|
|
||||||
|
The Java compiler complains with an obscure error:
|
||||||
|
[javac] /Users/ducos/Projects/luaj/build/jme/src/org/luaj/vm2/LuaValue.java:532: error: cannot access StringBuilder
|
||||||
|
[javac] public String tojstring() { return typename() + ": " + Integer.toHexString(hashCode()); }
|
||||||
|
|
||||||
|
This is because, in recent versions of Java, the concatenation of strings is automatically performed
|
||||||
|
with java.lang.StringBuilder
|
||||||
|
|
||||||
|
Unfortunately, this class is not available in the JME environment.
|
||||||
|
|
||||||
|
A workaround would be to replace the + concatenation with the String.concat() method, like this:
|
||||||
|
|
||||||
|
- public String tojstring() { return typename() + ": " + Integer.toHexString(hashCode()); }
|
||||||
|
+ public String tojstring() { return typename().concat(": ").concat(Integer.toHexString(hashCode())); }
|
||||||
|
|
||||||
|
But it has to be done everywhere in the code.
|
||||||
|
|
||||||
|
Maybe there is a more straightforward method, with a compiler's flag.
|
||||||
108
build-app.xml
Normal file
108
build-app.xml
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<!-- And build script to compile lua scripts into runnable jar files using the "luajc"
|
||||||
|
lua to java bytecode compiler.
|
||||||
|
|
||||||
|
Each source file is converted into a runnable jar file that takes arguments from the command line.
|
||||||
|
For example, the program test/lua/perf/binarytrees.lua is converted to a jar that can be run with
|
||||||
|
java -jar binarytrees.jar 15
|
||||||
|
-->
|
||||||
|
<project default="all">
|
||||||
|
<import file="build.xml"/>
|
||||||
|
|
||||||
|
<import file="build-libs.xml"/>
|
||||||
|
|
||||||
|
<available file="luaj-jse-${version}.jar" property="luaj.lib.exists"/>
|
||||||
|
|
||||||
|
<!-- this may need to be changed when building on mac -->
|
||||||
|
<property name="rt.jar" value="${java.home}/lib/rt.jar"/>
|
||||||
|
|
||||||
|
<target name="luaj-lib" unless="luaj.lib.exists">
|
||||||
|
<antcall target="jar-jse"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<macrodef name="perftest">
|
||||||
|
<attribute name="cmd"/>
|
||||||
|
<sequential>
|
||||||
|
<echo level="info">------ @{cmd}</echo>
|
||||||
|
<exec executable="bash">
|
||||||
|
<arg value="-c"/>
|
||||||
|
<arg value="time @{cmd}"/>
|
||||||
|
</exec>
|
||||||
|
</sequential>
|
||||||
|
</macrodef>
|
||||||
|
|
||||||
|
<macrodef name="buildappjar">
|
||||||
|
<attribute name="luaprog"/>
|
||||||
|
<attribute name="arg" default=""/>
|
||||||
|
<attribute name="srcdir" default="test/lua/perf"/>
|
||||||
|
<sequential>
|
||||||
|
<echo level="info">=========== @{srcdir}/@{luaprog} =============</echo>
|
||||||
|
<delete dir="build/@{luaprog}"/>
|
||||||
|
<mkdir dir="build/@{luaprog}/class"/>
|
||||||
|
<java classname="luajc">
|
||||||
|
<classpath>
|
||||||
|
<pathelement path="luaj-jse-${version}.jar"/>
|
||||||
|
<pathelement path="lib/bcel-5.2.jar"/>
|
||||||
|
</classpath>
|
||||||
|
<arg value="-s"/>
|
||||||
|
<arg path="@{srcdir}"/>
|
||||||
|
<arg value="-d"/>
|
||||||
|
<arg path="build/@{luaprog}/class"/>
|
||||||
|
<arg value="-m"/>
|
||||||
|
<arg value="-v"/>
|
||||||
|
<arg value="@{luaprog}.lua"/>
|
||||||
|
</java>
|
||||||
|
<jar destfile="build/@{luaprog}.jar">
|
||||||
|
<fileset dir="build/@{luaprog}/class"/>
|
||||||
|
<zipfileset includes="org/luaj/vm2/*.class,org/luaj/vm2/lib/*.class,org/luaj/vm2/lib/jse/*.class,org/luaj/vm2/compiler/*.class" src="luaj-jse-${version}.jar" />
|
||||||
|
<manifest>
|
||||||
|
<attribute name="Main-Class" value="@{luaprog}" />
|
||||||
|
</manifest>
|
||||||
|
</jar>
|
||||||
|
<unjar src="build/@{luaprog}.jar" dest="build/@{luaprog}/unjarred"/>
|
||||||
|
<perftest cmd="java -jar build/@{luaprog}.jar @{arg}"/>
|
||||||
|
|
||||||
|
<!-- The following can be adapted to produce an optimized jar.
|
||||||
|
<taskdef resource="proguard/ant/task.properties" classpath="lib/proguard.jar" />
|
||||||
|
<proguard>
|
||||||
|
-injars build/@{luaprog}.jar
|
||||||
|
-outjars build/@{luaprog}-opt.jar
|
||||||
|
-libraryjars ${rt.jar}
|
||||||
|
-overloadaggressively
|
||||||
|
-repackageclasses ''
|
||||||
|
-allowaccessmodification
|
||||||
|
-printmapping build/@{luaprog}.map
|
||||||
|
|
||||||
|
-keep public class @{luaprog} {
|
||||||
|
public static void main(java.lang.String[]);
|
||||||
|
}
|
||||||
|
</proguard>
|
||||||
|
<unjar src="build/@{luaprog}-opt.jar" dest="build/@{luaprog}/unjarred-opt"/>
|
||||||
|
<perftest cmd="java -jar build/@{luaprog}-opt.jar @{arg}"/>
|
||||||
|
-->
|
||||||
|
</sequential>
|
||||||
|
</macrodef>
|
||||||
|
|
||||||
|
<target name="binarytrees" depends="luaj-lib,proguard-lib">
|
||||||
|
<buildappjar luaprog="binarytrees" arg="15"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="fannkuch" depends="luaj-lib,proguard-lib">
|
||||||
|
<buildappjar luaprog="fannkuch" arg="10"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="nbody" depends="luaj-lib,proguard-lib">
|
||||||
|
<buildappjar luaprog="nbody" arg="1000000"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="nsieve" depends="luaj-lib,proguard-lib">
|
||||||
|
<buildappjar luaprog="nsieve" arg="8"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="swingapp" depends="luaj-lib,proguard-lib">
|
||||||
|
<buildappjar luaprog="swingapp" srcdir="examples/lua"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="allappjars" depends="binarytrees,fannkuch,nbody,nsieve,swingapp"/>
|
||||||
|
|
||||||
|
<target name="all" depends="allappjars"/>
|
||||||
|
</project>
|
||||||
116
build-applet.xml
Normal file
116
build-applet.xml
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<project name="sample" default="main" basedir=".">
|
||||||
|
<property file="version.properties"/>
|
||||||
|
|
||||||
|
<!-- find libs -->
|
||||||
|
<import file="build-libs.xml"/>
|
||||||
|
|
||||||
|
<!-- main java class -->
|
||||||
|
<property name="java.dir" value="examples/jse"/>
|
||||||
|
<property name="java.name" value="SampleApplet"/>
|
||||||
|
|
||||||
|
<!-- main script -->
|
||||||
|
<property name="script.dir" value="examples/lua"/>
|
||||||
|
<property name="script.name" value="swingapplet"/>
|
||||||
|
<property name="image.name" value="logo.gif"/>
|
||||||
|
|
||||||
|
<!-- location of luaj jar -->
|
||||||
|
<property name="libs.dir" value="lib"/>
|
||||||
|
<property name="luaj.jar" value="${libs.dir}/luaj-jse-${version}.jar"/>
|
||||||
|
|
||||||
|
<!-- location of build results -->
|
||||||
|
<property name="build.dir" value="build/applet"/>
|
||||||
|
|
||||||
|
<target name="clean">
|
||||||
|
<delete failonerror="false" dir="${build.dir}"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="dirs">
|
||||||
|
<mkdir dir="build/applet/classes"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="classes" depends="dirs">
|
||||||
|
<copy todir="${build.dir}">
|
||||||
|
<fileset dir="${script.dir}" includes="${script.name}.lua,${image.name}"/>
|
||||||
|
</copy>
|
||||||
|
<javac destdir="${build.dir}/classes" source="1.8" target="1.8"
|
||||||
|
classpath="${luaj.jar}" srcdir="${java.dir}" includes="${java.name}.java"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="manifest" depends="dirs">
|
||||||
|
<manifest file="${build.dir}/MANIFEST.MF">
|
||||||
|
<attribute name="Permissions" value="sandbox"/>
|
||||||
|
<attribute name="Main-class" value="${java.name}"/>
|
||||||
|
</manifest>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="jar" depends="classes,manifest">
|
||||||
|
<jar destfile="${build.dir}/${script.name}.jar"
|
||||||
|
manifest="${build.dir}/MANIFEST.MF">
|
||||||
|
<fileset dir="${build.dir}" includes="*.lua"/>
|
||||||
|
<fileset dir="${build.dir}/classes"/>
|
||||||
|
<zipfileset
|
||||||
|
src="${luaj.jar}"
|
||||||
|
excludes="**/script/*,**/luajc/**,**/parser/**,**/ast/**,lua*"/>
|
||||||
|
</jar>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="obf" depends="jar,proguard-lib">
|
||||||
|
<taskdef resource="proguard/ant/task.properties" classpath="lib/proguard.jar" />
|
||||||
|
<copy file="${build.dir}/${script.name}.jar"
|
||||||
|
tofile="${build.dir}/${script.name}-unobfuscated.jar"/>
|
||||||
|
<proguard>
|
||||||
|
-injars ${build.dir}/${script.name}-unobfuscated.jar
|
||||||
|
-outjars ${build.dir}/${script.name}.jar
|
||||||
|
-libraryjars ${java.home}/lib/rt.jar
|
||||||
|
-overloadaggressively
|
||||||
|
-repackageclasses ''
|
||||||
|
-allowaccessmodification
|
||||||
|
-printmapping ${build.dir}/mapping.txt
|
||||||
|
|
||||||
|
-keep public class * extends java.applet.Applet
|
||||||
|
|
||||||
|
-target 1.8
|
||||||
|
</proguard>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="sign" depends="obf">
|
||||||
|
<signjar jar="${build.dir}/${script.name}.jar"
|
||||||
|
alias="${sign.alias}"
|
||||||
|
storepass="${sign.storepass}"
|
||||||
|
keypass="${sign.keypass}"
|
||||||
|
keystore="${sign.keystore}" />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="html" depends="dirs">
|
||||||
|
<echoxml file="build/applet/LuajSampleApplet.html">
|
||||||
|
<html>
|
||||||
|
<head><title>Luaj Sample Applet</title></head>
|
||||||
|
<body>
|
||||||
|
<h1>Luaj Sample Applet</h1>
|
||||||
|
Requires browser that supports applets.
|
||||||
|
${script.name}
|
||||||
|
<applet archive='${script.name}.jar'
|
||||||
|
code='${java.name}.class'
|
||||||
|
width='800'
|
||||||
|
height='640' >
|
||||||
|
<param name='luaj.script' value='${script.name}.lua'/>
|
||||||
|
<param name="java_version" value="1.8+"/>
|
||||||
|
</applet>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
</echoxml>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="run" depends="jar,html">
|
||||||
|
<exec executable="open" spawn="true">
|
||||||
|
<arg value="-a Firefox"/>
|
||||||
|
<arg path="build/applet/LuajSampleApplet.html"/>
|
||||||
|
</exec>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="all" depends="clean,sign,html,run"/>
|
||||||
|
|
||||||
|
<target name="main" depends="sign,html"/>
|
||||||
|
|
||||||
|
</project>
|
||||||
119
build-coverage.xml
Normal file
119
build-coverage.xml
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<project default="all" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
|
||||||
|
<!--
|
||||||
|
Run code coverage for unit tests on the luaj vm and libraries.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<property name="classes.dir" value="build/classes-debug" />
|
||||||
|
<property name="instrumented.dir" value="build/instrumented" />
|
||||||
|
<property name="reports.xml.dir" value="build/reports-junit-xml" />
|
||||||
|
<property name="reports.html.dir" value="build/reports-junit-html" />
|
||||||
|
<property name="coverage.xml.dir" value="build/reports-coverage-xml" />
|
||||||
|
<property name="coverage.html.dir" value="build/reports-coverage-html" />
|
||||||
|
<property name="cobertura.serfile" value="cobertura.ser" />
|
||||||
|
<property name="cobertura.logfile" value="cobertura.log" />
|
||||||
|
|
||||||
|
<artifact:dependencies filesetId="cobutura.fileset">
|
||||||
|
<dependency groupId="net.sourceforge.cobertura" artifactId="cobertura" version="1.9.4.1"/>
|
||||||
|
<dependency groupId="junit" artifactId="junit" version="3.8.1"/>
|
||||||
|
</artifact:dependencies>
|
||||||
|
|
||||||
|
<path id="cobertura.classpath">
|
||||||
|
<fileset refid="cobutura.fileset" />
|
||||||
|
</path>
|
||||||
|
|
||||||
|
<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
|
||||||
|
|
||||||
|
<import file="wtk.xml"/>
|
||||||
|
|
||||||
|
<property environment="env"/>
|
||||||
|
|
||||||
|
<target name="clean" description="Remove all files created by the build/test process.">
|
||||||
|
<delete dir="${classes.dir}" failonerror="yes"/>
|
||||||
|
<delete dir="${instrumented.dir}" failonerror="yes"/>
|
||||||
|
<delete file="${cobertura.logfile}" />
|
||||||
|
<delete file="${cobertura.serfile}" />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="init">
|
||||||
|
<ant antfile="build.xml" target="bcel-lib"/>
|
||||||
|
<ant antfile="build.xml" target="luaj1-lib"/>
|
||||||
|
<mkdir dir="${classes.dir}" />
|
||||||
|
<mkdir dir="${instrumented.dir}" />
|
||||||
|
<mkdir dir="${reports.xml.dir}" />
|
||||||
|
<mkdir dir="${reports.html.dir}" />
|
||||||
|
<mkdir dir="${coverage.xml.dir}" />
|
||||||
|
<mkdir dir="${coverage.html.dir}" />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="compile" depends="init,wtk-or-fail">
|
||||||
|
<javac destdir="${classes.dir}" debug="yes" target="1.8">
|
||||||
|
<classpath refid="cobertura.classpath" />
|
||||||
|
<classpath refid="wtk-libs" />
|
||||||
|
<classpath path="lib/bcel-5.2.jar" />
|
||||||
|
<src path="src/core"/>
|
||||||
|
<src path="src/jme"/>
|
||||||
|
<src path="src/jse"/>
|
||||||
|
<src path="test/junit"/>
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="instrument" depends="compile">
|
||||||
|
<delete file="${cobertura.serfile}"/>
|
||||||
|
<delete dir="${instrumented.dir}" failonerror="no"/>
|
||||||
|
<cobertura-instrument datafile="${cobertura.serfile}" todir="${instrumented.dir}">
|
||||||
|
<fileset dir="${classes.dir}">
|
||||||
|
<include name="org/luaj/vm2/*.class" />
|
||||||
|
<include name="org/luaj/vm2/lib/*.class" />
|
||||||
|
<include name="org/luaj/vm2/lib/jse/*.class" />
|
||||||
|
<include name="org/luaj/vm2/lib/jme/*.class" />
|
||||||
|
<include name="org/luaj/vm2/compiler/*.class" />
|
||||||
|
<include name="org/luaj/vm2/luajc/*.class" />
|
||||||
|
<include name="org/luaj/vm2/lua2java/*.class" />
|
||||||
|
<include name="org/luaj/vm2/parser/*.class" />
|
||||||
|
<include name="org/luaj/vm2/ast/*.class" />
|
||||||
|
<exclude name="**/*Test*.class" />
|
||||||
|
</fileset>
|
||||||
|
</cobertura-instrument>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="test">
|
||||||
|
<junit fork="yes" dir="${basedir}" showoutput="yes">
|
||||||
|
<sysproperty key="net.sourceforge.cobertura.serfile"
|
||||||
|
file="${basedir}/${cobertura.serfile}" />
|
||||||
|
<classpath location="${instrumented.dir}" />
|
||||||
|
<classpath location="${classes.dir}" />
|
||||||
|
<classpath refid="cobertura.classpath" />
|
||||||
|
<classpath location="test/lua" />
|
||||||
|
<classpath location="test/junit/org/luaj/vm2/compiler" />
|
||||||
|
<classpath location="test/junit/org/luaj/vm2/vm1" />
|
||||||
|
<classpath path="lib/bcel-5.2.jar" />
|
||||||
|
<formatter type="xml" />
|
||||||
|
<batchtest todir="${reports.xml.dir}">
|
||||||
|
<fileset dir="test/junit">
|
||||||
|
<include name="org/luaj/vm2/AllTests.java" />
|
||||||
|
</fileset>
|
||||||
|
</batchtest>
|
||||||
|
</junit>
|
||||||
|
|
||||||
|
<junitreport todir="${reports.xml.dir}">
|
||||||
|
<fileset dir="${reports.xml.dir}">
|
||||||
|
<include name="TEST-*.xml" />
|
||||||
|
</fileset>
|
||||||
|
<report format="frames" todir="${reports.html.dir}" />
|
||||||
|
</junitreport>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="report">
|
||||||
|
<cobertura-report datafile="${cobertura.serfile}" destdir="${coverage.xml.dir}" format="xml" />
|
||||||
|
<cobertura-report datafile="${cobertura.serfile}" destdir="${coverage.html.dir}">
|
||||||
|
<fileset dir="src/core"/>
|
||||||
|
<fileset dir="src/jse"/>
|
||||||
|
<fileset dir="src/jme"/>
|
||||||
|
</cobertura-report>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="coverage" depends="clean,init,compile,instrument,test,report"/>
|
||||||
|
|
||||||
|
<target name="all" depends="coverage" />
|
||||||
|
|
||||||
|
</project>
|
||||||
56
build-libs.xml
Normal file
56
build-libs.xml
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<project default="all-libs">
|
||||||
|
|
||||||
|
<available file="lib/midpapi20.jar" property="midpapi.lib.exists"/>
|
||||||
|
<available file="lib/bcel-5.2.jar" property="bcel.lib.exists"/>
|
||||||
|
<available file="lib/javacc.jar" property="javacc.lib.exists"/>
|
||||||
|
<available file="lib/proguard.jar" property="proguard.lib.exists"/>
|
||||||
|
<available file="lib/antenna-bin-1.2.0-beta.jar" property="antenna.lib.exists"/>
|
||||||
|
<available file="lib/junit.jar" property="junit.lib.exists"/>
|
||||||
|
<available file="lib/cobertura.jar" property="cobertura.lib.exists"/>
|
||||||
|
<available file="lib/microemulator.jar" property="microemulator.lib.exists"/>
|
||||||
|
|
||||||
|
<macrodef name="download">
|
||||||
|
<attribute name="zipname"/>
|
||||||
|
<attribute name="jars" default="**/*.jar"/>
|
||||||
|
<sequential>
|
||||||
|
<mkdir dir="lib"/>
|
||||||
|
<get src="http://luaj.sourceforge.net/lib/@{zipname}.tar.gz"
|
||||||
|
dest="lib/@{zipname}.tar.gz"/>
|
||||||
|
<gunzip src="lib/@{zipname}.tar.gz" dest="lib/@{zipname}.tar"/>
|
||||||
|
<untar src="lib/@{zipname}.tar" dest="lib" overwrite="true">
|
||||||
|
<patternset>
|
||||||
|
<include name="@{jars}"/>
|
||||||
|
</patternset>
|
||||||
|
<mapper type="flatten"/>
|
||||||
|
</untar>
|
||||||
|
</sequential>
|
||||||
|
</macrodef>
|
||||||
|
|
||||||
|
<target name="wtk-libs" unless="midpapi.lib.exists">
|
||||||
|
<download zipname="wtk-2.5.2-api"/>
|
||||||
|
</target>
|
||||||
|
<target name="bcel-lib" unless="bcel.lib.exists">
|
||||||
|
<download zipname="/bcel-5.2"/>
|
||||||
|
</target>
|
||||||
|
<target name="javacc-lib" unless="javacc.lib.exists">
|
||||||
|
<download zipname="javacc-5.0"/>
|
||||||
|
</target>
|
||||||
|
<target name="proguard-lib" unless="proguard.lib.exists">
|
||||||
|
<download zipname="proguard4.6"/>
|
||||||
|
</target>
|
||||||
|
<target name="antenna-lib" unless="antenna.lib.exists">
|
||||||
|
<download zipname="antenna-bin-1.2.0-beta"/>
|
||||||
|
</target>
|
||||||
|
<target name="junit-lib" unless="junit.lib.exists">
|
||||||
|
<download zipname="junit-3.8.2"/>
|
||||||
|
</target>
|
||||||
|
<target name="cobertura-lib" unless="cobertura.lib.exists">
|
||||||
|
<download zipname="cobertura-1.9.4.1-bin"/>
|
||||||
|
</target>
|
||||||
|
<target name="microemulator-lib" unless="microemulator.lib.exists">
|
||||||
|
<download zipname="microemulator-2.0.4" jars="**/microemulator.jar"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="all-libs" depends="wtk-libs,bcel-lib,javacc-lib,proguard-lib,antenna-lib,junit-lib,cobertura-lib"/>
|
||||||
|
|
||||||
|
</project>
|
||||||
176
build-maven.xml
Normal file
176
build-maven.xml
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
<project default="usage">
|
||||||
|
<!-- Ant file to deploy to maven once the distribution is released on sourceforge.
|
||||||
|
-->
|
||||||
|
<property file="version.properties"/>
|
||||||
|
|
||||||
|
<macrodef name="write_pom">
|
||||||
|
<attribute name="platform"/>
|
||||||
|
<attribute name="snapshot" default=""/>
|
||||||
|
<sequential>
|
||||||
|
<mkdir dir="build/maven-${version}"/>
|
||||||
|
<echo file="build/maven-${version}/luaj-@{platform}-${version}@{snapshot}.pom"><![CDATA[<project>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.luaj</groupId>
|
||||||
|
<artifactId>luaj-]]>@{platform}<![CDATA[</artifactId>
|
||||||
|
<version>]]>${version}@{snapshot}<![CDATA[</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>luaj-]]>@{platform}<![CDATA[</name>
|
||||||
|
<description>Luaj ]]>${version}<![CDATA[ for the ]]>@{platform}<![CDATA[ platform</description>
|
||||||
|
<url>http://sourceforge.net/projects/luaj/</url>
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>MIT License</name>
|
||||||
|
<url>http://luaj.sourceforge.net/license.txt</url>
|
||||||
|
<distribution>repo</distribution>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>jrosebor</id>
|
||||||
|
<name>James Roseborough</name>
|
||||||
|
<email>jim.roseborough@luaj.org</email>
|
||||||
|
<timezone>-8</timezone>
|
||||||
|
<roles></roles>
|
||||||
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>ifarmer</id>
|
||||||
|
<name>Ian Farmer</name>
|
||||||
|
<email>ian.farmer@luaj.org</email>
|
||||||
|
<timezone>-8</timezone>
|
||||||
|
<roles></roles>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
<scm>
|
||||||
|
<url>http://luaj.cvs.sourceforge.net/viewvc/luaj/luaj-vm/</url>
|
||||||
|
</scm>
|
||||||
|
</project>
|
||||||
|
]]></echo>
|
||||||
|
</sequential>
|
||||||
|
</macrodef>
|
||||||
|
|
||||||
|
<macrodef name="prepare_files">
|
||||||
|
<attribute name="platform"/>
|
||||||
|
<attribute name="snapshot" default=""/>
|
||||||
|
<sequential>
|
||||||
|
<mkdir dir="build/maven-${version}"/>
|
||||||
|
<write_pom platform="@{platform}" snapshot="@{snapshot}"/>
|
||||||
|
<copy file="luaj-${version}.zip" todir="build/maven-${version}"/>
|
||||||
|
<unzip src="build/maven-${version}/luaj-${version}.zip" dest="build/maven-${version}"/>
|
||||||
|
<copy file="build/maven-${version}/luaj-${version}/lib/luaj-@{platform}-${version}.jar" todir="build/maven-${version}"/>
|
||||||
|
|
||||||
|
<!-- make a -sources file -->
|
||||||
|
<mkdir dir="build/maven-${version}/sources-@{platform}"/>
|
||||||
|
<copy todir="build/maven-${version}/sources-@{platform}">
|
||||||
|
<fileset dir="build/maven-${version}/luaj-${version}/src/core"/>
|
||||||
|
<fileset dir="build/maven-${version}/luaj-${version}/src/@{platform}"/>
|
||||||
|
<filterchain>
|
||||||
|
<tokenfilter><replacestring from='"Luaj 0.0"' to='"Luaj-@{platform} ${version}"'/></tokenfilter>
|
||||||
|
</filterchain>
|
||||||
|
</copy>
|
||||||
|
<zip destfile="build/maven-${version}/luaj-@{platform}-${version}-sources.jar"
|
||||||
|
basedir="build/maven-${version}/sources-@{platform}"/>
|
||||||
|
|
||||||
|
<!-- make a -javadoc file -->
|
||||||
|
<mkdir dir="build/maven-${version}/javadoc-@{platform}"/>
|
||||||
|
<javadoc defaultexcludes="yes"
|
||||||
|
destdir="build/maven-${version}/javadoc-@{platform}"
|
||||||
|
author="true"
|
||||||
|
version="true"
|
||||||
|
use="true"
|
||||||
|
windowtitle="Luaj API">
|
||||||
|
<fileset dir="build/maven-${version}/sources-@{platform}">
|
||||||
|
<include name="org/luaj/vm/*.java"/>
|
||||||
|
<include name="org/luaj/vm2/*.java"/>
|
||||||
|
<include name="org/luaj/vm2/server/*.java"/>
|
||||||
|
<include name="**/LuaC.java"/>
|
||||||
|
<include name="**/LuaJC.java"/>
|
||||||
|
<include name="**/lib/*/*.java"/>
|
||||||
|
</fileset>
|
||||||
|
<doctitle><![CDATA[<h1>Luaj API</h1>]]></doctitle>
|
||||||
|
<bottom><![CDATA[<i>Copyright © 2007-2015 Luaj.org. All Rights Reserved.</i>]]></bottom>
|
||||||
|
<tag name="todo" scope="all" description="To do:"/>
|
||||||
|
<link offline="true" href="http://sourceforge.net/projects/luaj/" packagelistLoc="C:\tmp"/>
|
||||||
|
<link href="http://sourceforge.net/projects/luaj/"/>
|
||||||
|
</javadoc>
|
||||||
|
<zip destfile="build/maven-${version}/luaj-@{platform}-${version}-javadoc.jar"
|
||||||
|
basedir="build/maven-${version}/javadoc-@{platform}"/>
|
||||||
|
</sequential>
|
||||||
|
</macrodef>
|
||||||
|
|
||||||
|
<macrodef name="shapshot_files">
|
||||||
|
<attribute name="platform"/>
|
||||||
|
<sequential>
|
||||||
|
<exec executable="mvn">
|
||||||
|
<arg value="deploy:deploy-file"/>
|
||||||
|
<arg value="-Durl=https://oss.sonatype.org/content/repositories/snapshots"/>
|
||||||
|
<arg value="-DrepositoryId=nexus-releases"/>
|
||||||
|
<arg value="-DpomFile=build/maven-${version}/luaj-@{platform}-${version}-SNAPSHOT.pom"/>
|
||||||
|
<arg value="-Dfile=build/maven-${version}/luaj-@{platform}-${version}.jar"/>
|
||||||
|
<arg value="-Dsources=build/maven-${version}/luaj-@{platform}-${version}-sources.jar"/>
|
||||||
|
<arg value="-Djavadoc=build/maven-${version}/luaj-@{platform}-${version}-javadoc.jar"/>
|
||||||
|
</exec>
|
||||||
|
</sequential>
|
||||||
|
</macrodef>
|
||||||
|
|
||||||
|
<macrodef name="sign_and_deploy">
|
||||||
|
<attribute name="platform"/>
|
||||||
|
<sequential>
|
||||||
|
<exec executable="mvn">
|
||||||
|
<arg value="gpg:sign-and-deploy-file"/>
|
||||||
|
<arg value="-Durl=http://oss.sonatype.org/service/local/staging/deploy/maven2"/>
|
||||||
|
<arg value="-DrepositoryId=nexus-releases"/>
|
||||||
|
<arg value="-DpomFile=build/maven-${version}/luaj-@{platform}-${version}.pom"/>
|
||||||
|
<arg value="-Dfile=build/maven-${version}/luaj-@{platform}-${version}.jar"/>
|
||||||
|
<arg value="-Dsources=build/maven-${version}/luaj-@{platform}-${version}-sources.jar"/>
|
||||||
|
<arg value="-Djavadoc=build/maven-${version}/luaj-@{platform}-${version}-javadoc.jar"/>
|
||||||
|
</exec>
|
||||||
|
</sequential>
|
||||||
|
</macrodef>
|
||||||
|
|
||||||
|
<macrodef name="prepare_and_install">
|
||||||
|
<attribute name="platform"/>
|
||||||
|
<sequential>
|
||||||
|
<prepare_files platform="@{platform}"/>
|
||||||
|
<exec executable="mvn">
|
||||||
|
<arg value="install:install-file"/>
|
||||||
|
<arg value="-Dfile=build/maven-${version}/luaj-@{platform}-${version}.jar"/>
|
||||||
|
<arg value="-DpomFile=build/maven-${version}/luaj-@{platform}-${version}.pom"/>
|
||||||
|
</exec>
|
||||||
|
</sequential>
|
||||||
|
</macrodef>
|
||||||
|
|
||||||
|
<macrodef name="prepare_and_snapshot">
|
||||||
|
<attribute name="platform"/>
|
||||||
|
<sequential>
|
||||||
|
<prepare_files platform="@{platform}" snapshot="-SNAPSHOT"/>
|
||||||
|
<shapshot_files platform="@{platform}"/>
|
||||||
|
</sequential>
|
||||||
|
</macrodef>
|
||||||
|
|
||||||
|
<macrodef name="prepare_and_deploy">
|
||||||
|
<attribute name="platform"/>
|
||||||
|
<sequential>
|
||||||
|
<prepare_files platform="@{platform}"/>
|
||||||
|
<sign_and_deploy platform="@{platform}"/>
|
||||||
|
</sequential>
|
||||||
|
</macrodef>
|
||||||
|
|
||||||
|
<target name="install">
|
||||||
|
<prepare_and_install platform="jse"/>
|
||||||
|
<prepare_and_install platform="jme"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="snapshot">
|
||||||
|
<prepare_and_snapshot platform="jse"/>
|
||||||
|
<prepare_and_snapshot platform="jme"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="deploy">
|
||||||
|
<prepare_and_deploy platform="jse"/>
|
||||||
|
<prepare_and_deploy platform="jme"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="usage">
|
||||||
|
<echo level="info">Usage: ant [-Dversion=${version}] -f build-maven.xml [install | shapshot | deploy]</echo>
|
||||||
|
</target>
|
||||||
|
</project>
|
||||||
113
build-midlet.xml
Normal file
113
build-midlet.xml
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<project name="sample" default="all" basedir=".">
|
||||||
|
<property file="version.properties"/>
|
||||||
|
|
||||||
|
<!-- find libs -->
|
||||||
|
<import file="build-libs.xml"/>
|
||||||
|
|
||||||
|
<!-- main script -->
|
||||||
|
<property name="script.name" value="hello"/>
|
||||||
|
<property name="script.dir" value="examples/lua"/>
|
||||||
|
|
||||||
|
<target name="clean">
|
||||||
|
<delete failonerror="false" dir="build"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="dirs">
|
||||||
|
<mkdir dir="build"/>
|
||||||
|
<mkdir dir="build/tool"/>
|
||||||
|
<mkdir dir="build/classes"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="tools" depends="dirs,bcel-lib,wtk-libs,microemulator-lib">
|
||||||
|
<javac destdir="build/tool" classpath="lib/bcel-5.2.jar">
|
||||||
|
<src path="src/core"/>
|
||||||
|
<src path="src/jse"/>
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- compile script into lua bytecode -->
|
||||||
|
<target name="luac" depends="tools">
|
||||||
|
<java classname="luac" classpath="build/tool">
|
||||||
|
<arg line="-o build/classes/${script.name}.lua"/>
|
||||||
|
<arg line="${script.dir}/${script.name}.lua"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- compile script into java bytecode -->
|
||||||
|
<target name="luajc" depends="tools,wtk-libs">
|
||||||
|
<java classname="luajc" classpath="build/tool:lib/bcel-5.2.jar">
|
||||||
|
<arg line="-verbose"/>
|
||||||
|
<arg line="-srcdir ${script.dir}"/>
|
||||||
|
<arg line="-destdir build/classes"/>
|
||||||
|
<arg line="${script.name}.lua"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="classes" depends="dirs,wtk-libs">
|
||||||
|
<mkdir dir="build/midlet/src"/>
|
||||||
|
<copy todir="build/midlet/src">
|
||||||
|
<fileset dir="src/core"/>
|
||||||
|
<fileset dir="src/jme"/>
|
||||||
|
<fileset dir="examples/jme"/>
|
||||||
|
<filterchain>
|
||||||
|
<tokenfilter><replacestring from='"Luaj 0.0"' to='"Luaj-jme ${version}"'/></tokenfilter>
|
||||||
|
</filterchain>
|
||||||
|
</copy>
|
||||||
|
<path id="wtk-libs">
|
||||||
|
<pathelement path="lib/cldcapi11.jar"/>
|
||||||
|
<pathelement path="lib/midpapi20.jar"/>
|
||||||
|
<pathelement path="lib/mmapi.jar"/>
|
||||||
|
</path>
|
||||||
|
<javac destdir="build/classes" encoding="utf-8" source="1.8" target="1.8" bootclasspathref="wtk-libs"
|
||||||
|
srcdir="build/midlet/src"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="jar" depends="luajc,classes">
|
||||||
|
<jar destfile="build/sample-plain.jar"
|
||||||
|
basedir="build/classes"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="obf" depends="jar,proguard-lib">
|
||||||
|
<taskdef resource="proguard/ant/task.properties" classpath="lib/proguard.jar" />
|
||||||
|
<proguard>
|
||||||
|
-injars build/sample-plain.jar
|
||||||
|
-outjars build/sample.jar
|
||||||
|
-libraryjars lib/midpapi20.jar
|
||||||
|
-libraryjars lib/cldcapi11.jar
|
||||||
|
-overloadaggressively
|
||||||
|
-repackageclasses ''
|
||||||
|
-microedition
|
||||||
|
|
||||||
|
-keep public class SampleMIDlet
|
||||||
|
-keep public class * extends org.luaj.vm2.LuaValue
|
||||||
|
</proguard>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="jad" depends="obf">
|
||||||
|
<length file="build/sample.jar" property="sample.jar.length" />
|
||||||
|
<echo level="info">Jar file length is ${sample.jar.length}</echo>
|
||||||
|
<manifest file="build/sample.jad">
|
||||||
|
<attribute name="Built-By" value="luaj-${version}"/>
|
||||||
|
<attribute name="MIDlet-Name" value="Luaj ${script.name}"/>
|
||||||
|
<attribute name="MIDlet-Version" value="${version}"/>
|
||||||
|
<attribute name="MIDlet-Vendor" value="luaj.org"/>
|
||||||
|
<attribute name="MIDlet-Description" value="Luaj Sample Midlet"/>
|
||||||
|
<attribute name="MIDlet-1" value="${script.name}-${version}, , SampleMIDlet"/>
|
||||||
|
<attribute name="MIDlet-Jar-URL" value="sample.jar"/>
|
||||||
|
<attribute name="MIDlet-Jar-Size" value="${sample.jar.length}"/>
|
||||||
|
<attribute name="script" value="${script.name}"/>
|
||||||
|
</manifest>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="package" depends="jad,jar,obf"/>
|
||||||
|
|
||||||
|
<target name="run" depends="jad,jar,obf,microemulator-lib">
|
||||||
|
<java jar="lib/microemulator.jar" fork="true">
|
||||||
|
<arg path="build/sample.jad"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="all" depends="clean,package,run"/>
|
||||||
|
|
||||||
|
</project>
|
||||||
68
build-perf.xml
Normal file
68
build-perf.xml
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<project default="all">
|
||||||
|
<import file="build.xml"/>
|
||||||
|
|
||||||
|
<property name="lua.command" value="lua"/>
|
||||||
|
<available file="luaj-jse-${version}.jar" property="luaj.lib.exists"/>
|
||||||
|
<available file="lib/jill-1.0.1.jar" property="jill.lib.exists"/>
|
||||||
|
<available file="lib/kahlua.jar" property="kahlua.lib.exists"/>
|
||||||
|
<available file="lib/mochalua-1.0.jar" property="mochalua.lib.exists"/>
|
||||||
|
|
||||||
|
<target name="luaj-lib" unless="luaj.lib.exists">
|
||||||
|
<antcall target="jar-jse"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="jill-lib" unless="jill.lib.exists">
|
||||||
|
<mkdir dir="lib"/>
|
||||||
|
<get src="http://jillcode.googlecode.com/files/jill-1.0.1.zip"
|
||||||
|
dest="lib/jill-1.0.1.zip"/>
|
||||||
|
<unzip src="lib/jill-1.0.1.zip" dest="lib" overwrite="true"/>
|
||||||
|
<ant dir="lib/jill-1.0.1" target="compile"/>
|
||||||
|
<jar destfile="lib/jill-1.0.1.jar" basedir="lib/jill-1.0.1/compiled"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="kahlua-lib" unless="kahlua.lib.exists">
|
||||||
|
<get src="http://kahlua.googlecode.com/files/kahlua.jar"
|
||||||
|
dest="lib/kahlua.jar"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="mochalua-lib" unless="mochalua.lib.exists">
|
||||||
|
<get src="http://mochalua.googlecode.com/files/Mochalua%201.0.jar"
|
||||||
|
dest="lib/mochalua-1.0.jar"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="perf-libs" depends="luaj-lib,bcel-lib,jill-lib,kahlua-lib,mochalua-lib"/>
|
||||||
|
|
||||||
|
<macrodef name="perftest">
|
||||||
|
<attribute name="program" default="lua"/>
|
||||||
|
<attribute name="luaprog" default="fannkuch.lua 10"/>
|
||||||
|
<attribute name="basedir" default="test/lua/perf/"/>
|
||||||
|
<sequential>
|
||||||
|
<echo level="info">------ @{program} @{luaprog}</echo>
|
||||||
|
<exec executable="bash">
|
||||||
|
<arg value="-c"/>
|
||||||
|
<arg value="time @{program} @{basedir}@{luaprog}"/>
|
||||||
|
</exec>
|
||||||
|
</sequential>
|
||||||
|
</macrodef>
|
||||||
|
|
||||||
|
|
||||||
|
<macrodef name="testcase">
|
||||||
|
<attribute name="luaprog" default="fannkuch.lua 10"/>
|
||||||
|
<sequential>
|
||||||
|
<echo level="info">=========== @{luaprog} =============</echo>
|
||||||
|
<perftest program="java -version" luaprog="" basedir=""/>
|
||||||
|
<perftest program="${lua.command}" luaprog="@{luaprog}"/>
|
||||||
|
<perftest program="java -cp luaj-jse-${version}.jar lua -n" luaprog="@{luaprog}"/>
|
||||||
|
<perftest program="java -cp luaj-jse-${version}.jar${path.separator}lib/bcel-5.2.jar lua -b" luaprog="@{luaprog}"/>
|
||||||
|
</sequential>
|
||||||
|
</macrodef>
|
||||||
|
|
||||||
|
<target name="alltests">
|
||||||
|
<testcase luaprog="binarytrees.lua 15"/>
|
||||||
|
<testcase luaprog="fannkuch.lua 10"/>
|
||||||
|
<testcase luaprog="nbody.lua 1000000"/>
|
||||||
|
<testcase luaprog="nsieve.lua 9"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="all" depends="alltests"/>
|
||||||
|
</project>
|
||||||
225
build.xml
Normal file
225
build.xml
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
<project default="jar-jse">
|
||||||
|
<property file="version.properties"/>
|
||||||
|
|
||||||
|
<property name="jar.name.jme" value="luaj-jme-${version}.jar"/>
|
||||||
|
<property name="jar.name.jse" value="luaj-jse-${version}.jar"/>
|
||||||
|
<property name="jar.name.sources" value="luaj-sources-${version}.jar"/>
|
||||||
|
|
||||||
|
<target name="clean-build">
|
||||||
|
<delete dir="build"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="clean" depends="clean-build">
|
||||||
|
<delete>
|
||||||
|
<fileset dir="." includes="luaj-*.jar"/>
|
||||||
|
</delete>
|
||||||
|
<delete dir="examples/android/bin"/>
|
||||||
|
<delete dir="examples/android/build"/>
|
||||||
|
<delete dir="examples/android/gen"/>
|
||||||
|
<delete dir="examples/android/libs"/>
|
||||||
|
<delete dir="examples/maven/target"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<import file="build-libs.xml"/>
|
||||||
|
|
||||||
|
<target name="parser" depends="javacc-lib">
|
||||||
|
<java classname="javacc" classpath="lib/javacc.jar">
|
||||||
|
<arg line="grammar/LuaParser.jj"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="plain-parser" depends="javacc-lib">
|
||||||
|
<java dir="src/jse" fork="true" classname="javacc" classpath="lib/javacc.jar">
|
||||||
|
<arg line="../../grammar/Lua52.jj"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="compile-jme" depends="wtk-libs,bcel-lib">
|
||||||
|
<delete dir="build/jme/src"/>
|
||||||
|
<mkdir dir="build/jme/src"/>
|
||||||
|
<mkdir dir="build/jme/classes"/>
|
||||||
|
<copy todir="build/jme/src">
|
||||||
|
<fileset dir="src/core"/>
|
||||||
|
<fileset dir="src/jme"/>
|
||||||
|
<filterchain>
|
||||||
|
<tokenfilter><replacestring from='"Luaj 0.0"' to='"Luaj-jme ${version}"'/></tokenfilter>
|
||||||
|
</filterchain>
|
||||||
|
</copy>
|
||||||
|
|
||||||
|
<path id="wtk-libs">
|
||||||
|
<pathelement path="lib/cldcapi11.jar"/>
|
||||||
|
<pathelement path="lib/midpapi20.jar"/>
|
||||||
|
<pathelement path="lib/mmapi.jar"/>
|
||||||
|
</path>
|
||||||
|
<javac includeantruntime="false" destdir="build/jme/classes" encoding="utf-8" source="1.8" target="1.8" bootclasspathref="wtk-libs"
|
||||||
|
debug="on"
|
||||||
|
srcdir="build/jme/src"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="compile-jse" depends="wtk-libs,bcel-lib">
|
||||||
|
<delete dir="build/jse/src"/>
|
||||||
|
<mkdir dir="build/jse/src"/>
|
||||||
|
<mkdir dir="build/jse/classes"/>
|
||||||
|
<copy todir="build/jse/src">
|
||||||
|
<fileset dir="src/core"/>
|
||||||
|
<filterchain>
|
||||||
|
<tokenfilter><replacestring from='"Luaj 0.0"' to='"Luaj-jse ${version}"'/></tokenfilter>
|
||||||
|
</filterchain>
|
||||||
|
</copy>
|
||||||
|
<copy todir="build/jse/src">
|
||||||
|
<fileset dir="src/jse"/>
|
||||||
|
<filterchain>
|
||||||
|
<tokenfilter><replacestring from='<String>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<Stat>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<Exp>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<Name>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<Block>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<TableField>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<VarExp>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<Exp.VarExp>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<Object,String>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<Double,String>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<Integer,Integer>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<Integer,LocalVariableGen>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<Exp,Integer>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<String,byte[]>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<String,Variable>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<LuaValue,String>' to=''/></tokenfilter>
|
||||||
|
<tokenfilter><replacestring from='<LuaString,String>' to=''/></tokenfilter>
|
||||||
|
</filterchain>
|
||||||
|
</copy>
|
||||||
|
|
||||||
|
<javac destdir="build/jse/classes" encoding="utf-8" source="1.8" target="1.8"
|
||||||
|
classpath="lib/bcel-5.2.jar"
|
||||||
|
debug="on"
|
||||||
|
srcdir="build/jse/src"
|
||||||
|
excludes="**/script/*,**/Lua2Java*,**/server/*,lua*"
|
||||||
|
includeantruntime="false"
|
||||||
|
/>
|
||||||
|
<javac destdir="build/jse/classes" encoding="utf-8" source="1.8" target="1.8"
|
||||||
|
classpath="build/jse/classes"
|
||||||
|
debug="on"
|
||||||
|
srcdir="build/jse/src"
|
||||||
|
includes="**/script/*,**/Lua2Java*,**/server/*"
|
||||||
|
includeantruntime="false"
|
||||||
|
/>
|
||||||
|
<javac destdir="build/jse/classes" encoding="utf-8" source="1.8" target="1.8"
|
||||||
|
classpath="build/jse/classes"
|
||||||
|
debug="on"
|
||||||
|
srcdir="build/jse/src"
|
||||||
|
includes="lua*"
|
||||||
|
includeantruntime="false"
|
||||||
|
/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="compile" depends="compile-jme,compile-jse" />
|
||||||
|
|
||||||
|
<target name="jar-jme" depends="compile-jme">
|
||||||
|
<jar destfile="${jar.name.jme}" basedir="build/jme/classes"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="jar-jse" depends="compile-jse">
|
||||||
|
<jar destfile="${jar.name.jse}">
|
||||||
|
<fileset dir="build/jse/classes"/>
|
||||||
|
<fileset dir="src/jse/">
|
||||||
|
<include name="META-INF/services/**"/>
|
||||||
|
</fileset>
|
||||||
|
</jar>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="jar-jse-sources" depends="compile">
|
||||||
|
<jar destfile="${jar.name.sources}">
|
||||||
|
<fileset dir="build/jme/src"/>
|
||||||
|
<fileset dir="build/jse/src"/>
|
||||||
|
</jar>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="doc">
|
||||||
|
<delete dir="docs/api"/>
|
||||||
|
<mkdir dir="docs/api"/>
|
||||||
|
<javadoc defaultexcludes="yes"
|
||||||
|
destdir="docs/api"
|
||||||
|
author="true"
|
||||||
|
version="true"
|
||||||
|
use="true"
|
||||||
|
windowtitle="Luaj API">
|
||||||
|
<fileset dir="src/core" defaultexcludes="yes" includes="org/luaj/vm2/*.java,org/luaj/vm2/compiler/LuaC.java,org/luaj/vm2/lib/*.java"/>
|
||||||
|
<fileset dir="src/jse" defaultexcludes="yes" includes="org/luaj/vm2/lib/jse/*.java,org/luaj/vm2/luajc/LuaJC.java,org/luaj/vm2/server/*.java"/>
|
||||||
|
<fileset dir="src/jme" defaultexcludes="yes" includes="org/luaj/vm2/lib/jme/*.java"/>
|
||||||
|
<doctitle><![CDATA[<h1>Luaj API</h1>]]></doctitle>
|
||||||
|
<bottom><![CDATA[<i>Copyright © 2007-2015 Luaj.org. All Rights Reserved.</i>]]></bottom>
|
||||||
|
<tag name="todo" scope="all" description="To do:"/>
|
||||||
|
<group title="Core VM" packages="org.luaj.vm.*"/>
|
||||||
|
<link offline="true" href="http://sourceforge.net/projects/luaj/" packagelistLoc="C:\tmp"/>
|
||||||
|
<link href="http://sourceforge.net/projects/luaj/"/>
|
||||||
|
</javadoc>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="dist" depends="all,doc">
|
||||||
|
<delete dir="build/luaj-${version}"/>
|
||||||
|
<mkdir dir="build/luaj-${version}/src"/>
|
||||||
|
<mkdir dir="build/luaj-${version}/lib"/>
|
||||||
|
<copy todir="build/luaj-${version}/src">
|
||||||
|
<fileset dir="src">
|
||||||
|
<exclude name="src/test/**"/>
|
||||||
|
<exclude name="**/antlr/**"/>
|
||||||
|
<exclude name="**/lst/**"/>
|
||||||
|
<exclude name="**/JavaCodeGenerator.java"/>
|
||||||
|
<exclude name="**/LuaJCompiler.java"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
<copy todir="build/luaj-${version}/test">
|
||||||
|
<fileset dir="test"/>
|
||||||
|
</copy>
|
||||||
|
<copy todir="build/luaj-${version}/examples">
|
||||||
|
<fileset dir="examples">
|
||||||
|
<include name="android/*.*"/>
|
||||||
|
<include name="android/assets/**"/>
|
||||||
|
<include name="android/res/**"/>
|
||||||
|
<include name="android/src/**"/>
|
||||||
|
<include name="jme/*.java"/>
|
||||||
|
<include name="jse/*.java"/>
|
||||||
|
<include name="lua/*.*"/>
|
||||||
|
<include name="maven/pom.xml"/>
|
||||||
|
<include name="maven/src/**"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
<copy todir="build/luaj-${version}/lib">
|
||||||
|
<fileset dir=".">
|
||||||
|
<include name="*-${version}.jar"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
<copy todir="build/luaj-${version}">
|
||||||
|
<fileset dir=".">
|
||||||
|
<include name="build.xml"/>
|
||||||
|
<include name="build-libs.xml"/>
|
||||||
|
<include name="build-coverage.xml"/>
|
||||||
|
<include name="version.properties"/>
|
||||||
|
<include name="wtk.xml"/>
|
||||||
|
<include name="README.html"/>
|
||||||
|
<include name="names.csv"/>
|
||||||
|
<include name=".classpath"/>
|
||||||
|
<include name=".project"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
<copy todir="build/luaj-${version}/docs">
|
||||||
|
<fileset dir="docs"/>
|
||||||
|
</copy>
|
||||||
|
<zip destfile="luaj-${version}.zip"
|
||||||
|
basedir="build" includes="luaj-${version}/**"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="mvn_install" depends="jar-jse">
|
||||||
|
<exec executable="mvn">
|
||||||
|
<arg value="install:install-file"/>
|
||||||
|
<arg value="-Dfile=${jar.name.jse}"/>
|
||||||
|
<arg value="-DgroupId=org.luaj"/>
|
||||||
|
<arg value="-DartifactId=luaj-jse"/>
|
||||||
|
<arg value="-Dversion=${version}"/>
|
||||||
|
<arg value="-Dpackaging=jar"/>
|
||||||
|
</exec>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="all" depends="clean,jar-jme,jar-jse,jar-jse-sources"/>
|
||||||
|
|
||||||
|
</project>
|
||||||
36
core/pom.xml
36
core/pom.xml
@@ -1,36 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>org.openautonomousconnection.luaj</groupId>
|
|
||||||
<artifactId>parent</artifactId>
|
|
||||||
<version>3.0.2</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>core</artifactId>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>attach-sources</id>
|
|
||||||
<goals><goal>jar</goal></goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<source>${maven.compiler.release}</source>
|
|
||||||
<target>${maven.compiler.release}</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,692 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2009 Luaj.org. All rights reserved.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
******************************************************************************/
|
|
||||||
package org.luaj.vm2;
|
|
||||||
|
|
||||||
import org.luaj.vm2.libs.DebugLib.CallFrame;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extension of {@link LuaFunction} which executes lua bytecode.
|
|
||||||
* <p>
|
|
||||||
* A {@link LuaClosure} is a combination of a {@link Prototype}
|
|
||||||
* and a {@link LuaValue} to use as an environment for execution.
|
|
||||||
* Normally the {@link LuaValue} is a {@link Globals} in which case the environment
|
|
||||||
* will contain standard lua libraries.
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* There are three main ways {@link LuaClosure} instances are created:
|
|
||||||
* <ul>
|
|
||||||
* <li>Construct an instance using {@link #LuaClosure(Prototype, LuaValue)}</li>
|
|
||||||
* <li>Construct it indirectly by loading a chunk via {@link Globals#load(java.io.Reader, String)}
|
|
||||||
* <li>Execute the lua bytecode {@link Lua#OP_CLOSURE} as part of bytecode processing
|
|
||||||
* </ul>
|
|
||||||
* <p>
|
|
||||||
* To construct it directly, the {@link Prototype} is typically created via a compiler such as
|
|
||||||
* {@link org.luaj.vm2.compiler.LuaC}:
|
|
||||||
* <pre> {@code
|
|
||||||
* 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();
|
|
||||||
* }</pre>
|
|
||||||
* <p>
|
|
||||||
* To construct it indirectly, the {@link Globals#load(java.io.Reader, String)} method may be used:
|
|
||||||
* <pre> {@code
|
|
||||||
* 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();
|
|
||||||
* }</pre>
|
|
||||||
* <p>
|
|
||||||
* 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 {@link LuaFunction} but not a {@link LuaClosure}.
|
|
||||||
* <p>
|
|
||||||
* Since a {@link LuaClosure} is a {@link LuaFunction} which is a {@link LuaValue},
|
|
||||||
* all the value operations can be used directly such as:
|
|
||||||
* <ul>
|
|
||||||
* <li>{@link LuaValue#call()}</li>
|
|
||||||
* <li>{@link LuaValue#call(LuaValue)}</li>
|
|
||||||
* <li>{@link LuaValue#invoke()}</li>
|
|
||||||
* <li>{@link LuaValue#invoke(Varargs)}</li>
|
|
||||||
* <li>{@link LuaValue#method(String)}</li>
|
|
||||||
* <li>{@link LuaValue#method(String,LuaValue)}</li>
|
|
||||||
* <li>{@link LuaValue#invokemethod(String)}</li>
|
|
||||||
* <li>{@link LuaValue#invokemethod(String,Varargs)}</li>
|
|
||||||
* <li> ...</li>
|
|
||||||
* </ul>
|
|
||||||
* @see LuaValue
|
|
||||||
* @see LuaFunction
|
|
||||||
* @see LuaValue#isclosure()
|
|
||||||
* @see LuaValue#checkclosure()
|
|
||||||
* @see LuaValue#optclosure(LuaClosure)
|
|
||||||
* @see LoadState
|
|
||||||
* @see Globals#compiler
|
|
||||||
*/
|
|
||||||
public class LuaClosure extends LuaFunction {
|
|
||||||
private static final UpValue[] NOUPVALUES = new UpValue[0];
|
|
||||||
|
|
||||||
public final Prototype p;
|
|
||||||
|
|
||||||
public UpValue[] upValues;
|
|
||||||
|
|
||||||
final Globals globals;
|
|
||||||
|
|
||||||
/** Create a closure around a Prototype with a specific environment.
|
|
||||||
* If the prototype has upvalues, the environment will be written into the first upvalue.
|
|
||||||
* @param p the Prototype to construct this Closure for.
|
|
||||||
* @param env the environment to associate with the closure.
|
|
||||||
*/
|
|
||||||
public LuaClosure(Prototype p, LuaValue env) {
|
|
||||||
this.p = p;
|
|
||||||
this.initupvalue1(env);
|
|
||||||
globals = env instanceof Globals? (Globals) env: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initupvalue1(LuaValue env) {
|
|
||||||
if (p.upvalues == null || p.upvalues.length == 0)
|
|
||||||
this.upValues = NOUPVALUES;
|
|
||||||
else {
|
|
||||||
this.upValues = new UpValue[p.upvalues.length];
|
|
||||||
this.upValues[0] = new UpValue(new LuaValue[] {env}, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean isclosure() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LuaClosure optclosure(LuaClosure defval) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LuaClosure checkclosure() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String tojstring() {
|
|
||||||
return "function: " + p.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private List<LuaValue[]> stackPool = new ArrayList<>();
|
|
||||||
private LuaValue[] getNewStack() {
|
|
||||||
if (stackPool.isEmpty()) {
|
|
||||||
return getNewStackRaw();
|
|
||||||
} else {
|
|
||||||
return stackPool.remove(stackPool.size() - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private LuaValue[] getNewStackRaw() {
|
|
||||||
int max = p.maxstacksize;
|
|
||||||
LuaValue[] stack = new LuaValue[max];
|
|
||||||
System.arraycopy(NILS, 0, stack, 0, max);
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void releaseStack(LuaValue[] stack) {
|
|
||||||
System.arraycopy(NILS, 0, stack, 0, stack.length);
|
|
||||||
stackPool.add(stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final LuaValue call() {
|
|
||||||
LuaValue[] stack = getNewStack();
|
|
||||||
LuaValue result = execute(stack,NONE).arg1();
|
|
||||||
releaseStack(stack);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final LuaValue call(LuaValue arg) {
|
|
||||||
LuaValue[] stack = getNewStack();
|
|
||||||
LuaValue result;
|
|
||||||
switch ( p.numparams ) {
|
|
||||||
default:
|
|
||||||
stack[0]=arg;
|
|
||||||
result = execute(stack,NONE).arg1();
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
result = execute(stack,arg).arg1();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
releaseStack(stack);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final LuaValue call(LuaValue arg1, LuaValue arg2) {
|
|
||||||
LuaValue[] stack = getNewStack();
|
|
||||||
LuaValue result;
|
|
||||||
switch ( p.numparams ) {
|
|
||||||
default:
|
|
||||||
stack[0]=arg1;
|
|
||||||
stack[1]=arg2;
|
|
||||||
result = execute(stack,NONE).arg1();
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
stack[0]=arg1;
|
|
||||||
result = execute(stack,arg2).arg1();
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
result = execute(stack,p.is_vararg!=0 ? varargsOf(arg1,arg2) : NONE).arg1();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
releaseStack(stack);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
|
|
||||||
LuaValue[] stack = getNewStack();
|
|
||||||
LuaValue result;
|
|
||||||
switch ( p.numparams ) {
|
|
||||||
default:
|
|
||||||
stack[0]=arg1;
|
|
||||||
stack[1]=arg2;
|
|
||||||
stack[2]=arg3;
|
|
||||||
result = execute(stack,NONE).arg1();
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
stack[0]=arg1;
|
|
||||||
stack[1]=arg2;
|
|
||||||
result = execute(stack,arg3).arg1();
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
stack[0]=arg1;
|
|
||||||
result = execute(stack,p.is_vararg!=0 ? varargsOf(arg2,arg3) : NONE).arg1();
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
result = execute(stack,p.is_vararg!=0 ? varargsOf(arg1,arg2,arg3) : NONE).arg1();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
releaseStack(stack);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final Varargs invoke(Varargs varargs) {
|
|
||||||
return onInvoke(varargs).eval();
|
|
||||||
}
|
|
||||||
|
|
||||||
public final Varargs onInvoke(Varargs varargs) {
|
|
||||||
LuaValue[] stack = getNewStack();
|
|
||||||
for ( int i=0; i<p.numparams; i++ )
|
|
||||||
stack[i] = varargs.arg(i+1);
|
|
||||||
Varargs result = execute(stack,p.is_vararg!=0 ? varargs.subargs(p.numparams+1) : NONE);
|
|
||||||
if (result instanceof LuaValue) {
|
|
||||||
releaseStack(stack);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Varargs execute( LuaValue[] stack, Varargs varargs ) {
|
|
||||||
// loop through instructions
|
|
||||||
int i,a,b,c,pc=0,top=0;
|
|
||||||
LuaValue o;
|
|
||||||
Varargs v = NONE;
|
|
||||||
int[] code = p.code;
|
|
||||||
LuaValue[] k = p.k;
|
|
||||||
|
|
||||||
// upvalues are only possible when closures create closures
|
|
||||||
// TODO: use linked list.
|
|
||||||
UpValue[] openups = p.p.length>0? new UpValue[stack.length]: null;
|
|
||||||
|
|
||||||
// allow for debug hooks
|
|
||||||
if (globals != null && globals.debuglib != null)
|
|
||||||
globals.debuglib.onCall( this, varargs, stack );
|
|
||||||
|
|
||||||
// process instructions
|
|
||||||
try {
|
|
||||||
for (; true; ++pc) {
|
|
||||||
if (Thread.currentThread().isInterrupted()) {
|
|
||||||
throw new LuaError("interrupted");
|
|
||||||
}
|
|
||||||
if (globals != null && globals.debuglib != null)
|
|
||||||
globals.debuglib.onInstruction( pc, v, top );
|
|
||||||
|
|
||||||
// pull out instruction
|
|
||||||
i = code[pc];
|
|
||||||
a = ((i>>6) & 0xff);
|
|
||||||
|
|
||||||
// process the op code
|
|
||||||
switch ( i & 0x3f ) {
|
|
||||||
|
|
||||||
case Lua.OP_MOVE:/* A B R(A):= R(B) */
|
|
||||||
stack[a] = stack[i>>>23];
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_LOADK:/* A Bx R(A):= Kst(Bx) */
|
|
||||||
stack[a] = k[i>>>14];
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_LOADKX:/* A R(A) := Kst(extra arg) */
|
|
||||||
++pc;
|
|
||||||
i = code[pc];
|
|
||||||
if ((i & 0x3f) != Lua.OP_EXTRAARG) {
|
|
||||||
int op = i & 0x3f;
|
|
||||||
throw new LuaError("OP_EXTRAARG expected after OP_LOADKX, got " +
|
|
||||||
(op < Print.OPNAMES.length - 1 ? Print.OPNAMES[op] : "UNKNOWN_OP_" + op));
|
|
||||||
}
|
|
||||||
stack[a] = k[i>>>6];
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_LOADBOOL:/* A B C R(A):= (Bool)B: if (C) pc++ */
|
|
||||||
stack[a] = (i>>>23!=0)? LuaValue.TRUE: LuaValue.FALSE;
|
|
||||||
if ((i&(0x1ff<<14)) != 0)
|
|
||||||
++pc; /* skip next instruction (if C) */
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_LOADNIL: /* A B R(A):= ...:= R(A+B):= nil */
|
|
||||||
for ( b=i>>>23; b-->=0; )
|
|
||||||
stack[a++] = LuaValue.NIL;
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_GETUPVAL: /* A B R(A):= UpValue[B] */
|
|
||||||
stack[a] = upValues[i>>>23].getValue();
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_GETTABUP: /* A B C R(A) := UpValue[B][RK(C)] */
|
|
||||||
stack[a] = upValues[i>>>23].getValue().get((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_GETTABLE: /* A B C R(A):= R(B)[RK(C)] */
|
|
||||||
stack[a] = stack[i>>>23].get((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_SETTABUP: /* A B C UpValue[A][RK(B)] := RK(C) */
|
|
||||||
upValues[a].getValue().set(((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]), (c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_SETUPVAL: /* A B UpValue[B]:= R(A) */
|
|
||||||
upValues[i>>>23].setValue(stack[a]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_SETTABLE: /* A B C R(A)[RK(B)]:= RK(C) */
|
|
||||||
stack[a].set(((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]), (c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_NEWTABLE: /* A B C R(A):= {} (size = B,C) */
|
|
||||||
stack[a] = new LuaTable(i>>>23,(i>>14)&0x1ff);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_SELF: /* A B C R(A+1):= R(B): R(A):= R(B)[RK(C)] */
|
|
||||||
stack[a+1] = (o = stack[i>>>23]);
|
|
||||||
stack[a] = o.get((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_ADD: /* A B C R(A):= RK(B) + RK(C) */
|
|
||||||
stack[a] = ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).add((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_SUB: /* A B C R(A):= RK(B) - RK(C) */
|
|
||||||
stack[a] = ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).sub((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_MUL: /* A B C R(A):= RK(B) * RK(C) */
|
|
||||||
stack[a] = ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).mul((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_DIV: /* A B C R(A):= RK(B) / RK(C) */
|
|
||||||
stack[a] = ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).div((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_IDIV: /* A B C R(A):= RK(B) // RK(C) */
|
|
||||||
stack[a] = ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).idiv((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_BAND: /* A B C R(A):= RK(B) & RK(C) */
|
|
||||||
stack[a] = ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).band((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_BOR: /* A B C R(A):= RK(B) | RK(C) */
|
|
||||||
stack[a] = ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).bor((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_BXOR: /* A B C R(A):= RK(B) ~ RK(C) */
|
|
||||||
stack[a] = ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).bxor((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_SHL: /* A B C R(A):= RK(B) << RK(C) */
|
|
||||||
stack[a] = ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).shl((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_SHR: /* A B C R(A):= RK(B) >> RK(C) */
|
|
||||||
stack[a] = ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).shr((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_MOD: /* A B C R(A):= RK(B) % RK(C) */
|
|
||||||
stack[a] = ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).mod((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_POW: /* A B C R(A):= RK(B) ^ RK(C) */
|
|
||||||
stack[a] = ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).pow((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_UNM: /* A B R(A):= -R(B) */
|
|
||||||
stack[a] = stack[i>>>23].neg();
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_BNOT: /* A B R(A):= ~R(B) */
|
|
||||||
stack[a] = stack[i>>>23].bnot();
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_NOT: /* A B R(A):= not R(B) */
|
|
||||||
stack[a] = stack[i>>>23].not();
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_LEN: /* A B R(A):= length of R(B) */
|
|
||||||
stack[a] = stack[i>>>23].len();
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_CONCAT: /* A B C R(A):= R(B).. ... ..R(C) */
|
|
||||||
b = i>>>23;
|
|
||||||
c = (i>>14)&0x1ff;
|
|
||||||
{
|
|
||||||
if ( c > b+1 ) {
|
|
||||||
Buffer sb = stack[c].buffer();
|
|
||||||
while ( --c>=b )
|
|
||||||
sb.concatTo(stack[c]);
|
|
||||||
stack[a] = sb.value();
|
|
||||||
} else {
|
|
||||||
stack[a] = stack[c-1].concat(stack[c]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_JMP: /* A sBx pc+=sBx; if (A) close all upvalues >= R(A - 1) */
|
|
||||||
pc += (i>>>14)-0x1ffff;
|
|
||||||
if (a > 0) {
|
|
||||||
for (--a, b = openups.length; --b>=0; )
|
|
||||||
if (openups[b] != null && openups[b].index >= a) {
|
|
||||||
openups[b].close();
|
|
||||||
openups[b] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_EQ: /* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */
|
|
||||||
if ( ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).eq_b((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]) != (a!=0) )
|
|
||||||
++pc;
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_LT: /* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */
|
|
||||||
if ( ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).lt_b((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]) != (a!=0) )
|
|
||||||
++pc;
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_LE: /* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
|
|
||||||
if ( ((b=i>>>23)>0xff? k[b&0x0ff]: stack[b]).lteq_b((c=(i>>14)&0x1ff)>0xff? k[c&0x0ff]: stack[c]) != (a!=0) )
|
|
||||||
++pc;
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_TEST: /* A C if not (R(A) <=> C) then pc++ */
|
|
||||||
if ( stack[a].toboolean() != ((i&(0x1ff<<14))!=0) )
|
|
||||||
++pc;
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_TESTSET: /* A B C if (R(B) <=> C) then R(A):= R(B) else pc++ */
|
|
||||||
/* note: doc appears to be reversed */
|
|
||||||
if ( (o=stack[i>>>23]).toboolean() != ((i&(0x1ff<<14))!=0) )
|
|
||||||
++pc;
|
|
||||||
else
|
|
||||||
stack[a] = o; // TODO: should be sBx?
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_CALL: /* A B C R(A), ... ,R(A+C-2):= R(A)(R(A+1), ... ,R(A+B-1)) */
|
|
||||||
switch ( i & (Lua.MASK_B | Lua.MASK_C) ) {
|
|
||||||
case (1<<Lua.POS_B) | (0<<Lua.POS_C): v=stack[a].invoke(NONE); top=a+v.narg(); continue;
|
|
||||||
case (2<<Lua.POS_B) | (0<<Lua.POS_C): v=stack[a].invoke(stack[a+1]); top=a+v.narg(); continue;
|
|
||||||
case (1<<Lua.POS_B) | (1<<Lua.POS_C): stack[a].call(); continue;
|
|
||||||
case (2<<Lua.POS_B) | (1<<Lua.POS_C): stack[a].call(stack[a+1]); continue;
|
|
||||||
case (3<<Lua.POS_B) | (1<<Lua.POS_C): stack[a].call(stack[a+1],stack[a+2]); continue;
|
|
||||||
case (4<<Lua.POS_B) | (1<<Lua.POS_C): stack[a].call(stack[a+1],stack[a+2],stack[a+3]); continue;
|
|
||||||
case (1<<Lua.POS_B) | (2<<Lua.POS_C): stack[a] = stack[a].call(); continue;
|
|
||||||
case (2<<Lua.POS_B) | (2<<Lua.POS_C): stack[a] = stack[a].call(stack[a+1]); continue;
|
|
||||||
case (3<<Lua.POS_B) | (2<<Lua.POS_C): stack[a] = stack[a].call(stack[a+1],stack[a+2]); continue;
|
|
||||||
case (4<<Lua.POS_B) | (2<<Lua.POS_C): stack[a] = stack[a].call(stack[a+1],stack[a+2],stack[a+3]); continue;
|
|
||||||
default:
|
|
||||||
b = i>>>23;
|
|
||||||
c = (i>>14)&0x1ff;
|
|
||||||
v = stack[a].invoke(b>0?
|
|
||||||
varargsOf(stack, a+1, b-1): // exact arg count
|
|
||||||
varargsOf(stack, a+1, top-v.narg()-(a+1), v)); // from prev top
|
|
||||||
if ( c > 0 ) {
|
|
||||||
v.copyto(stack, a, c-1);
|
|
||||||
v = NONE;
|
|
||||||
} else {
|
|
||||||
top = a + v.narg();
|
|
||||||
v = v.dealias();
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Lua.OP_TAILCALL: /* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */
|
|
||||||
switch ( i & Lua.MASK_B ) {
|
|
||||||
case (1<<Lua.POS_B): return new TailcallVarargs(stack[a], NONE);
|
|
||||||
case (2<<Lua.POS_B): return new TailcallVarargs(stack[a], stack[a+1]);
|
|
||||||
case (3<<Lua.POS_B): return new TailcallVarargs(stack[a], varargsOf(stack[a+1],stack[a+2]));
|
|
||||||
case (4<<Lua.POS_B): return new TailcallVarargs(stack[a], varargsOf(stack[a+1],stack[a+2],stack[a+3]));
|
|
||||||
default:
|
|
||||||
b = i>>>23;
|
|
||||||
v = b>0?
|
|
||||||
varargsOf(stack,a+1,b-1): // exact arg count
|
|
||||||
varargsOf(stack, a+1, top-v.narg()-(a+1), v); // from prev top
|
|
||||||
return new TailcallVarargs( stack[a], v );
|
|
||||||
}
|
|
||||||
|
|
||||||
case Lua.OP_RETURN: /* A B return R(A), ... ,R(A+B-2) (see note) */
|
|
||||||
b = i>>>23;
|
|
||||||
switch ( b ) {
|
|
||||||
case 0: return varargsOf(stack, a, top-v.narg()-a, v);
|
|
||||||
case 1: return NONE;
|
|
||||||
case 2: return stack[a];
|
|
||||||
default:
|
|
||||||
return varargsOf(stack, a, b-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
case Lua.OP_FORLOOP: /* A sBx R(A)+=R(A+2): if R(A) <?= R(A+1) then { pc+=sBx: R(A+3)=R(A) }*/
|
|
||||||
{
|
|
||||||
LuaValue limit = stack[a + 1];
|
|
||||||
LuaValue step = stack[a + 2];
|
|
||||||
LuaValue idx = stack[a].add(step);
|
|
||||||
if (step.gt_b(0)? idx.lteq_b(limit): idx.gteq_b(limit)) {
|
|
||||||
stack[a] = idx;
|
|
||||||
stack[a + 3] = idx;
|
|
||||||
pc += (i>>>14)-0x1ffff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_FORPREP: /* A sBx R(A)-=R(A+2): pc+=sBx */
|
|
||||||
{
|
|
||||||
LuaValue init = stack[a].checknumber("'for' initial value must be a number");
|
|
||||||
LuaValue limit = stack[a + 1].checknumber("'for' limit must be a number");
|
|
||||||
LuaValue step = stack[a + 2].checknumber("'for' step must be a number");
|
|
||||||
stack[a] = init.sub(step);
|
|
||||||
stack[a + 1] = limit;
|
|
||||||
stack[a + 2] = step;
|
|
||||||
pc += (i>>>14)-0x1ffff;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_TFORCALL: /* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); */
|
|
||||||
v = stack[a].invoke(varargsOf(stack[a+1],stack[a+2]));
|
|
||||||
c = (i>>14) & 0x1ff;
|
|
||||||
while (--c >= 0)
|
|
||||||
stack[a+3+c] = v.arg(c+1);
|
|
||||||
v = NONE;
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_TFORLOOP: /* A sBx if R(A+1) ~= nil then { R(A)=R(A+1); pc += sBx */
|
|
||||||
if (!stack[a+1].isnil()) { /* continue loop? */
|
|
||||||
stack[a] = stack[a+1]; /* save control varible. */
|
|
||||||
pc += (i>>>14)-0x1ffff;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_SETLIST: /* A B C R(A)[(C-1)*FPF+i]:= R(A+i), 1 <= i <= B */
|
|
||||||
{
|
|
||||||
if ( (c=(i>>14)&0x1ff) == 0 )
|
|
||||||
c = code[++pc];
|
|
||||||
int offset = (c-1) * Lua.LFIELDS_PER_FLUSH;
|
|
||||||
o = stack[a];
|
|
||||||
if ( (b=i>>>23) == 0 ) {
|
|
||||||
b = top - a - 1;
|
|
||||||
int m = b - v.narg();
|
|
||||||
int j=1;
|
|
||||||
for ( ;j<=m; j++ )
|
|
||||||
o.set(offset+j, stack[a + j]);
|
|
||||||
for ( ;j<=b; j++ )
|
|
||||||
o.set(offset+j, v.arg(j-m));
|
|
||||||
} else {
|
|
||||||
o.presize( offset + b );
|
|
||||||
for (int j=1; j<=b; j++)
|
|
||||||
o.set(offset+j, stack[a + j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_CLOSURE: /* A Bx R(A):= closure(KPROTO[Bx]) */
|
|
||||||
{
|
|
||||||
Prototype newp = p.p[i>>>14];
|
|
||||||
LuaClosure ncl = new LuaClosure(newp, globals);
|
|
||||||
Upvaldesc[] uv = newp.upvalues;
|
|
||||||
for ( int j=0, nup=uv.length; j<nup; ++j ) {
|
|
||||||
if (uv[j].instack) /* upvalue refes to local variable? */
|
|
||||||
ncl.upValues[j] = findupval(stack, uv[j].idx, openups);
|
|
||||||
else /* get upvalue from enclosing function */
|
|
||||||
ncl.upValues[j] = upValues[uv[j].idx];
|
|
||||||
}
|
|
||||||
stack[a] = ncl;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_VARARG: /* A B R(A), R(A+1), ..., R(A+B-1) = vararg */
|
|
||||||
b = i>>>23;
|
|
||||||
if ( b == 0 ) {
|
|
||||||
top = a + (b = varargs.narg());
|
|
||||||
v = varargs;
|
|
||||||
} else {
|
|
||||||
for ( int j=1; j<b; ++j )
|
|
||||||
stack[a+j-1] = varargs.arg(j);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case Lua.OP_EXTRAARG:
|
|
||||||
throw new java.lang.IllegalArgumentException("Uexecutable opcode: OP_EXTRAARG");
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new java.lang.IllegalArgumentException("Illegal opcode: " + (i & 0x3f));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch ( LuaError le ) {
|
|
||||||
if (le.traceback == null)
|
|
||||||
processErrorHooks(le, p, pc);
|
|
||||||
throw le;
|
|
||||||
} catch ( Exception e ) {
|
|
||||||
LuaError le = new LuaError(e);
|
|
||||||
processErrorHooks(le, p, pc);
|
|
||||||
throw le;
|
|
||||||
} finally {
|
|
||||||
if ( openups != null )
|
|
||||||
for ( int u=openups.length; --u>=0; )
|
|
||||||
if ( openups[u] != null )
|
|
||||||
openups[u].close();
|
|
||||||
if (globals != null && globals.debuglib != null)
|
|
||||||
globals.debuglib.onReturn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the error hook if there is one
|
|
||||||
* @param msg the message to use in error hook processing.
|
|
||||||
* */
|
|
||||||
LuaValue errorHook(LuaValue msgobj, String msg, int level) {
|
|
||||||
if (globals == null ) return LuaValue.valueOf(msg);
|
|
||||||
final LuaThread r = globals.running;
|
|
||||||
if (r.errorfunc == null)
|
|
||||||
return LuaValue.valueOf(globals.debuglib != null?
|
|
||||||
msg + "\n" + globals.debuglib.traceback(level):
|
|
||||||
msg);
|
|
||||||
final LuaValue e = r.errorfunc;
|
|
||||||
r.errorfunc = null;
|
|
||||||
try {
|
|
||||||
return e.call(msgobj != null ? msgobj : LuaValue.NIL);
|
|
||||||
} catch ( Throwable t ) {
|
|
||||||
return LuaValue.valueOf("error in error handling");
|
|
||||||
} finally {
|
|
||||||
r.errorfunc = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processErrorHooks(LuaError le, Prototype p, int pc) {
|
|
||||||
String file = "?";
|
|
||||||
int line = -1;
|
|
||||||
{
|
|
||||||
CallFrame frame = null;
|
|
||||||
if (globals != null && globals.debuglib != null) {
|
|
||||||
frame = globals.debuglib.getCallFrame(le.level);
|
|
||||||
if (frame != null) {
|
|
||||||
String src = frame.shortsource();
|
|
||||||
file = src != null ? src : "?";
|
|
||||||
line = frame.currentline();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (frame == null) {
|
|
||||||
file = p.source != null? p.source.tojstring(): "?";
|
|
||||||
line = p.lineinfo != null && pc >= 0 && pc < p.lineinfo.length ? p.lineinfo[pc] : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
le.fileline = file + ":" + line;
|
|
||||||
LuaValue error = errorHook(le.getMessageObject(), le.getMessage(), le.level);
|
|
||||||
le.setMessageObject(error);
|
|
||||||
le.traceback = error != null ? error.tojstring() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private UpValue findupval(LuaValue[] stack, short idx, UpValue[] openups) {
|
|
||||||
final int n = openups.length;
|
|
||||||
for (int i = 0; i < n; ++i)
|
|
||||||
if (openups[i] != null && openups[i].index == idx)
|
|
||||||
return openups[i];
|
|
||||||
for (int i = 0; i < n; ++i)
|
|
||||||
if (openups[i] == null)
|
|
||||||
return openups[i] = new UpValue(stack, idx);
|
|
||||||
error("No space for upvalue");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected LuaValue getUpvalue(int i) {
|
|
||||||
return upValues[i].getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setUpvalue(int i, LuaValue v) {
|
|
||||||
upValues[i].setValue(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String name() {
|
|
||||||
return "<"+p.shortsource()+":"+p.linedefined+">";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,309 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2007-2012 LuaJ. All rights reserved.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
******************************************************************************/
|
|
||||||
package org.luaj.vm2;
|
|
||||||
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.locks.Condition;
|
|
||||||
import java.util.concurrent.locks.Lock;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Subclass of {@link LuaValue} that implements
|
|
||||||
* a lua coroutine thread using Java Threads.
|
|
||||||
* <p>
|
|
||||||
* A LuaThread is typically created in response to a scripted call to
|
|
||||||
* {@code coroutine.create()}
|
|
||||||
* <p>
|
|
||||||
* The threads must be initialized with the globals, so that
|
|
||||||
* the global environment may be passed along according to rules of lua.
|
|
||||||
* This is done via the constructor arguments {@link #LuaThread(Globals)} or
|
|
||||||
* {@link #LuaThread(Globals, LuaValue)}.
|
|
||||||
* <p>
|
|
||||||
* The utility classes {@link org.luaj.vm2.libs.jse.JsePlatform} and
|
|
||||||
* {@link org.luaj.vm2.libs.jme.JmePlatform}
|
|
||||||
* see to it that this {@link Globals} are initialized properly.
|
|
||||||
* <p>
|
|
||||||
* The behavior of coroutine threads matches closely the behavior
|
|
||||||
* of C coroutine library. However, because of the use of Java threads
|
|
||||||
* to manage call state, it is possible to yield from anywhere in luaj.
|
|
||||||
* <p>
|
|
||||||
* Each Java thread wakes up at regular intervals and checks a weak reference
|
|
||||||
* to determine if it can ever be resumed. If not, it throws
|
|
||||||
* {@link OrphanedThread} which is an {@link java.lang.Error}.
|
|
||||||
* Applications should not catch {@link OrphanedThread}, because it can break
|
|
||||||
* the thread safety of luaj. The value controlling the polling interval
|
|
||||||
* is {@link #thread_orphan_check_interval} and may be set by the user.
|
|
||||||
* <p>
|
|
||||||
* There are two main ways to abandon a coroutine. The first is to call
|
|
||||||
* {@code yield()} from lua, or equivalently {@link Globals#yield(Varargs)},
|
|
||||||
* and arrange to have it never resumed possibly by values passed to yield.
|
|
||||||
* The second is to throw {@link OrphanedThread}, which should put the thread
|
|
||||||
* in a dead state. In either case all references to the thread must be
|
|
||||||
* dropped, and the garbage collector must run for the thread to be
|
|
||||||
* garbage collected.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @see LuaValue
|
|
||||||
* @see org.luaj.vm2.libs.jse.JsePlatform
|
|
||||||
* @see org.luaj.vm2.libs.jme.JmePlatform
|
|
||||||
* @see org.luaj.vm2.libs.CoroutineLib
|
|
||||||
*/
|
|
||||||
public class LuaThread extends LuaValue {
|
|
||||||
|
|
||||||
/** Shared metatable for lua threads. */
|
|
||||||
public static LuaValue s_metatable;
|
|
||||||
|
|
||||||
/** The current number of coroutines. Should not be set. */
|
|
||||||
public static int coroutine_count = 0;
|
|
||||||
|
|
||||||
/** Polling interval, in milliseconds, which each thread uses while waiting to
|
|
||||||
* return from a yielded state to check if the lua threads is no longer
|
|
||||||
* referenced and therefore should be garbage collected.
|
|
||||||
* A short polling interval for many threads will consume server resources.
|
|
||||||
* Orphaned threads cannot be detected and collected unless garbage
|
|
||||||
* collection is run. This can be changed by Java startup code if desired.
|
|
||||||
*/
|
|
||||||
public static long thread_orphan_check_interval = 5000;
|
|
||||||
|
|
||||||
public static final String USE_PLATFORM_THREAD = "USE_PLATFORM_THREAD";
|
|
||||||
|
|
||||||
private static boolean SUPPORT_VIRTUAL_THREAD = false;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
Thread.class.getMethod("ofVirtual");
|
|
||||||
SUPPORT_VIRTUAL_THREAD = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
//e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final int STATUS_INITIAL = 0;
|
|
||||||
public static final int STATUS_SUSPENDED = 1;
|
|
||||||
public static final int STATUS_RUNNING = 2;
|
|
||||||
public static final int STATUS_NORMAL = 3;
|
|
||||||
public static final int STATUS_DEAD = 4;
|
|
||||||
public static final String[] STATUS_NAMES = {
|
|
||||||
"suspended",
|
|
||||||
"suspended",
|
|
||||||
"running",
|
|
||||||
"normal",
|
|
||||||
"dead",};
|
|
||||||
|
|
||||||
public final State state;
|
|
||||||
|
|
||||||
public static final int MAX_CALLSTACK = 256;
|
|
||||||
|
|
||||||
/** Thread-local used by DebugLib to store debugging state.
|
|
||||||
* This is an opaque value that should not be modified by applications. */
|
|
||||||
public Object callstack;
|
|
||||||
|
|
||||||
public final Globals globals;
|
|
||||||
|
|
||||||
/** Error message handler for this thread, if any. */
|
|
||||||
public LuaValue errorfunc;
|
|
||||||
|
|
||||||
/** Private constructor for main thread only */
|
|
||||||
public LuaThread(Globals globals) {
|
|
||||||
state = new State(globals, this, null);
|
|
||||||
state.status = STATUS_RUNNING;
|
|
||||||
this.globals = globals;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a LuaThread around a function and environment
|
|
||||||
* @param func The function to execute
|
|
||||||
*/
|
|
||||||
public LuaThread(Globals globals, LuaValue func) {
|
|
||||||
LuaValue.assert_(func != null, "function cannot be null");
|
|
||||||
state = new State(globals, this, func);
|
|
||||||
this.globals = globals;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int type() {
|
|
||||||
return LuaValue.TTHREAD;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String typename() {
|
|
||||||
return "thread";
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isthread() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LuaThread optthread(LuaThread defval) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LuaThread checkthread() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LuaValue getmetatable() {
|
|
||||||
return s_metatable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStatus() {
|
|
||||||
return STATUS_NAMES[state.status];
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMainThread() {
|
|
||||||
return this.state.function == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Varargs resume(Varargs args) {
|
|
||||||
final LuaThread.State s = this.state;
|
|
||||||
if (s.status > LuaThread.STATUS_SUSPENDED)
|
|
||||||
return LuaValue.varargsOf(LuaValue.FALSE,
|
|
||||||
LuaValue.valueOf("cannot resume "+(s.status==LuaThread.STATUS_DEAD? "dead": "non-suspended")+" coroutine"));
|
|
||||||
return s.lua_resume(this, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class State implements Runnable {
|
|
||||||
private final Globals globals;
|
|
||||||
final WeakReference lua_thread;
|
|
||||||
public final LuaValue function;
|
|
||||||
Varargs args = LuaValue.NONE;
|
|
||||||
Varargs result = LuaValue.NONE;
|
|
||||||
String error = null;
|
|
||||||
|
|
||||||
/** Hook function control state used by debug lib. */
|
|
||||||
public LuaValue hookfunc;
|
|
||||||
|
|
||||||
public boolean hookline;
|
|
||||||
public boolean hookcall;
|
|
||||||
public boolean hookrtrn;
|
|
||||||
public int hookcount;
|
|
||||||
public boolean inhook;
|
|
||||||
public int lastline;
|
|
||||||
public int bytecodes;
|
|
||||||
|
|
||||||
public int status = LuaThread.STATUS_INITIAL;
|
|
||||||
private Lock locker = new ReentrantLock();
|
|
||||||
private Condition cond = locker.newCondition();
|
|
||||||
|
|
||||||
State(Globals globals, LuaThread lua_thread, LuaValue function) {
|
|
||||||
this.globals = globals;
|
|
||||||
this.lua_thread = new WeakReference(lua_thread);
|
|
||||||
this.function = function;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
locker.lock();
|
|
||||||
try {
|
|
||||||
try {
|
|
||||||
Varargs a = this.args;
|
|
||||||
this.args = LuaValue.NONE;
|
|
||||||
this.result = function.invoke(a);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
this.error = t.getMessage();
|
|
||||||
} finally {
|
|
||||||
this.status = LuaThread.STATUS_DEAD;
|
|
||||||
cond.signal();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
locker.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Varargs lua_resume(LuaThread new_thread, Varargs args) {
|
|
||||||
locker.lock();
|
|
||||||
try {
|
|
||||||
LuaThread previous_thread = globals.running;
|
|
||||||
try {
|
|
||||||
globals.running = new_thread;
|
|
||||||
this.args = args;
|
|
||||||
if (this.status == STATUS_INITIAL) {
|
|
||||||
this.status = STATUS_RUNNING;
|
|
||||||
Thread t = null;
|
|
||||||
if(SUPPORT_VIRTUAL_THREAD) {
|
|
||||||
LuaValue setting = globals.get(USE_PLATFORM_THREAD);
|
|
||||||
if(setting.isnil()) {//default
|
|
||||||
if(Thread.currentThread().isVirtual()) {
|
|
||||||
t = Thread.ofVirtual().name("Coroutine-"+(++coroutine_count)).start(this);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(!setting.toboolean()) {
|
|
||||||
t = Thread.ofVirtual().name("Coroutine-"+(++coroutine_count)).start(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (t == null){
|
|
||||||
new Thread(this, "Coroutine-"+(++coroutine_count)).start();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cond.signal();
|
|
||||||
}
|
|
||||||
if (previous_thread != null)
|
|
||||||
previous_thread.state.status = STATUS_NORMAL;
|
|
||||||
this.status = STATUS_RUNNING;
|
|
||||||
cond.await();
|
|
||||||
return (this.error != null?
|
|
||||||
LuaValue.varargsOf(LuaValue.FALSE, LuaValue.valueOf(this.error)):
|
|
||||||
LuaValue.varargsOf(LuaValue.TRUE, this.result));
|
|
||||||
} catch (InterruptedException ie) {
|
|
||||||
throw new OrphanedThread();
|
|
||||||
} finally {
|
|
||||||
this.args = LuaValue.NONE;
|
|
||||||
this.result = LuaValue.NONE;
|
|
||||||
this.error = null;
|
|
||||||
globals.running = previous_thread;
|
|
||||||
if (previous_thread != null)
|
|
||||||
globals.running.state.status =STATUS_RUNNING;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
locker.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Varargs lua_yield(Varargs args) {
|
|
||||||
locker.lock();
|
|
||||||
try {
|
|
||||||
try {
|
|
||||||
this.result = args;
|
|
||||||
this.status = STATUS_SUSPENDED;
|
|
||||||
cond.signal();
|
|
||||||
do {
|
|
||||||
cond.await(thread_orphan_check_interval,TimeUnit.MILLISECONDS);
|
|
||||||
if (this.lua_thread.get() == null) {
|
|
||||||
this.status = STATUS_DEAD;
|
|
||||||
throw new OrphanedThread();
|
|
||||||
}
|
|
||||||
} while (this.status == STATUS_SUSPENDED);
|
|
||||||
return this.args;
|
|
||||||
} catch (InterruptedException ie) {
|
|
||||||
this.status = STATUS_DEAD;
|
|
||||||
throw new OrphanedThread();
|
|
||||||
} finally {
|
|
||||||
this.args = LuaValue.NONE;
|
|
||||||
this.result = LuaValue.NONE;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
locker.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user