diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000..d56dcf1a7c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+build
+out
+run
+deploy
+*.ipr
+*.iws
+*.iml
+.gradle
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000..f5314a6d9e
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,98 @@
+ComputerCraft Public License
+============================
+
+Version 1.0.0 (Based on Minecraft Mod Public License 1.0.1)
+
+0. Definitions
+--------------
+
+Minecraft: Denotes a copy of the PC Java version of the game “Minecraft” licensed by Mojang AB
+
+User: Anybody that interacts with the software in one of the following ways:
+ - play
+ - decompile
+ - recompile or compile
+ - modify
+ - distribute
+
+Mod: The mod code designated by the present license, in source form, binary
+form, as obtained standalone, as part of a wider distribution or resulting from
+the compilation of the original or modified sources.
+
+Dependency: Code required for the mod to work properly. This includes
+dependencies required to compile the code as well as any file or modification
+that is explicitly or implicitly required for the mod to be working.
+
+1. Scope
+--------
+
+The present license is granted to any user of the mod. As a prerequisite,
+a user must own a legally acquired copy of Minecraft
+
+2. Liability
+------------
+
+This mod is provided 'as is' with no warranties, implied or otherwise. The owner
+of this mod takes no responsibility for any damages incurred from the use of
+this mod. This mod alters fundamental parts of the Minecraft game, parts of
+Minecraft may not work with this mod installed. All damages caused from the use
+or misuse of this mad fall on the user.
+
+3. Play rights
+--------------
+
+The user is allowed to install this mod on a Minecraft client or server and to play
+without restriction.
+
+4. Modification rights
+----------------------
+
+The user has the right to decompile the source code, look at either the
+decompiled version or the original source code, and to modify it.
+
+5. Distribution of original or modified copy rights
+---------------------------------------------------
+
+Is subject to distribution rights this entire mod in its various forms. This
+include:
+ - original binary or source forms of this mod files
+ - modified versions of these binaries or source files, as well as binaries
+ resulting from source modifications
+ - patch to its source or binary files
+ - any copy of a portion of its binary source files
+
+The user is allowed to redistribute this mod partially, in totality, or
+included in a distribution.
+
+When distributing binary files, the user must provide means to obtain its
+entire set of sources or modified sources at no cost.
+
+All distributions of this mod must remain licensed under the CCPL.
+
+All dependencies that this mod have on other mods or classes must be licensed
+under conditions comparable to this version of CCPL, with the exception of the
+Minecraft code and the mod loading framework (e.g. Forge).
+
+Modified version of binaries and sources, as well as files containing sections
+copied from this mod, should be distributed under the terms of the present
+license.
+
+7. Use of mod code and assets in other projects
+-----------------------------------------------
+
+It is permitted to use the code and assets contained in this mod (and modified
+versions thereof) in other Minecraft Mods, provided they are non-commercial.
+However: the code and assets may not be used in commercial mods, mods for other
+games, other games, other non-game projects, or any commercial projects.
+
+When using code covered by this license in other projects, the source code used
+must be made available at no cost and remain licensed under the CCPL.
+
+8. Contributing
+---------------
+
+If you choose to contribute code or assets to be included in this mod, you
+agree that, if added to to the main repository at
+https://github.com/dan200/ComputerCraft, your contributions will be covered by
+this license, and that Daniel Ratcliffe will retain the right to re-license the
+mod, including your contributions, in part or in whole, under other licenses.
diff --git a/LICENSE-luaj b/LICENSE-luaj
new file mode 100644
index 0000000000..2cc1808644
--- /dev/null
+++ b/LICENSE-luaj
@@ -0,0 +1,19 @@
+Copyright (c) 2007 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.
\ No newline at end of file
diff --git a/README.md b/README.md
index 7e0787c380..af193bcc14 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,25 @@
ComputerCraft
=============
-Issue tracker for ComputerCraft and ComputerCraftEdu
-* http://www.computercraft.info
-* http://www.computercraftedu.com
+ComputerCraft is a Minecraft modification which adds programmable Robots and Computers to the world of Minecraft.
+If you're not familiar with ComputerCraft, visit the [Website](http://www.computercraft.info/download) or the [Wiki](http://www.computercraft.info/wiki) to find out more.
+
+About this Repository
+=====================
+
+ComputerCraft was originally released in late 2011 by [Daniel Ratcliffe](https://twitter.com/DanTwoHundred). In early 2017, after working on the mod solo for five years, it was decided to release the source code publicly to allow Dan to devote time to other projects. This repository marks the first public release of this source code.
+
+The code in this repository will always represent the "bleeding edge" of the ComputerCraft codebase, but stable builds back to 1.79 will be marked on the [Releases](https://github.com/dan200/ComputerCraft/releases) page.
+
+Contributing
+============
+
+While ComputerCraft will no longer be actively developed by Daniel Ratcliffe, you may still contribute pull requests which will be reviewed and incorporated into releases periodically. A pull requests is more likely to be accepted if it meets the following criteria:
+
+* It does not add any new dependencies for compiling, running or using the mod.
+* It does not break compatibility with world saves or programs created with previous versions of the mod.
+* It does not add unneccessary complexity for users of the mod, and maintains the accessibility for which the mod is known.
+* It does not add unneccessary complexity or stylistic changes to the code, especially where functionality is not being changed.
+* It does not create bugs!
+
+The pull requests most likely to be accepted are those which fix bugs, simplify code, or make the mod compatible with newer versions of Minecraft.
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000000..54599037f2
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,85 @@
+
+// For those who want the bleeding edge
+buildscript {
+ repositories {
+ jcenter()
+ maven {
+ name = "forge"
+ url = "http://files.minecraftforge.net/maven"
+ }
+ }
+ dependencies {
+ classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT'
+ }
+}
+apply plugin: 'net.minecraftforge.gradle.forge'
+
+/*
+// for people who want stable - not yet functional for MC 1.8.8 - we require the forgegradle 2.1 snapshot
+plugins {
+ id "net.minecraftforge.gradle.forge" version "2.0.2"
+}
+*/
+
+version = "1.79"
+group = "dan200.computercraft"
+archivesBaseName = "ComputerCraft"
+
+minecraft {
+ version = "1.8.9-11.15.0.1715"
+ runDir = "run"
+ replace '${version}', project.version
+
+ // the mappings can be changed at any time, and must be in the following format.
+ // snapshot_YYYYMMDD snapshot are built nightly.
+ // stable_# stables are built at the discretion of the MCP team.
+ // Use non-default mappings at your own risk. they may not allways work.
+ // simply re-run your setup task after changing the mappings to update your workspace.
+ mappings = "snapshot_20151224"
+ // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
+}
+
+dependencies {
+ // you may put jars on which you depend on in ./libs
+ // or you may define them like so..
+ //compile "some.group:artifact:version:classifier"
+ //compile "some.group:artifact:version"
+
+ // real examples
+ //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
+ //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
+
+ // the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
+ //provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
+
+ // the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided,
+ // except that these dependencies get remapped to your current MCP mappings
+ //deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev'
+ //deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
+
+ // for more info...
+ // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
+ // http://www.gradle.org/docs/current/userguide/dependency_management.html
+
+}
+
+processResources
+{
+ // this will ensure that this task is redone when the versions change.
+ inputs.property "version", project.version
+ inputs.property "mcversion", project.minecraft.version
+
+ // replace stuff in mcmod.info, nothing else
+ from(sourceSets.main.resources.srcDirs) {
+ include 'mcmod.info'
+
+ // replace version and mcversion
+ expand 'version':project.version, 'mcversion':project.minecraft.version
+ }
+
+ // copy everything else, thats not the mcmod.info
+ from(sourceSets.main.resources.srcDirs) {
+ exclude 'mcmod.info'
+ }
+}
+
diff --git a/build_luaj.sh b/build_luaj.sh
new file mode 100755
index 0000000000..b3aaf0871d
--- /dev/null
+++ b/build_luaj.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+cd luaj-2.0.3
+echo "Building LuaJ..."
+ant clean
+ant
+
+echo "Copying output to libs..."
+rm ../libs/luaj-jse-2.0.3.jar
+cp luaj-jse-2.0.3.jar ../libs
+
+echo "Done."
+cd ..
diff --git a/deploy.sh b/deploy.sh
new file mode 100755
index 0000000000..0ce941a6ff
--- /dev/null
+++ b/deploy.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+echo "Building with gradle..."
+rm -rf build/libs
+rm -rf build/resources
+rm -rf build/classes
+chmod -R +rw src/main/resources
+chmod +x gradlew
+./gradlew build
+
+echo "Deleting old deployment..."
+rm -rf deploy
+mkdir deploy
+
+echo "Making new deployment..."
+INPUTJAR=`ls -1 build/libs | grep -v sources`
+OUTPUTJAR=`ls -1 build/libs | grep -v sources | sed s/\-//g`
+FRIENDLYNAME=`ls -1 build/libs | grep -v sources | sed s/\-/\ /g | sed s/\.jar//g`
+cp build/libs/$INPUTJAR deploy/$OUTPUTJAR
+
+echo "Creating API..."
+mkdir -p deploy/api/src/dan200/computercraft
+cp -r build/sources/main/java/dan200/computercraft/api deploy/api/src/dan200/computercraft/api
+
+echo "Creating API Javadocs..."
+mkdir -p deploy/api/doc
+cd src/main/java/dan200/computercraft/api
+find . -type f -name "*.java" | xargs javadoc -d ../../../../../../deploy/api/doc -windowtitle "$FRIENDLYNAME"
+cd ../../../../../..
+
+echo "Adding API and Javadocs to deployment..."
+cd deploy
+zip -r $OUTPUTJAR api/doc > /dev/null
+zip -r $OUTPUTJAR api/src/dan200/computercraft > /dev/null
+cd ..
+rm -rf deploy/api
+
+echo "Adding LuaJ to deployment..."
+mkdir deploy/luaj
+cd deploy/luaj
+jar xf ../../libs/luaj-jse-2.0.3.jar
+zip -r ../$OUTPUTJAR org > /dev/null
+cd ../..
+rm -rf deploy/luaj
+
+echo "Done."
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000000..30d399d8d2
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000000..9397848f19
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Mon Sep 14 12:28:28 PDT 2015
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000000..ab2a1bde5a
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS="-Xmx2048m"
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/libs/luaj-jse-2.0.3.jar b/libs/luaj-jse-2.0.3.jar
new file mode 100644
index 0000000000..b05ee77450
Binary files /dev/null and b/libs/luaj-jse-2.0.3.jar differ
diff --git a/luaj-2.0.3/.classpath b/luaj-2.0.3/.classpath
new file mode 100644
index 0000000000..eded28b8ce
--- /dev/null
+++ b/luaj-2.0.3/.classpath
@@ -0,0 +1,19 @@
+
+
+ +Copyright © 2009-2012 Luaj.org. +Freely available under the terms of the +Luaj license. + +
+ +introduction +· +examples +· +concepts +· +libraries +· +luaj api +· +parser +· +building +· +downloads +· +release notes + + +
+ +
|
+From the main distribution directory line type: + +
+ java -cp lib/luaj-jse-2.0.3.jar lua examples/lua/hello.lua ++ +
+You should see the following output: +
+ hello, world ++ +To see how luaj can be used to acccess most Java API's including swing, try: + +
+ java -cp lib/luaj-jse-2.0.3.jar lua examples/lua/swingapp.lua ++ +
+From the main distribution directory line type: + +
+ java -cp lib/luaj-jse-2.0.3.jar luac examples/lua/hello.lua + java -cp lib/luaj-jse-2.0.3.jar lua luac.out ++ +
+The compiled output "luac.out" is lua bytecode and should run and produce the same result. + +
+Luaj can compile to lua source code to Java source code: + +
+ java -cp lib/luaj-jse-2.0.3.jar lua2java -s examples/lua -d . hello.lua + javac -cp lib/luaj-jse-2.0.3.jar hello.java + java -cp "lib/luaj-jse-2.0.3.jar;." lua -l hello ++ +
+The output hello.java is Java source, that implements the logic in hello.lua directly. +Once hello.java is compiled into hello.class it can be required and used in place of the original lua script, but with better performance. +There are no additional dependencies for compiling or running source-to-source compiled lua. + +
+Lua scripts can also be run directly in this mode without precompiling using the lua command with the -j option when run in JDK 1.5 or higher: +
+ java -cp lib/luaj-jse-2.0.3.jar lua -j examples/lua/hello.lua ++ +
+Luaj can compile lua sources or binaries directly to java bytecode if the bcel library is on the class path. From the main distribution directory line type: + +
+ ant bcel-lib + java -cp "lib/luaj-jse-2.0.3.jar;lib/bcel-5.2.jar" luajc -s examples/lua -d . hello.lua + java -cp "lib/luaj-jse-2.0.3.jar;." lua -l hello ++ +
+The output hello.class is Java bytecode, should run and produce the same result. +There is no runtime dependency on the bcel library, +but the compiled classes must be in the class path at runtime, unless runtime jit-compiling via luajc and bcel are desired (see later sections). + +
+Lua scripts can also be run directly in this mode without precompiling using the lua command with the -b option and providing the bcel library in the class path: +
+ java -cp "lib/luaj-jse-2.0.3.jar;lib/bcel-5.2.jar" lua -b examples/lua/hello.lua ++ + +
+The following pattern is used within Java SE + +
+ import org.luaj.vm2.*; + import org.luaj.vm2.lib.jse.*; + + String script = "examples/lua/hello.lua"; + LuaValue _G = JsePlatform.standardGlobals(); + _G.get("dofile").call( LuaValue.valueOf(script) ); ++ +
+A simple example may be found in +
+ examples/jse/SampleJseMain.java ++ +
+You must include the library lib/luaj-jse-2.0.3.jar in your class path. + +
+The for MIDlets the JmePlatform is used instead: + +
+ import org.luaj.vm2.*; + import org.luaj.vm2.lib.jme.*; + + String script = "examples/lua/hello.lua"; + LuaValue _G = JmePlatform.standardGlobals(); + _G.get("dofile").call( LuaValue.valueOf(script) ); ++ +
+The file must be a resource within within the midlet jar for dofile() to find it. +Any files included via require() must also be part of the midlet resources. + +
+A simple example may be found in +
+ examples/jme/SampleMIDlet.java ++ +
+You must include the library lib/luaj-jme-2.0.3.jar in your midlet jar. + +
+An ant script to build and run the midlet is in +
+ build-midlet.xml ++ +
+You must install the wireless toolkit and define WTK_HOME for this script to work. + +
+The standard use of JSR-223 scripting engines may be used: + +
+ ScriptEngineManager mgr = new ScriptEngineManager(); + ScriptEngine e = mgr.getEngineByExtension(".lua"); + e.put("x", 25); + e.eval("y = math.sqrt(x)"); + System.out.println( "y="+e.get("y") ); ++ +
+All standard aspects of script engines including compiled statements should be supported. + +
+You must include the library lib/luaj-jse-2.0.3.jar in your class path. + +
+A working example may be found in +
+ examples/jse/ScriptEngineSample.java ++ +To compile and run it using Java 1.6 or higher: + +
+ javac examples/jse/ScriptEngineSample.java + java -cp "lib/luaj-jse-2.0.3.jar;examples/jse" ScriptEngineSample ++ +
+To exclude the lua-to-lua-bytecode compiler, do not call +standardGlobals() or debugGlobals() +but instead initialize globals with including only those libraries +that are needed and omitting the line: +
+ org.luaj.vm2.compiler.LuaC.install(); ++ + +
+To compile from lua sources to Java sources for all lua loaded at runtime, +install the Lua2Java compiler after globals have been created using: + +
+ org.luaj.vm2.jse.lua2java.Lua2Java.install(); ++ +This uses the system Java compiler to compile from Java source to Java bytecode, +and cannot compile lua binary files containing lua bytecode at runtime. + +
+To compile from lua to Java bytecode for all lua loaded at runtime, +install the LuaJC compiler after globals have been created using: + +
+ org.luaj.vm2.jse.luajc.LuaJC.install(); ++ +
+This will compile all lua bytecode into Java bytecode, regardless of if they are loaded as +lua source or lua binary files. + +
+The requires bcel to be on the class path, and the ClassLoader of JSE or CDC. + +
+The following libraries are loaded by both JsePlatform.standardGlobals() and JmePlatform.standardGlobals(): +
base + coroutine + io + math + os + package + string + table ++ +
+The JsePlatform.standardGlobals() globals also include: +
luajava ++ +
+The JsePlatform.debugGlobals() and JsePlatform.debugGlobals() functions produce globals that include: +
debug ++ +
+The JmePlatform.standardGlobals() instantiated the io library io in +
+ src/jme/org/luaj/vm2/lib/jme/JmeIoLib.java ++ +The JsePlatform.standardGlobals() includes support for random access and is in +
+ src/jse/org/luaj/vm2/lib/jse/JseIoLib.java ++ +
+The basic os library implementation us used by JmePlatform and is in: +
+ src/core/org/luaj/lib/OsLib.java ++ +A richer version for use by JsePlatform is : +
+ src/jse/org/luaj/vm2/lib/jse/JseOsLib.java ++ +Time is a represented as number of milliseconds since the epoch, +and most time and date formatting, locales, and other features +are not implemented. + +
+Luaj uses WeakReferences and the OrphanedThread error to ensure that coroutines that are no longer referenced +are properly garbage collected. For thread safety, OrphanedThread should not be caught by Java code. +See LuaThread +and OrphanedThread +javadoc for details. + +
+ require 'org.luaj.vm2.lib.DebugLib' ++ +The lua command line utility includes the debug library by default. + + +
+The following lua script will open a swing frame on Java SE: +
+ jframe = luajava.bindClass( "javax.swing.JFrame" ) + frame = luajava.newInstance( "javax.swing.JFrame", "Texts" ); + frame:setDefaultCloseOperation(jframe.EXIT_ON_CLOSE) + frame:setSize(300,400) + frame:setVisible(true) ++ +
+See a longer sample in examples/lua/swingapp.lua for details, including a simple animation loop, rendering graphics, mouse and key handling, and image loading. +Or try running it using: +
+ java -cp lib/luaj-jse-2.0.3.jar lua examples/lua/swingapp.lua ++ +
+The Java ME platform does not include this library, and it cannot be made to work because of the lack of a reflection API in Java ME. + +
+The lua connand line tool includes luajava. + +
+ http://luaj.sourceforge.net/api/2.0 ++ +You can also build a local version from sources using +
+ ant doc ++ +
+ org.luaj.vm2.LuaValue ++ +
+ call(); // invoke the function with no arguments + call(LuaValue arg1); // call the function with 1 argument + invoke(Varargs arg); // call the function with variable arguments, variable return values + get(int index); // get a table entry using an integer key + get(LuaValue key); // get a table entry using an arbitrary key, may be a LuaInteger + rawget(int index); // raw get without metatable calls + valueOf(int i); // return LuaValue corresponding to an integer + valueOf(String s); // return LuaValue corresponding to a String + toint(); // return value as a Java int + tojstring(); // return value as a Java String + isnil(); // is the value nil + NIL; // the value nil + NONE; // a Varargs instance with no values ++ +
+ org.luaj.vm2.Varargs ++ +
+ narg(); // return number of arguments + arg1(); // return the first argument + arg(int n); // return the nth argument + isnil(int n); // true if the nth argument is nil + checktable(int n); // return table or throw error + optlong(int n,long d); // return n if a long, d if no argument, or error if not a long ++ +See the Varargs API for a complete list. + +
+ org.luaj.vm2.lib.ZeroArgFunction + org.luaj.vm2.lib.OneArgFunction + org.luaj.vm2.lib.TwoArgFunction + org.luaj.vm2.lib.ThreeArgFunction + org.luaj.vm2.lib.VarArgFunction ++ +Each of these functions has an abstract method that must be implemented, +and argument fixup is done automatically by the classes as each Java function is invoked. + +
+For example, to implement a "hello, world" function, we could supply: +
+ pubic class hello extends ZeroArgFunction { + public LuaValue call() { + env.get("print").call(valueOf("hello, world")); + } + } ++ +The value env is the environment of the function, and is normally supplied +by the instantiating object whenever default loading is used. + +
+Calling this function from lua could be done by: +
+ require( 'hello' )() ++ +while calling this function from Java would look like: +
+ new hello().call(); ++ +Note that in both the lua and Java case, extra arguments will be ignored, and the function will be called. +Also, no virtual machine instance is necessary to call the function. +To allow for arguments, or return multiple values, extend one of the other base classes. + +
+A plain undecorated grammer that can be used for validation is available in grammar/Lua51.jj +while a grammar that generates a typed parse tree is in grammar/LuaParser.jj + +
+To simplify the creation of abstract syntax trees from lua sources, the LuaParser class is generated as part of the JME build. +To use it, provide an input stream, and invoke the root generator, which will return a Chunk if the file is valid, +or throw a ParseException if there is a syntax error. + +
+For example, to parse a file and print all variable names, use code like: +
+ try { + String file = "main.lua"; + LuaParser parser = new LuaParser(new FileInputStream(file)); + Chunk chunk = parser.Chunk(); + chunk.accept( new Visitor() { + public void visit(Exp.NameExp exp) { + System.out.println("Name in use: "+exp.name.name); + } + } ); + } catch ( ParseException e ) { + System.out.println("parse failed: " + e.getMessage() + "\n" + + "Token Image: '" + e.currentToken.image + "'\n" + + "Location: " + e.currentToken.beginLine + ":" + e.currentToken.beginColumn + + "-" + e.currentToken.endLine + "," + e.currentToken.endColumn); + } ++In luaj 2.0.3 error reporting was turned on in the parser so line numbers are avaiable for most parse exceptions. +This example may be found in +
+ examples/jse/SampleParser.java ++ +
+See the org.luaj.vm2.ast package javadoc for the API relating to the syntax tree that is produced. + +
+Other targets exist for creating distribution file an measuring code coverage of unit tests. + +
+The main luaj JUnit tests are organized into a JUnit 3 suite: +
+ test/junit/org/luaj/vm2/AllTests.lua ++ +
+Unit test scripts can be found in these locations +
+ test/lua/*.lua + test/junit/org/luaj/vm2/compiler/lua5.1-tests.zip + test/junit/org/luaj/vm2/compiler/regressions.zip + test/junit/org/luaj/vm2/vm1/luajvm1-tests.zip ++ +
+A build script for running unit tests and producing code coverage statistics is in +
+ build-coverage.xml ++ +It relies on the cobertura code coverage library. + +
+ SourceForge Luaj Project Page + SourceForge Luaj Download Area ++ +and LuaForge: +
+ LuaForge Luaj Project Page + LuaForge Luaj Project Area ++ +
|
BaseLib
+ +Buffer + +CoerceJavaToLua + +CoerceLuaToJava + +CoroutineLib + +DebugLib + +IoLib + +JmeIoLib + +JmePlatform + +JseBaseLib + +JseIoLib + +JseMathLib + +JseMathLib.JseMathLib1 + +JseMathLib.JseMathLib2 + +JseOsLib + +JsePlatform + +JseProcess + +LibFunction + +LoadState + +LoadState.LuaCompiler + +LocVars + +Lua + +LuaBoolean + +LuaC + +LuaClosure + +LuaDouble + +LuaError + +LuaFunction + +LuaInteger + +LuajavaLib + +LuaJC + +LuaNil + +LuaNumber + +LuaString + +LuaTable + +LuaThread + +LuaThread.CallStack + +LuaUserdata + +LuaValue + +MathLib + +OneArgFunction + +OrphanedThread + +OsLib + +PackageLib + +Print + +Prototype + +ResourceFinder + +StringLib + +TableLib + +TailcallVarargs + +ThreeArgFunction + +TwoArgFunction + +UpValue + +VarArgFunction + +Varargs + +WeakTable + +ZeroArgFunction + + |
+
BaseLib
+ +Buffer + +CoerceJavaToLua + +CoerceLuaToJava + +CoroutineLib + +DebugLib + +IoLib + +JmeIoLib + +JmePlatform + +JseBaseLib + +JseIoLib + +JseMathLib + +JseMathLib.JseMathLib1 + +JseMathLib.JseMathLib2 + +JseOsLib + +JsePlatform + +JseProcess + +LibFunction + +LoadState + +LoadState.LuaCompiler + +LocVars + +Lua + +LuaBoolean + +LuaC + +LuaClosure + +LuaDouble + +LuaError + +LuaFunction + +LuaInteger + +LuajavaLib + +LuaJC + +LuaNil + +LuaNumber + +LuaString + +LuaTable + +LuaThread + +LuaThread.CallStack + +LuaUserdata + +LuaValue + +MathLib + +OneArgFunction + +OrphanedThread + +OsLib + +PackageLib + +Print + +Prototype + +ResourceFinder + +StringLib + +TableLib + +TailcallVarargs + +ThreeArgFunction + +TwoArgFunction + +UpValue + +VarArgFunction + +Varargs + +WeakTable + +ZeroArgFunction + + |
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+org.luaj.* | +
---|
+ +
org.luaj.vm2.LoadState | +||
---|---|---|
+public static final int |
+LUA_TBOOLEAN |
+1 |
+
+public static final int |
+LUA_TFUNCTION |
+6 |
+
+public static final int |
+LUA_TINT |
+-2 |
+
+public static final int |
+LUA_TLIGHTUSERDATA |
+2 |
+
+public static final int |
+LUA_TNIL |
+0 |
+
+public static final int |
+LUA_TNONE |
+-1 |
+
+public static final int |
+LUA_TNUMBER |
+3 |
+
+public static final int |
+LUA_TSTRING |
+4 |
+
+public static final int |
+LUA_TTABLE |
+5 |
+
+public static final int |
+LUA_TTHREAD |
+8 |
+
+public static final int |
+LUA_TUSERDATA |
+7 |
+
+public static final int |
+LUA_TVALUE |
+9 |
+
+public static final int |
+LUAC_FORMAT |
+0 |
+
+public static final int |
+LUAC_HEADERSIZE |
+12 |
+
+public static final int |
+LUAC_VERSION |
+81 |
+
+public static final int |
+NUMBER_FORMAT_FLOATS_OR_DOUBLES |
+0 |
+
+public static final int |
+NUMBER_FORMAT_INTS_ONLY |
+1 |
+
+public static final int |
+NUMBER_FORMAT_NUM_PATCH_INT32 |
+4 |
+
+public static final java.lang.String |
+SOURCE_BINARY_STRING |
+"binary string" |
+
+ +
+ +
org.luaj.vm2.Lua | +||
---|---|---|
+public static final java.lang.String |
+_VERSION |
+"Luaj 0.0" |
+
+public static final int |
+BITRK |
+256 |
+
+public static final int |
+iABC |
+0 |
+
+public static final int |
+iABx |
+1 |
+
+public static final int |
+iAsBx |
+2 |
+
+public static final int |
+LFIELDS_PER_FLUSH |
+50 |
+
+public static final int |
+LUA_MULTRET |
+-1 |
+
+public static final int |
+MASK_A |
+16320 |
+
+public static final int |
+MASK_B |
+-8388608 |
+
+public static final int |
+MASK_Bx |
+-16384 |
+
+public static final int |
+MASK_C |
+8372224 |
+
+public static final int |
+MASK_NOT_A |
+-16321 |
+
+public static final int |
+MASK_NOT_B |
+8388607 |
+
+public static final int |
+MASK_NOT_Bx |
+16383 |
+
+public static final int |
+MASK_NOT_C |
+-8372225 |
+
+public static final int |
+MASK_NOT_OP |
+-64 |
+
+public static final int |
+MASK_OP |
+63 |
+
+public static final int |
+MAX_OP |
+63 |
+
+public static final int |
+MAXARG_A |
+255 |
+
+public static final int |
+MAXARG_B |
+511 |
+
+public static final int |
+MAXARG_Bx |
+262143 |
+
+public static final int |
+MAXARG_C |
+511 |
+
+public static final int |
+MAXARG_sBx |
+131071 |
+
+public static final int |
+MAXINDEXRK |
+255 |
+
+public static final int |
+NO_REG |
+255 |
+
+public static final int |
+NUM_OPCODES |
+38 |
+
+public static final int |
+OP_ADD |
+12 |
+
+public static final int |
+OP_AND |
+60 |
+
+public static final int |
+OP_CALL |
+28 |
+
+public static final int |
+OP_CLOSE |
+35 |
+
+public static final int |
+OP_CLOSURE |
+36 |
+
+public static final int |
+OP_CONCAT |
+21 |
+
+public static final int |
+OP_DIV |
+15 |
+
+public static final int |
+OP_EQ |
+23 |
+
+public static final int |
+OP_FORLOOP |
+31 |
+
+public static final int |
+OP_FORPREP |
+32 |
+
+public static final int |
+OP_GE |
+62 |
+
+public static final int |
+OP_GETGLOBAL |
+5 |
+
+public static final int |
+OP_GETTABLE |
+6 |
+
+public static final int |
+OP_GETUPVAL |
+4 |
+
+public static final int |
+OP_GT |
+63 |
+
+public static final int |
+OP_JMP |
+22 |
+
+public static final int |
+OP_LE |
+25 |
+
+public static final int |
+OP_LEN |
+20 |
+
+public static final int |
+OP_LOADBOOL |
+2 |
+
+public static final int |
+OP_LOADK |
+1 |
+
+public static final int |
+OP_LOADNIL |
+3 |
+
+public static final int |
+OP_LT |
+24 |
+
+public static final int |
+OP_MOD |
+16 |
+
+public static final int |
+OP_MOVE |
+0 |
+
+public static final int |
+OP_MUL |
+14 |
+
+public static final int |
+OP_NEQ |
+61 |
+
+public static final int |
+OP_NEWTABLE |
+10 |
+
+public static final int |
+OP_NOT |
+19 |
+
+public static final int |
+OP_OR |
+59 |
+
+public static final int |
+OP_POW |
+17 |
+
+public static final int |
+OP_RETURN |
+30 |
+
+public static final int |
+OP_SELF |
+11 |
+
+public static final int |
+OP_SETGLOBAL |
+7 |
+
+public static final int |
+OP_SETLIST |
+34 |
+
+public static final int |
+OP_SETTABLE |
+9 |
+
+public static final int |
+OP_SETUPVAL |
+8 |
+
+public static final int |
+OP_SUB |
+13 |
+
+public static final int |
+OP_TAILCALL |
+29 |
+
+public static final int |
+OP_TEST |
+26 |
+
+public static final int |
+OP_TESTSET |
+27 |
+
+public static final int |
+OP_TFORLOOP |
+33 |
+
+public static final int |
+OP_UNM |
+18 |
+
+public static final int |
+OP_VARARG |
+37 |
+
+public static final int |
+OpArgK |
+3 |
+
+public static final int |
+OpArgN |
+0 |
+
+public static final int |
+OpArgR |
+2 |
+
+public static final int |
+OpArgU |
+1 |
+
+public static final int |
+POS_A |
+6 |
+
+public static final int |
+POS_B |
+23 |
+
+public static final int |
+POS_Bx |
+14 |
+
+public static final int |
+POS_C |
+14 |
+
+public static final int |
+POS_OP |
+0 |
+
+public static final int |
+SIZE_A |
+8 |
+
+public static final int |
+SIZE_B |
+9 |
+
+public static final int |
+SIZE_Bx |
+18 |
+
+public static final int |
+SIZE_C |
+9 |
+
+public static final int |
+SIZE_OP |
+6 |
+
+public static final int |
+VARARG_HASARG |
+1 |
+
+public static final int |
+VARARG_ISVARARG |
+2 |
+
+public static final int |
+VARARG_NEEDSARG |
+4 |
+
+ +
+ +
org.luaj.vm2.LuaDouble | +||
---|---|---|
+public static final java.lang.String |
+JSTR_NAN |
+"nan" |
+
+public static final java.lang.String |
+JSTR_NEGINF |
+"-inf" |
+
+public static final java.lang.String |
+JSTR_POSINF |
+"inf" |
+
+ +
+ +
org.luaj.vm2.LuaThread | +||
---|---|---|
+public static final int |
+MAX_CALLSTACK |
+256 |
+
+ +
+ +
org.luaj.vm2.LuaValue | +||
---|---|---|
+public static final int |
+TBOOLEAN |
+1 |
+
+public static final int |
+TFUNCTION |
+6 |
+
+public static final int |
+TINT |
+-2 |
+
+public static final int |
+TLIGHTUSERDATA |
+2 |
+
+public static final int |
+TNIL |
+0 |
+
+public static final int |
+TNONE |
+-1 |
+
+public static final int |
+TNUMBER |
+3 |
+
+public static final int |
+TSTRING |
+4 |
+
+public static final int |
+TTABLE |
+5 |
+
+public static final int |
+TTHREAD |
+8 |
+
+public static final int |
+TUSERDATA |
+7 |
+
+public static final int |
+TVALUE |
+9 |
+
+ +
+ +
org.luaj.vm2.compiler.LuaC | +||
---|---|---|
+public static final int |
+MAXSTACK |
+250 |
+
+ +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+ +++The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.
+ +++Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:
+
+- Interfaces (italic)
- Classes
- Enums
- Exceptions
- Errors
- Annotation Types
+ ++ ++Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:
+
+Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.- Class inheritance diagram
- Direct Subclasses
- All Known Subinterfaces
- All Known Implementing Classes
- Class/interface declaration
- Class/interface description +
+
- Nested Class Summary
- Field Summary
- Constructor Summary
- Method Summary +
+
- Field Detail
- Constructor Detail
- Method Detail
+ ++ ++Each annotation type has its own separate page with the following sections:
+
+- Annotation Type declaration
- Annotation Type description
- Required Element Summary
- Optional Element Summary
- Element Detail
+ +++Each enum has its own separate page with the following sections:
+
+- Enum declaration
- Enum description
- Enum Constant Summary
- Enum Constant Detail
+Each documented package, class and interface has its own Use page. This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.+
+There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with+java.lang.Object
. The interfaces do not inherit fromjava.lang.Object
.+
+- When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
- When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
+The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.+
+The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.+
+
+
+
+
+This help file applies to API documentation generated using the standard doclet.
+
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
and
with another operand, based on lua rules for boolean evaluation.
+LuaValue
to the buffer.
+LuaString
to the buffer.
+LuaError
indicating an invalid argument was supplied to a function
+LuaError
indicating an invalid argument was supplied to a function
+LuaError
based on an arithmetic error such as add, or pow,
+ typically due to an invalid operand type
+LuaError
based on an arithmetic error such as add, or pow,
+ typically due to an invalid operand type
+LuaError
if not
+LibFunction
which implements the lua basic library functions.Buffer
for more efficient concatenation of
+ multiple strings.
+this
with 0 arguments, including metatag processing,
+ and return only the first return value.
+this
with 1 argument, including metatag processing,
+ and return only the first return value.
+this
with 2 arguments, including metatag processing,
+ and return only the first return value.
+this
with 3 arguments, including metatag processing,
+ and return only the first return value.
+CALL
metatag, if it exists.
+LuaBoolean
,
+ or throw LuaError
if not
+LuaClosure
,
+ or throw LuaError
if not
+LuaError
if not numeric
+LuaError
if not
+LuaError
if not numeric
+LuaError
if not numeric
+LuaError
if not numeric
+LuaError
if it doesn't exist
+NIL
, or throw LuaError
if it is
+LuaError
+LuaError
+LuaError
if it is not.
+LuaTable
, or throw LuaError
if it is not
+LuaThread
, or throw LuaError
if it is not
+LuaUserdata
, or throw LuaError
if it is not
+LuaUserdata
, or throw LuaError
if it is not
+LuaError
if not
+LuaError
based on a comparison error such as greater-than or less-than,
+ typically due to an invalid operand type
+LuaError
based on a comparison error such as greater-than or less-than,
+ typically due to an invalid operand type
+Buffer
+Buffer
onto this value and return the result
+ using rules of lua string concatenation including metatag processing.
+LuaValue
+LuaString
+LuaNumber
+LuaNumber
+ and return the result using rules of lua string concatenation including
+ metatag processing.
+LuaString
+ and return the result using rules of lua string concatenation including
+ metatag processing.
+LibFunction
which implements the lua standard coroutine
+ library.LuaValue
result.
+debug
library.
+debug
library.
+LibFunction
which implements the lua standard debug
+ library.LuaValue
result.
+EQ
.
+EQ
,
+ and return java boolean
+LuaError
with a particular message
+false
+INDEX
.
+INDEX
.
+INDEX
.
+LuaValue
+LuaValue
.
+LuaValue
.
+LuaValue
.
+LuaValue
.
+LuaValue
.
+LuaValue
.
+LuaError
indicating an illegal operation occurred,
+ typically involved in managing weak references
+this
is a table,
+ return NIL
if there are no more, or throw a LuaError
if not a table.
+this
with 0 arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+this
with 0 arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+this
with 0 arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+this
with 1 argument, including metatag processing,
+ and retain all return values in a Varargs
.
+this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+this
with 1 argument, including metatag processing,
+ and retain all return values in a Varargs
.
+this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+LibFunction
which implements the
+ core of the lua standard io
library.this
is a boolean
+this
is a function
that is a closure,
+ meaning interprets lua bytecode for its execution
+this
is a function
+this
is a number
and is representable by java int
+ without rounding or truncation
+this
is a LuaInteger
+this
is a number
and is representable by java long
+ without rounding or truncation
+this
is nil
+this
is a number
+this
is a string
+this
is a table
+this
is a thread
+this
is a userdata
+this
is a userdata
of type c
+IoLib
and therefore LibFunction
which implements the lua standard io
+ library for the JSE platform.JmePlatform
class is a convenience class to standardize
+ how globals tables are initialized for the JME platform.BaseLib
and LibFunction
which implements the lua basic library functions
+ and provides a directory based ResourceFinder
as the BaseLib.FINDER
.IoLib
and therefore LibFunction
which implements the lua standard io
+ library for the JSE platform.LibFunction
which implements the lua standard math
+ library.LibFunction
which implements the standard lua os
library.JsePlatform
class is a convenience class to standardize
+ how globals tables are initialized for the JSE platform.(#this)
including metatag processing as java int
+LuaError
based on the len operator,
+ typically due to an invalid operand type
+(#this)
including metatag processing as java int
+LuaFunction
common to Java functions exposed to lua.LuaTable
initialized with supplied array values.
+LuaTable
initialized with supplied array values.
+this
+ and calling it, which should iniitalize the library instance and
+ install itself into this instance.
+Prototype
instances.Prototype
LuaValue
.
+LuaValue
.
+LuaValue
.
+LuaValue
.
+LuaValue
.
+LuaValue
.
+LuaValue
.
+LuaValue
which can hold a Java boolean as its value.LuaFunction
which executes lua bytecode.LuaNumber
which can hold a Java double as its value.LuaNumber
which can hold a Java int as its value.LibFunction
which implements the features of the luajava package.LoadState.LuaCompiler
which does direct
+ lua-to-java-bytecode compiling.nil
LuaValue
for representing lua strings.LuaValue
for representing lua tables.LuaValue
that implements
+ a lua coroutine thread using Java Threads.LibFunction
which implements the lua standard math
+ library.LuaValue.NIL
if it doesn't exist
+this
with 0 arguments, including metatag processing,
+ and return only the first return value.
+this
with 0 arguments, including metatag processing,
+ and return only the first return value.
+this
with 1 argument, including metatag processing,
+ and return only the first return value.
+this
with 1 argument, including metatag processing,
+ and return only the first return value.
+this
with 2 arguments, including metatag processing,
+ and return only the first return value.
+this
with 2 arguments, including metatag processing,
+ and return only the first return value.
+(-this)
as defined by lua unary minus operator
+EQ
.
+EQ
.
+this
is a table,
+ return NIL
if there are no more, or throw a LuaError
if not a table.
+nil
+NIL
values to optimize filling stacks using System.arraycopy().
+Varargs
list of no values
+(~this)
as defined by lua not operator
+defval
if nil, or throw a LuaError if any other type.
+LuaClosure
+defval
if nil, or throw a LuaError if any other type.
+defval
if nil, or throw a LuaError if it cannot be converted to one.
+LuaFunction
+defval
if nil, or throw a LuaError if an incompatible type.
+defval
if nil, or throw a LuaError if not a number.
+LuaInteger
+defval
if nil, or throw a LuaError if not a number or is not representable by a java int.
+defval
if nil, or throw a LuaError if any other type
+defval
if nil, or throw a LuaError if not a number.
+LuaNumber
+defval
if nil, or throw a LuaError if not a number or string that can be converted to a number.
+LuaString
+defval
if nil, or throw a LuaError if any other type
+LuaTable
+defval
if nil, or throw a LuaError if any other type.
+LuaThread
+defval
if nil, or throw a LuaError if any other type.
+defval
if nil, or throw a LuaError if any other type.
+defval
if nil, or throw a LuaError if any other type.
+defval
.
+or
with another operand, based on lua rules for boolean evaluation.
+Error
sublcass that indicates a lua thread that is no
+ longer referenced has been detected.LibFunction
which implements the standard lua os
library.LibFunction
which implements the lua standard package and module
+ library functions.LuaString
onto the front of this buffer
+LuaClosure
that is being executed
+LuaUserdata
value
+ without metatag processing.
+LuaString
value
+ without metatag processing.
+true
+NEWINDEX
.
+NEWINDEX
.
+NEWINDEX
.
+NEWINDEX
.
+NEWINDEX
.
+NEWINDEX
.
+NEWINDEX
.
+LuaValue
+LuaValue
+LuaString
+ using string comparison based on byte values.
+LibFunction
which implements the lua standard string
+ library.NIL
if it was weak and is no longer referenced.
+NIL
if it was weak and is no longer referenced.
+LuaString
or LuaNumber
,
+ or throw a LuaError
if it is not
+Varargs
instance containing arguments starting at index start
+LibFunction
which implements the lua standard table
+ library.LuaTable
.
+LuaTable
initialized with supplied array values.
+LuaTable
preallocated to hold array and hashed elements
+LuaTable
initialized with supplied named values.
+LuaTable
initialized with supplied named values and sequential elements.
+LuaTable
initialized with supplied named values and sequential elements in an array part and as varargs.
+TailcallVarargs
around a function and arguments.
+Varargs
that represents a lua tail call
+ in a Java library function execution environment.LuaValue.NIL
or FALSE
, true if anything else
+i
to java boolean based on lua rules for boolean evaluation.
+LuaString
+LuaValue.tojstring()
+true
+i
+LuaError
indicating an invalid type was supplied to a function
+LuaError
indicating an operation is not implemented
+LuaValue
+LuaString
instance whose bytes match
+ the supplied Java String using the UTF8 encoding.
+LuaString
around a byte array without copying the contents.
+LuaString
using the supplied characters as byte values.
+LuaString
around a byte array without copying the contents.
+LuaValue
.
+LuaValue
.
+LuaValue
.
+LuaValue
.
+LuaValue
.
+LuaValue
.
+Varargs
around an array of LuaValue
s.
+Varargs
around an array of LuaValue
s.
+Varargs
around an array of LuaValue
s.
+Varargs
around an array of LuaValue
s.
+Varargs
around a set of 2 or more LuaValue
s.
+Varargs
around a set of 3 or more LuaValue
s.
+LuaTable
that provides weak key and weak value semantics.
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Buffer ++
public final class Buffer
+String buffer for use in string library methods, optimized for production + of StrValue instances. +
+ The buffer can begin initially as a wrapped LuaValue
+ and only when concatenation actually occurs are the bytes first copied.
+
+ To convert back to a LuaValue
again,
+ the function value()
is used.
+
+ +
+
LuaValue
,
+LuaValue.buffer()
,
+LuaString
+Constructor Summary | +|
---|---|
Buffer()
+
++ Create buffer with default capacity |
+|
Buffer(int initialCapacity)
+
++ Create buffer with specified initial capacity |
+|
Buffer(LuaValue value)
+
++ Create buffer with specified initial value |
+
+Method Summary | +|
---|---|
+ Buffer |
+append(byte b)
+
++ Append a single byte to the buffer. |
+
+ Buffer |
+append(LuaString str)
+
++ Append a LuaString to the buffer. |
+
+ Buffer |
+append(LuaValue val)
+
++ Append a LuaValue to the buffer. |
+
+ Buffer |
+append(java.lang.String str)
+
++ Append a Java String to the buffer. |
+
+ Buffer |
+concatTo(LuaNumber lhs)
+
++ Concatenate this buffer onto a LuaNumber |
+
+ Buffer |
+concatTo(LuaString lhs)
+
++ Concatenate this buffer onto a LuaString |
+
+ Buffer |
+concatTo(LuaValue lhs)
+
++ Concatenate this buffer onto a LuaValue |
+
+ void |
+makeroom(int nbefore,
+ int nafter)
+
++ Ensure there is enough room before and after the bytes. |
+
+ Buffer |
+prepend(LuaString s)
+
++ Concatenate bytes from a LuaString onto the front of this buffer |
+
+ Buffer |
+setvalue(LuaValue value)
+
++ Set buffer contents as a LuaValue |
+
+ java.lang.String |
+tojstring()
+
++ Convert the buffer to a Java String |
+
+ LuaString |
+tostring()
+
++ Convert the buffer to a LuaString |
+
+ java.lang.String |
+toString()
+
++ Convert the buffer to a Java String |
+
+ LuaValue |
+value()
+
++ Get buffer contents as a LuaValue |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public Buffer()+
+
DEFAULT_CAPACITY
+public Buffer(int initialCapacity)+
+
initialCapacity
- the initial capacity+public Buffer(LuaValue value)+
+
value
- the initial value+Method Detail | +
---|
+public LuaValue value()+
LuaValue
++
LuaValue
, converting as necessary+public Buffer setvalue(LuaValue value)+
LuaValue
++
value
- value to set+public final LuaString tostring()+
LuaString
++
LuaString
+public java.lang.String tojstring()+
+
+public java.lang.String toString()+
+
toString
in class java.lang.Object
+public final Buffer append(byte b)+
+
this
to allow call chaining+public final Buffer append(LuaValue val)+
LuaValue
to the buffer.
++
this
to allow call chaining+public final Buffer append(LuaString str)+
LuaString
to the buffer.
++
this
to allow call chaining+public final Buffer append(java.lang.String str)+
+
this
to allow call chainingLuaString.encodeToUtf8(char[], byte[], int)
+public Buffer concatTo(LuaValue lhs)+
LuaValue
++
lhs
- the left-hand-side value onto which we are concatenating this
+Buffer
for use in call chaining.+public Buffer concatTo(LuaString lhs)+
LuaString
++
lhs
- the left-hand-side value onto which we are concatenating this
+Buffer
for use in call chaining.+public Buffer concatTo(LuaNumber lhs)+
LuaNumber
+
+ The LuaNumber
will be converted to a string before concatenating.
+
+
lhs
- the left-hand-side value onto which we are concatenating this
+Buffer
for use in call chaining.+public Buffer prepend(LuaString s)+
LuaString
onto the front of this buffer
++
s
- the left-hand-side value which we will concatenate onto the front of this
+Buffer
for use in call chaining.+public final void makeroom(int nbefore, + int nafter)+
+
nbefore
- number of unused bytes which must precede the data after this completesnafter
- number of unused bytes which must follow the data after this completes
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
public static interface LoadState.LuaCompiler
+Interface for the compiler, if it is installed. +
+ See the LuaClosure
documentation for examples of how to use the compiler.
+
+ +
+
LuaClosure
,
+load(InputStream, String, LuaValue)
+Method Summary | +|
---|---|
+ LuaFunction |
+load(java.io.InputStream stream,
+ java.lang.String filename,
+ LuaValue env)
+
++ Load into a Closure or LuaFunction from a Stream and initializes the environment |
+
+Method Detail | +
---|
+LuaFunction load(java.io.InputStream stream, + java.lang.String filename, + LuaValue env) + throws java.io.IOException+
+
java.io.IOException
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.LoadState ++
public class LoadState
+Class to manage loading of Prototype
instances.
+
+ The LoadState
class exposes one main function,
+ namely load(InputStream, String, LuaValue)
,
+ to be used to load code from a particular input stream.
+
+ A simple pattern for loading and executing code is +
LuaValue _G = JsePlatform.standardGlobals();
+ LoadState.load( new FileInputStream("main.lua"), "main.lua", _G ).call();
+
+ This should work regardless of which LoadState.LuaCompiler
+ has been installed.
+ + + Prior to loading code, a compiler should be installed. +
+ By default, when using JsePlatform
or
+ to construct globals, the LuaC
compiler is installed.
+
+ To override the default compiler with, say, the LuaJC
+ lua-to-java bytecode compiler, install it before loading,
+ for example:
+
LuaValue _G = JsePlatform.standardGlobals();
+ LuaJC.install();
+ LoadState.load( new FileInputStream("main.lua"), "main.lua", _G ).call();
+
++ +
+
LoadState.LuaCompiler
,
+LuaClosure
,
+LuaFunction
,
+compiler
,
+load(InputStream, String, LuaValue)
,
+LuaC
,
+LuaJC
+Nested Class Summary | +|
---|---|
+static interface |
+LoadState.LuaCompiler
+
++ Interface for the compiler, if it is installed. |
+
+Field Summary | +|
---|---|
+static LoadState.LuaCompiler |
+compiler
+
++ Compiler instance, if installed |
+
+ java.io.DataInputStream |
+is
+
++ input stream from which we are loading |
+
+static int |
+LUA_TBOOLEAN
+
++ |
+
+static int |
+LUA_TFUNCTION
+
++ |
+
+static int |
+LUA_TINT
+
++ |
+
+static int |
+LUA_TLIGHTUSERDATA
+
++ |
+
+static int |
+LUA_TNIL
+
++ |
+
+static int |
+LUA_TNONE
+
++ |
+
+static int |
+LUA_TNUMBER
+
++ |
+
+static int |
+LUA_TSTRING
+
++ |
+
+static int |
+LUA_TTABLE
+
++ |
+
+static int |
+LUA_TTHREAD
+
++ |
+
+static int |
+LUA_TUSERDATA
+
++ |
+
+static int |
+LUA_TVALUE
+
++ |
+
+static int |
+LUAC_FORMAT
+
++ for header of binary files -- this is the official format |
+
+static int |
+LUAC_HEADERSIZE
+
++ size of header of binary files |
+
+static int |
+LUAC_VERSION
+
++ for header of binary files -- this is Lua 5.1 |
+
+static int |
+NUMBER_FORMAT_FLOATS_OR_DOUBLES
+
++ format corresponding to non-number-patched lua, all numbers are floats or doubles |
+
+static int |
+NUMBER_FORMAT_INTS_ONLY
+
++ format corresponding to non-number-patched lua, all numbers are ints |
+
+static int |
+NUMBER_FORMAT_NUM_PATCH_INT32
+
++ format corresponding to number-patched lua, all numbers are 32-bit (4 byte) ints |
+
+static java.lang.String |
+SOURCE_BINARY_STRING
+
++ Name for compiled chunks |
+
+Method Summary | +|
---|---|
+static java.lang.String |
+getSourceName(java.lang.String name)
+
++ Construct a source name from a supplied chunk name |
+
+static LuaFunction |
+load(java.io.InputStream stream,
+ java.lang.String name,
+ LuaValue env)
+
++ Load lua in either binary or text form from an input stream. |
+
+static Prototype |
+loadBinaryChunk(int firstByte,
+ java.io.InputStream stream,
+ java.lang.String name)
+
++ Load lua thought to be a binary chunk from its first byte from an input stream. |
+
+ Prototype |
+loadFunction(LuaString p)
+
++ Load a function prototype from the input stream |
+
+ void |
+loadHeader()
+
++ Load the lua chunk header values. |
+
+static LuaValue |
+longBitsToLuaNumber(long bits)
+
++ Convert bits in a long value to a LuaValue . |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Field Detail | +
---|
+public static final int NUMBER_FORMAT_FLOATS_OR_DOUBLES+
+
+public static final int NUMBER_FORMAT_INTS_ONLY+
+
+public static final int NUMBER_FORMAT_NUM_PATCH_INT32+
+
+public static final int LUA_TINT+
+public static final int LUA_TNONE+
+public static final int LUA_TNIL+
+public static final int LUA_TBOOLEAN+
+public static final int LUA_TLIGHTUSERDATA+
+public static final int LUA_TNUMBER+
+public static final int LUA_TSTRING+
+public static final int LUA_TTABLE+
+public static final int LUA_TFUNCTION+
+public static final int LUA_TUSERDATA+
+public static final int LUA_TTHREAD+
+public static final int LUA_TVALUE+
+public static LoadState.LuaCompiler compiler+
+
+public static final java.lang.String SOURCE_BINARY_STRING+
+
+public static final int LUAC_VERSION+
+
+public static final int LUAC_FORMAT+
+
+public static final int LUAC_HEADERSIZE+
+
+public final java.io.DataInputStream is+
+
+Method Detail | +
---|
+public static LuaValue longBitsToLuaNumber(long bits)+
LuaValue
.
++
bits
- long value containing the bits
+LuaInteger
or LuaDouble
whose value corresponds to the bits provided.+public Prototype loadFunction(LuaString p) + throws java.io.IOException+
+
p
- name of the source
+Prototype
instance that was loaded
+java.io.IOException
+public void loadHeader() + throws java.io.IOException+
+
java.io.IOException
- if an i/o exception occurs.+public static LuaFunction load(java.io.InputStream stream, + java.lang.String name, + LuaValue env) + throws java.io.IOException+
+
firstByte
- the first byte of the input streamstream
- InputStream to read, after having read the first byte alreadyname
- Name to apply to the loaded chunk
+Prototype
that was loaded
+java.lang.IllegalArgumentException
- if the signature is bac
+java.io.IOException
- if an IOException occurs+public static Prototype loadBinaryChunk(int firstByte, + java.io.InputStream stream, + java.lang.String name) + throws java.io.IOException+
+
firstByte
- the first byte of the input streamstream
- InputStream to read, after having read the first byte alreadyname
- Name to apply to the loaded chunk
+Prototype
that was loaded
+java.lang.IllegalArgumentException
- if the signature is bac
+java.io.IOException
- if an IOException occurs+public static java.lang.String getSourceName(java.lang.String name)+
+
name
- String name that appears in the chunk
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.LocVars ++
public class LocVars
+Data class to hold debug information relatign to local variables for a Prototype
+
+ +
+
+Field Summary | +|
---|---|
+ int |
+endpc
+
++ The instruction offset when the variable goes out of scope |
+
+ int |
+startpc
+
++ The instruction offset when the variable comes into scope |
+
+ LuaString |
+varname
+
++ The local variable name |
+
+Constructor Summary | +|
---|---|
LocVars(LuaString varname,
+ int startpc,
+ int endpc)
+
++ Construct a LocVars instance. |
+
+Method Summary | +|
---|---|
+ java.lang.String |
+tojstring()
+
++ |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Field Detail | +
---|
+public LuaString varname+
+
+public int startpc+
+
+public int endpc+
+
+Constructor Detail | +
---|
+public LocVars(LuaString varname, + int startpc, + int endpc)+
+
varname
- The local variable namestartpc
- The instruction offset when the variable comes into scopeendpc
- The instruction offset when the variable goes out of scope+Method Detail | +
---|
+public java.lang.String tojstring()+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Lua ++
public class Lua
+Constants for lua limits and opcodes. +
+ This is a direct translation of C lua distribution header file constants + for bytecode creation and processing. +
+ +
+
+Field Summary | +|
---|---|
+static java.lang.String |
+_VERSION
+
++ version is supplied by ant build task |
+
+static int |
+BITRK
+
++ this bit 1 means constant (0 means register) |
+
+static int |
+iABC
+
++ |
+
+static int |
+iABx
+
++ |
+
+static int |
+iAsBx
+
++ |
+
+static int |
+LFIELDS_PER_FLUSH
+
++ |
+
+static int |
+LUA_MULTRET
+
++ use return values from previous op |
+
+static int[] |
+luaP_opmodes
+
++ |
+
+static int |
+MASK_A
+
++ |
+
+static int |
+MASK_B
+
++ |
+
+static int |
+MASK_Bx
+
++ |
+
+static int |
+MASK_C
+
++ |
+
+static int |
+MASK_NOT_A
+
++ |
+
+static int |
+MASK_NOT_B
+
++ |
+
+static int |
+MASK_NOT_Bx
+
++ |
+
+static int |
+MASK_NOT_C
+
++ |
+
+static int |
+MASK_NOT_OP
+
++ |
+
+static int |
+MASK_OP
+
++ |
+
+static int |
+MAX_OP
+
++ |
+
+static int |
+MAXARG_A
+
++ |
+
+static int |
+MAXARG_B
+
++ |
+
+static int |
+MAXARG_Bx
+
++ |
+
+static int |
+MAXARG_C
+
++ |
+
+static int |
+MAXARG_sBx
+
++ |
+
+static int |
+MAXINDEXRK
+
++ |
+
+static int |
+NO_REG
+
++ invalid register that fits in 8 bits |
+
+static int |
+NUM_OPCODES
+
++ |
+
+static int |
+OP_ADD
+
++ |
+
+static int |
+OP_AND
+
++ |
+
+static int |
+OP_CALL
+
++ |
+
+static int |
+OP_CLOSE
+
++ |
+
+static int |
+OP_CLOSURE
+
++ |
+
+static int |
+OP_CONCAT
+
++ |
+
+static int |
+OP_DIV
+
++ |
+
+static int |
+OP_EQ
+
++ |
+
+static int |
+OP_FORLOOP
+
++ |
+
+static int |
+OP_FORPREP
+
++ |
+
+static int |
+OP_GE
+
++ |
+
+static int |
+OP_GETGLOBAL
+
++ |
+
+static int |
+OP_GETTABLE
+
++ |
+
+static int |
+OP_GETUPVAL
+
++ |
+
+static int |
+OP_GT
+
++ |
+
+static int |
+OP_JMP
+
++ |
+
+static int |
+OP_LE
+
++ |
+
+static int |
+OP_LEN
+
++ |
+
+static int |
+OP_LOADBOOL
+
++ |
+
+static int |
+OP_LOADK
+
++ |
+
+static int |
+OP_LOADNIL
+
++ |
+
+static int |
+OP_LT
+
++ |
+
+static int |
+OP_MOD
+
++ |
+
+static int |
+OP_MOVE
+
++ |
+
+static int |
+OP_MUL
+
++ |
+
+static int |
+OP_NEQ
+
++ |
+
+static int |
+OP_NEWTABLE
+
++ |
+
+static int |
+OP_NOT
+
++ |
+
+static int |
+OP_OR
+
++ |
+
+static int |
+OP_POW
+
++ |
+
+static int |
+OP_RETURN
+
++ |
+
+static int |
+OP_SELF
+
++ |
+
+static int |
+OP_SETGLOBAL
+
++ |
+
+static int |
+OP_SETLIST
+
++ |
+
+static int |
+OP_SETTABLE
+
++ |
+
+static int |
+OP_SETUPVAL
+
++ |
+
+static int |
+OP_SUB
+
++ |
+
+static int |
+OP_TAILCALL
+
++ |
+
+static int |
+OP_TEST
+
++ |
+
+static int |
+OP_TESTSET
+
++ |
+
+static int |
+OP_TFORLOOP
+
++ |
+
+static int |
+OP_UNM
+
++ |
+
+static int |
+OP_VARARG
+
++ |
+
+static int |
+OpArgK
+
++ |
+
+static int |
+OpArgN
+
++ |
+
+static int |
+OpArgR
+
++ |
+
+static int |
+OpArgU
+
++ |
+
+static int |
+POS_A
+
++ |
+
+static int |
+POS_B
+
++ |
+
+static int |
+POS_Bx
+
++ |
+
+static int |
+POS_C
+
++ |
+
+static int |
+POS_OP
+
++ |
+
+static int |
+SIZE_A
+
++ |
+
+static int |
+SIZE_B
+
++ |
+
+static int |
+SIZE_Bx
+
++ |
+
+static int |
+SIZE_C
+
++ |
+
+static int |
+SIZE_OP
+
++ |
+
+static int |
+VARARG_HASARG
+
++ masks for new-style vararg |
+
+static int |
+VARARG_ISVARARG
+
++ |
+
+static int |
+VARARG_NEEDSARG
+
++ |
+
+Constructor Summary | +|
---|---|
Lua()
+
++ |
+
+Method Summary | +|
---|---|
+static int |
+GET_OPCODE(int i)
+
++ |
+
+static int |
+GETARG_A(int i)
+
++ |
+
+static int |
+GETARG_B(int i)
+
++ |
+
+static int |
+GETARG_Bx(int i)
+
++ |
+
+static int |
+GETARG_C(int i)
+
++ |
+
+static int |
+GETARG_sBx(int i)
+
++ |
+
+static int |
+getBMode(int m)
+
++ |
+
+static int |
+getCMode(int m)
+
++ |
+
+static int |
+getOpMode(int m)
+
++ |
+
+static int |
+INDEXK(int r)
+
++ gets the index of the constant |
+
+static boolean |
+ISK(int x)
+
++ test whether value is a constant |
+
+static int |
+RKASK(int x)
+
++ code a constant index as a RK value |
+
+static boolean |
+testAMode(int m)
+
++ |
+
+static boolean |
+testTMode(int m)
+
++ |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Field Detail | +
---|
+public static final java.lang.String _VERSION+
+
+public static final int LUA_MULTRET+
+
+public static final int VARARG_HASARG+
+
+public static final int VARARG_ISVARARG+
+public static final int VARARG_NEEDSARG+
+public static final int iABC+
+public static final int iABx+
+public static final int iAsBx+
+public static final int SIZE_C+
+public static final int SIZE_B+
+public static final int SIZE_Bx+
+public static final int SIZE_A+
+public static final int SIZE_OP+
+public static final int POS_OP+
+public static final int POS_A+
+public static final int POS_C+
+public static final int POS_B+
+public static final int POS_Bx+
+public static final int MAX_OP+
+public static final int MAXARG_A+
+public static final int MAXARG_B+
+public static final int MAXARG_C+
+public static final int MAXARG_Bx+
+public static final int MAXARG_sBx+
+public static final int MASK_OP+
+public static final int MASK_A+
+public static final int MASK_B+
+public static final int MASK_C+
+public static final int MASK_Bx+
+public static final int MASK_NOT_OP+
+public static final int MASK_NOT_A+
+public static final int MASK_NOT_B+
+public static final int MASK_NOT_C+
+public static final int MASK_NOT_Bx+
+public static final int BITRK+
+
+public static final int MAXINDEXRK+
+public static final int NO_REG+
+
+public static final int OP_MOVE+
+public static final int OP_LOADK+
+public static final int OP_LOADBOOL+
+public static final int OP_LOADNIL+
+public static final int OP_GETUPVAL+
+public static final int OP_GETGLOBAL+
+public static final int OP_GETTABLE+
+public static final int OP_SETGLOBAL+
+public static final int OP_SETUPVAL+
+public static final int OP_SETTABLE+
+public static final int OP_NEWTABLE+
+public static final int OP_SELF+
+public static final int OP_ADD+
+public static final int OP_SUB+
+public static final int OP_MUL+
+public static final int OP_DIV+
+public static final int OP_MOD+
+public static final int OP_POW+
+public static final int OP_UNM+
+public static final int OP_NOT+
+public static final int OP_LEN+
+public static final int OP_CONCAT+
+public static final int OP_JMP+
+public static final int OP_EQ+
+public static final int OP_LT+
+public static final int OP_LE+
+public static final int OP_TEST+
+public static final int OP_TESTSET+
+public static final int OP_CALL+
+public static final int OP_TAILCALL+
+public static final int OP_RETURN+
+public static final int OP_FORLOOP+
+public static final int OP_FORPREP+
+public static final int OP_TFORLOOP+
+public static final int OP_SETLIST+
+public static final int OP_CLOSE+
+public static final int OP_CLOSURE+
+public static final int OP_VARARG+
+public static final int NUM_OPCODES+
+public static final int OP_GT+
+public static final int OP_GE+
+public static final int OP_NEQ+
+public static final int OP_AND+
+public static final int OP_OR+
+public static final int OpArgN+
+public static final int OpArgU+
+public static final int OpArgR+
+public static final int OpArgK+
+public static final int[] luaP_opmodes+
+public static final int LFIELDS_PER_FLUSH+
+Constructor Detail | +
---|
+public Lua()+
+Method Detail | +
---|
+public static int GET_OPCODE(int i)+
+public static int GETARG_A(int i)+
+public static int GETARG_B(int i)+
+public static int GETARG_C(int i)+
+public static int GETARG_Bx(int i)+
+public static int GETARG_sBx(int i)+
+public static boolean ISK(int x)+
+
+public static int INDEXK(int r)+
+
+public static int RKASK(int x)+
+
+public static int getOpMode(int m)+
+public static int getBMode(int m)+
+public static int getCMode(int m)+
+public static boolean testAMode(int m)+
+public static boolean testTMode(int m)+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaBoolean ++
public final class LuaBoolean
+Extension of LuaValue
which can hold a Java boolean as its value.
+
+ These instance are not instantiated directly by clients.
+ Instead, there are exactly twon instances of this class,
+ LuaValue.TRUE
and LuaValue.FALSE
+ representing the lua values true
and false
.
+ The function LuaValue.valueOf(boolean)
will always
+ return one of these two values.
+
+ Any LuaValue
can be converted to its equivalent
+ boolean representation using LuaValue.toboolean()
+
+
+ +
+
LuaValue
,
+LuaValue.valueOf(boolean)
,
+LuaValue.TRUE
,
+LuaValue.FALSE
+Field Summary | +|
---|---|
+static LuaValue |
+s_metatable
+
++ Shared static metatable for boolean values represented in lua. |
+
+ boolean |
+v
+
++ The value of the boolean |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Method Summary | +|
---|---|
+ boolean |
+booleanValue()
+
++ Return the boolean value for this boolean |
+
+ boolean |
+checkboolean()
+
++ Check that the value is a LuaBoolean ,
+ or throw LuaError if not |
+
+ LuaValue |
+getmetatable()
+
++ Get the metatable for this LuaValue |
+
+ boolean |
+isboolean()
+
++ Check if this is a boolean |
+
+ LuaValue |
+not()
+
++ Unary not: return inverse boolean value (~this) as defined by lua not operator |
+
+ boolean |
+optboolean(boolean defval)
+
++ Check that optional argument is a boolean and return its boolean value |
+
+ boolean |
+toboolean()
+
++ Convert to boolean false if LuaValue.NIL or FALSE , true if anything else |
+
+ java.lang.String |
+tojstring()
+
++ Convert to human readable String for any type. |
+
+ int |
+type()
+
++ Get the enumeration value for the type of this value. |
+
+ java.lang.String |
+typename()
+
++ Get the String name of the type of this value. |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static LuaValue s_metatable+
+
+public final boolean v+
+
+Method Detail | +
---|
+public int type()+
LuaValue
+
type
in class LuaValue
TNIL
,
+ TBOOLEAN
,
+ TNUMBER
,
+ TSTRING
,
+ TTABLE
,
+ TFUNCTION
,
+ TUSERDATA
,
+ TTHREAD
LuaValue.typename()
+public java.lang.String typename()+
LuaValue
+
+
typename
in class LuaValue
LuaValue.TYPE_NAMES
+ corresponding to the type of this value:
+ "nil", "boolean", "number", "string",
+ "table", "function", "userdata", "thread"LuaValue.type()
+public boolean isboolean()+
LuaValue
this
is a boolean
++
isboolean
in class LuaValue
boolean
, otherwise falseLuaValue.isboolean()
,
+LuaValue.toboolean()
,
+LuaValue.checkboolean()
,
+LuaValue.optboolean(boolean)
,
+#TOBOLEAN
+public LuaValue not()+
LuaValue
(~this)
as defined by lua not operator
++
not
in class LuaValue
TRUE
if NIL
or FALSE
, otherwise FALSE
+public boolean booleanValue()+
+
+public boolean toboolean()+
LuaValue
LuaValue.NIL
or FALSE
, true if anything else
++
toboolean
in class LuaValue
LuaValue.optboolean(boolean)
,
+LuaValue.checkboolean()
,
+LuaValue.isboolean()
,
+TBOOLEAN
+public java.lang.String tojstring()+
LuaValue
+
tojstring
in class LuaValue
LuaValue.tostring()
,
+LuaValue.optjstring(String)
,
+LuaValue.checkjstring()
,
+LuaValue.isstring()
,
+TSTRING
+public boolean optboolean(boolean defval)+
LuaValue
+
optboolean
in class LuaValue
defval
- boolean value to return if this
is nil or none
+this
cast to boolean if a ,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.checkboolean()
,
+LuaValue.isboolean()
,
+LuaValue.TBOOLEAN
+public boolean checkboolean()+
LuaValue
LuaBoolean
,
+ or throw LuaError
if not
++
checkboolean
in class LuaValue
this
if it is a LuaBoolean
LuaValue.optboolean(boolean)
,
+LuaValue.TBOOLEAN
+public LuaValue getmetatable()+
LuaValue
LuaValue
+
+ For LuaTable
and LuaUserdata
instances,
+ the metatable returned is this instance metatable.
+ For all other types, the class metatable value will be returned.
+
+
getmetatable
in class LuaValue
s_metatable
,
+LuaNumber.s_metatable
,
+LuaNil.s_metatable
,
+LuaFunction.s_metatable
,
+LuaThread.s_metatable
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.LuaClosure ++
public class LuaClosure
+Extension of LuaFunction
which executes lua bytecode.
+
+ A LuaClosure
is a combination of a Prototype
+ and a LuaValue
to use as an environment for execution.
+
+ There are three main ways LuaClosure
instances are created:
+
LuaClosure(Prototype, LuaValue)
LoadState.LuaCompiler.load(java.io.InputStream, String, LuaValue)
+ Lua.OP_CLOSURE
as part of bytecode processing
+
+ To construct it directly, the Prototype
is typically created via a compiler such as LuaC
:
+
InputStream is = new ByteArrayInputStream("print('hello,world').getBytes());
+ Prototype p = LuaC.instance.compile(is, "script");
+ LuaValue _G = JsePlatform.standardGlobals()
+ LuaClosure f = new LuaClosure(p, _G);
+
+
+ To construct it indirectly, the LuaC
compiler may be used,
+ which implements the LoadState.LuaCompiler
interface:
+
LuaFunction f = LuaC.instance.load(is, "script", _G);
+
+ + Typically, a closure that has just been loaded needs to be initialized by executing it, + and its return value can be saved if needed: +
LuaValue r = f.call();
+ _G.set( "mypkg", r )
+
+
+ In the preceding, the loaded value is typed as LuaFunction
+ to allow for the possibility of other compilers such as LuaJC
+ producing LuaFunction
directly without
+ creating a Prototype
or LuaClosure
.
+
+ Since a LuaClosure
is a LuaFunction
which is a LuaValue
,
+ all the value operations can be used directly such as:
+
LuaValue.setfenv(LuaValue)
LuaValue.call()
LuaValue.call(LuaValue)
LuaValue.invoke()
LuaValue.invoke(Varargs)
LuaValue.method(String)
LuaValue.method(String,LuaValue)
LuaValue.invokemethod(String)
LuaValue.invokemethod(String,Varargs)
+ +
+
LuaValue
,
+LuaFunction
,
+LuaValue.isclosure()
,
+LuaValue.checkclosure()
,
+LuaValue.optclosure(LuaClosure)
,
+LoadState
,
+LoadState.compiler
+Field Summary | +|
---|---|
+ Prototype |
+p
+
++ |
+
+ UpValue[] |
+upValues
+
++ |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
+protected |
+LuaClosure(int nupvalues,
+ LuaValue env)
+
++ |
+
+ |
+LuaClosure(Prototype p,
+ LuaValue env)
+
++ Supply the initial environment |
+
+Method Summary | +|
---|---|
+ LuaValue |
+call()
+
++ Call this with 0 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2)
+
++ Call this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ Call this with 3 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaClosure |
+checkclosure()
+
++ Check that the value is a LuaClosure ,
+ or throw LuaError if not |
+
+protected Varargs |
+execute(LuaValue[] stack,
+ Varargs varargs)
+
++ |
+
+ LuaValue |
+getmetatable()
+
++ Get the metatable for this LuaValue |
+
+protected LuaValue |
+getUpvalue(int i)
+
++ |
+
+ Varargs |
+invoke(Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ boolean |
+isclosure()
+
++ Check if this is a function that is a closure,
+ meaning interprets lua bytecode for its execution |
+
+ Varargs |
+onInvoke(Varargs varargs)
+
++ Callback used during tail call processing to invoke the function once. |
+
+ LuaClosure |
+optclosure(LuaClosure defval)
+
++ Check that optional argument is a closure and return as LuaClosure |
+
+protected void |
+setUpvalue(int i,
+ LuaValue v)
+
++ |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public final Prototype p+
+public final UpValue[] upValues+
+Constructor Detail | +
---|
+public LuaClosure(Prototype p, + LuaValue env)+
+
+protected LuaClosure(int nupvalues, + LuaValue env)+
+Method Detail | +
---|
+public boolean isclosure()+
LuaValue
this
is a function
that is a closure,
+ meaning interprets lua bytecode for its execution
++
isclosure
in class LuaValue
closure
, otherwise falseLuaValue.isfunction()
,
+LuaValue.checkclosure()
,
+LuaValue.optclosure(LuaClosure)
,
+LuaValue.TFUNCTION
+public LuaClosure optclosure(LuaClosure defval)+
LuaValue
LuaClosure
+
+ A LuaClosure
is a that executes lua byteccode.
+
+
optclosure
in class LuaValue
defval
- LuaClosure
to return if this
is nil or none
+this
cast to LuaClosure
if a function,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.checkclosure()
,
+LuaValue.isclosure()
,
+LuaValue.TFUNCTION
+public LuaClosure checkclosure()+
LuaValue
LuaClosure
,
+ or throw LuaError
if not
+
+ LuaClosure
is a subclass of that interprets lua bytecode.
+
+
checkclosure
in class LuaValue
this
cast as LuaClosure
LuaValue.checkfunction()
,
+LuaValue.optclosure(LuaClosure)
,
+LuaValue.isclosure()
,
+LuaValue.TFUNCTION
+public LuaValue getmetatable()+
LuaValue
LuaValue
+
+ For LuaTable
and LuaUserdata
instances,
+ the metatable returned is this instance metatable.
+ For all other types, the class metatable value will be returned.
+
+
getmetatable
in class LuaFunction
LuaBoolean.s_metatable
,
+LuaNumber.s_metatable
,
+LuaNil.s_metatable
,
+LuaFunction.s_metatable
,
+LuaThread.s_metatable
+public final LuaValue call()+
LuaValue
this
with 0 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
(this())
, or NIL
if there were none.LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.method(String)
,
+LuaValue.method(LuaValue)
+public final LuaValue call(LuaValue arg)+
LuaValue
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+LuaValue.method(String,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue)
+public final LuaValue call(LuaValue arg1, + LuaValue arg2)+
LuaValue
this
with 2 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called function
+(this(arg1,arg2))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue)
,
+LuaValue.method(String,LuaValue,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue,LuaValue)
+public final LuaValue call(LuaValue arg1, + LuaValue arg2, + LuaValue arg3)+
LuaValue
this
with 3 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called functionarg3
- Second argument to supply to the called function
+(this(arg1,arg2,arg3))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue, LuaValue)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+public final Varargs invoke(Varargs varargs)+
LuaValue
this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ If this
is a LuaFunction
, call it, and return all values.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a method call, use LuaValue.invokemethod(LuaValue)
instead.
+
+
invoke
in class LuaValue
varargs
- Varargs containing the arguments to supply to the called function
+Varargs
instance.LuaValue.varargsOf(LuaValue[])
,
+LuaValue.call(LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.invoke(LuaValue,Varargs)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+public Varargs onInvoke(Varargs varargs)+
LuaValue
+ This may return a TailcallVarargs
to be evaluated by the client.
+
+ This should not be called directly, instead use on of the call invocation functions. +
+
onInvoke
in class LuaValue
varargs
- the arguments to the call invocation.
+LuaValue.call()
,
+LuaValue.invoke()
,
+LuaValue.method(LuaValue)
,
+LuaValue.invokemethod(LuaValue)
+protected Varargs execute(LuaValue[] stack, + Varargs varargs)+
+protected LuaValue getUpvalue(int i)+
+protected void setUpvalue(int i, + LuaValue v)+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaNumber + org.luaj.vm2.LuaDouble ++
public class LuaDouble
+Extension of LuaNumber
which can hold a Java double as its value.
+
+ These instance are not instantiated directly by clients, but indirectly
+ via the static functions LuaValue.valueOf(int)
or LuaValue.valueOf(double)
+ functions. This ensures that values which can be represented as int
+ are wrapped in LuaInteger
instead of LuaDouble
.
+
+ Almost all API's implemented in LuaDouble are defined and documented in LuaValue
.
+
+ However the constants NAN
, POSINF
, NEGINF
,
+ JSTR_NAN
, JSTR_POSINF
, and JSTR_NEGINF
may be useful
+ when dealing with Nan or Infinite values.
+
+ LuaDouble also defines functions for handling the unique math rules of lua devision and modulo in +
++
+ +
+
LuaValue
,
+LuaNumber
,
+LuaInteger
,
+LuaValue.valueOf(int)
,
+LuaValue.valueOf(double)
+Field Summary | +|
---|---|
+static java.lang.String |
+JSTR_NAN
+
++ Constant String representation for NaN (not a number), "nan" |
+
+static java.lang.String |
+JSTR_NEGINF
+
++ Constant String representation for negative infinity, "-inf" |
+
+static java.lang.String |
+JSTR_POSINF
+
++ Constant String representation for positive infinity, "inf" |
+
+static LuaDouble |
+NAN
+
++ Constant LuaDouble representing NaN (not a number) |
+
+static LuaDouble |
+NEGINF
+
++ Constant LuaDouble representing negative infinity |
+
+static LuaDouble |
+POSINF
+
++ Constant LuaDouble representing positive infinity |
+
Fields inherited from class org.luaj.vm2.LuaNumber | +
---|
s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Method Summary | +|
---|---|
+ LuaValue |
+add(double lhs)
+
++ Add: Perform numeric add operation with another value + of double type with metatag processing |
+
+ LuaValue |
+add(LuaValue rhs)
+
++ Add: Perform numeric add operation with another value + including metatag processing. |
+
+ double |
+checkdouble()
+
++ Check that the value is numeric and return the value as a double, + or throw LuaError if not numeric |
+
+ int |
+checkint()
+
++ Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric |
+
+ LuaInteger |
+checkinteger()
+
++ Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric |
+
+ java.lang.String |
+checkjstring()
+
++ Convert this value to a Java String. |
+
+ long |
+checklong()
+
++ Check that the value is numeric, and convert and cast value to long, or throw LuaError if not numeric |
+
+ LuaNumber |
+checknumber()
+
++ Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError |
+
+ LuaString |
+checkstring()
+
++ Check that this is a lua string, or throw LuaError if it is not. |
+
+ LuaValue |
+checkvalidkey()
+
++ Check that this is a valid key in a table index operation, or throw LuaError if not |
+
+static double |
+ddiv_d(double lhs,
+ double rhs)
+
++ Divide two double numbers according to lua math, and return a double result. |
+
+static LuaValue |
+ddiv(double lhs,
+ double rhs)
+
++ Divide two double numbers according to lua math, and return a LuaValue result. |
+
+ LuaValue |
+div(double rhs)
+
++ Divide: Perform numeric divide operation by another value + of double type without metatag processing |
+
+ LuaValue |
+div(int rhs)
+
++ Divide: Perform numeric divide operation by another value + of int type without metatag processing |
+
+ LuaValue |
+div(LuaValue rhs)
+
++ Divide: Perform numeric divide operation by another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+divInto(double lhs)
+
++ Reverse-divide: Perform numeric divide operation into another value + with metatag processing |
+
+static double |
+dmod_d(double lhs,
+ double rhs)
+
++ Take modulo for double numbers according to lua math, and return a double result. |
+
+static LuaValue |
+dmod(double lhs,
+ double rhs)
+
++ Take modulo double numbers according to lua math, and return a LuaValue result. |
+
+ boolean |
+eq_b(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ ,
+ and return java boolean |
+
+ LuaValue |
+eq(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ . |
+
+ boolean |
+equals(java.lang.Object o)
+
++ |
+
+ boolean |
+gt_b(double rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ boolean |
+gt_b(int rhs)
+
++ Greater than: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+gt_b(LuaValue rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+gt(double rhs)
+
++ Greater than: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+gt(int rhs)
+
++ Greater than: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+gt(LuaValue rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ boolean |
+gteq_b(double rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+gteq_b(int rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+gteq_b(LuaValue rhs)
+
++ Greater than or equals: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+gteq(double rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+gteq(int rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+gteq(LuaValue rhs)
+
++ Greater than or equals: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ int |
+hashCode()
+
++ |
+
+ boolean |
+islong()
+
++ Check if this is a number and is representable by java long
+ without rounding or truncation |
+
+ boolean |
+isnumber()
+
++ Check if this is a number |
+
+ boolean |
+isstring()
+
++ Check if this is a string |
+
+ boolean |
+lt_b(double rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ boolean |
+lt_b(int rhs)
+
++ Less than: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+lt_b(LuaValue rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+lt(double rhs)
+
++ Less than: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+lt(int rhs)
+
++ Less than: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+lt(LuaValue rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ boolean |
+lteq_b(double rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+lteq_b(int rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+lteq_b(LuaValue rhs)
+
++ Less than or equals: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+lteq(double rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+lteq(int rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+lteq(LuaValue rhs)
+
++ Less than or equals: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+mod(double rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of double type without metatag processing |
+
+ LuaValue |
+mod(int rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of int type without metatag processing |
+
+ LuaValue |
+mod(LuaValue rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+modFrom(double lhs)
+
++ Reverse-modulo: Perform numeric modulo operation from another value + with metatag processing |
+
+ LuaValue |
+mul(double lhs)
+
++ Multiply: Perform numeric multiply operation with another value + of double type with metatag processing |
+
+ LuaValue |
+mul(int lhs)
+
++ Multiply: Perform numeric multiply operation with another value + of int type with metatag processing |
+
+ LuaValue |
+mul(LuaValue rhs)
+
++ Multiply: Perform numeric multiply operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+neg()
+
++ Unary minus: return negative value (-this) as defined by lua unary minus operator |
+
+ double |
+optdouble(double defval)
+
++ Check that optional argument is a number or string convertible to number and return as double |
+
+ int |
+optint(int defval)
+
++ Check that optional argument is a number or string convertible to number and return as int |
+
+ LuaInteger |
+optinteger(LuaInteger defval)
+
++ Check that optional argument is a number or string convertible to number and return as LuaInteger |
+
+ java.lang.String |
+optjstring(java.lang.String defval)
+
++ Check that optional argument is a string or number and return as Java String |
+
+ long |
+optlong(long defval)
+
++ Check that optional argument is a number or string convertible to number and return as long |
+
+ LuaNumber |
+optnumber(LuaNumber defval)
+
++ Check that optional argument is a number or string convertible to number and return as LuaNumber |
+
+ LuaString |
+optstring(LuaString defval)
+
++ Check that optional argument is a string or number and return as LuaString |
+
+ LuaValue |
+pow(double rhs)
+
++ Raise to power: Raise this value to a power + of double type with metatag processing |
+
+ LuaValue |
+pow(int rhs)
+
++ Raise to power: Raise this value to a power + of int type with metatag processing |
+
+ LuaValue |
+pow(LuaValue rhs)
+
++ Raise to power: Raise this value to a power + including metatag processing. |
+
+ LuaValue |
+powWith(double lhs)
+
++ Reverse-raise to power: Raise another value of double type to this power + with metatag processing |
+
+ LuaValue |
+powWith(int lhs)
+
++ Reverse-raise to power: Raise another value of double type to this power + with metatag processing |
+
+ boolean |
+raweq(double val)
+
++ Equals: Perform direct equality comparison with a double value + without metatag processing. |
+
+ boolean |
+raweq(int val)
+
++ Equals: Perform direct equality comparison with a int value + without metatag processing. |
+
+ boolean |
+raweq(LuaValue val)
+
++ Equals: Perform direct equality comparison with another value + without metatag processing. |
+
+ int |
+strcmp(LuaString rhs)
+
++ Perform string comparison with another value + known to be a LuaString
+ using string comparison based on byte values. |
+
+ LuaString |
+strvalue()
+
++ Convert this value to a string if it is a LuaString or LuaNumber ,
+ or throw a LuaError if it is not |
+
+ LuaValue |
+sub(double rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of double type with metatag processing |
+
+ LuaValue |
+sub(int rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of int type with metatag processing |
+
+ LuaValue |
+sub(LuaValue rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+subFrom(double lhs)
+
++ Reverse-subtract: Perform numeric subtract operation from an int value + with metatag processing |
+
+ byte |
+tobyte()
+
++ Convert to byte if numeric, or 0 if not. |
+
+ char |
+tochar()
+
++ Convert to char if numeric, or 0 if not. |
+
+ double |
+todouble()
+
++ Convert to double if numeric, or 0 if not. |
+
+ float |
+tofloat()
+
++ Convert to float if numeric, or 0 if not. |
+
+ int |
+toint()
+
++ Convert to int if numeric, or 0 if not. |
+
+ java.lang.String |
+tojstring()
+
++ Convert to human readable String for any type. |
+
+ long |
+tolong()
+
++ Convert to long if numeric, or 0 if not. |
+
+ LuaValue |
+tonumber()
+
++ Conditionally convert to lua number without throwing errors. |
+
+ short |
+toshort()
+
++ Convert to short if numeric, or 0 if not. |
+
+ LuaValue |
+tostring()
+
++ Conditionally convert to lua string without throwing errors. |
+
+static LuaNumber |
+valueOf(double d)
+
++ |
+
Methods inherited from class org.luaj.vm2.LuaNumber | +
---|
checknumber, concat, concat, concatTo, concatTo, getmetatable, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static final LuaDouble NAN+
+
+public static final LuaDouble POSINF+
+
+public static final LuaDouble NEGINF+
+
+public static final java.lang.String JSTR_NAN+
+
+public static final java.lang.String JSTR_POSINF+
+
+public static final java.lang.String JSTR_NEGINF+
+
+Method Detail | +
---|
+public static LuaNumber valueOf(double d)+
+public int hashCode()+
hashCode
in class java.lang.Object
+public boolean islong()+
LuaValue
this
is a number
and is representable by java long
+ without rounding or truncation
++
islong
in class LuaValue
number
+ meaning derives from LuaNumber
+ or derives from LuaString
and is convertible to a number,
+ and can be represented by long,
+ otherwise falseLuaValue.tonumber()
,
+LuaValue.checklong()
,
+LuaValue.optlong(long)
,
+LuaValue.TNUMBER
+public byte tobyte()+
LuaValue
+
tobyte
in class LuaValue
LuaValue.toint()
,
+LuaValue.todouble()
,
+#optbyte(byte)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public char tochar()+
LuaValue
+
tochar
in class LuaValue
LuaValue.toint()
,
+LuaValue.todouble()
,
+#optchar(char)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public double todouble()+
LuaValue
+
todouble
in class LuaValue
LuaValue.toint()
,
+LuaValue.tobyte()
,
+LuaValue.tochar()
,
+LuaValue.toshort()
,
+LuaValue.tolong()
,
+LuaValue.tofloat()
,
+LuaValue.optdouble(double)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public float tofloat()+
LuaValue
+
tofloat
in class LuaValue
LuaValue.toint()
,
+LuaValue.todouble()
,
+#optfloat(float)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public int toint()+
LuaValue
+
toint
in class LuaValue
LuaValue.tobyte()
,
+LuaValue.tochar()
,
+LuaValue.toshort()
,
+LuaValue.tolong()
,
+LuaValue.tofloat()
,
+LuaValue.todouble()
,
+LuaValue.optint(int)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public long tolong()+
LuaValue
+
tolong
in class LuaValue
LuaValue.isint()
,
+LuaValue.isinttype()
,
+LuaValue.toint()
,
+LuaValue.todouble()
,
+LuaValue.optlong(long)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public short toshort()+
LuaValue
+
toshort
in class LuaValue
LuaValue.toint()
,
+LuaValue.todouble()
,
+#optshort(short)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public double optdouble(double defval)+
LuaValue
+
optdouble
in class LuaValue
defval
- double to return if this
is nil or none
+this
cast to double if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optint(int)
,
+LuaValue.optinteger(LuaInteger)
,
+LuaValue.checkdouble()
,
+LuaValue.todouble()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public int optint(int defval)+
LuaValue
+
optint
in class LuaValue
defval
- int to return if this
is nil or none
+this
cast to int if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optlong(long)
,
+LuaValue.optinteger(LuaInteger)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public LuaInteger optinteger(LuaInteger defval)+
LuaValue
LuaInteger
++
optinteger
in class LuaValue
defval
- LuaInteger
to return if this
is nil or none
+this
converted and wrapped in LuaInteger
if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optint(int)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public long optlong(long defval)+
LuaValue
+
optlong
in class LuaValue
defval
- long to return if this
is nil or none
+this
cast to long if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optint(int)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public LuaInteger checkinteger()+
LuaValue
LuaError
if not numeric
+
+ Values that are LuaNumber
will be cast to int and may lose precision.
+ Values that are LuaString
that can be converted to a number will be converted,
+ then cast to int, so may also lose precision.
+
+
checkinteger
in class LuaValue
LuaInteger
if numericLuaValue.checkint()
,
+LuaValue.checklong()
,
+LuaValue.checkdouble()
,
+LuaValue.optinteger(LuaInteger)
,
+LuaValue.TNUMBER
+public LuaValue neg()+
LuaValue
(-this)
as defined by lua unary minus operator
++
neg
in class LuaValue
LuaBoolean
if boolean or nil,
+ numeric inverse as if numeric,
+ or metatag processing result if UNM
metatag is defined+public boolean equals(java.lang.Object o)+
equals
in class LuaValue
+public LuaValue eq(LuaValue val)+
LuaValue
EQ
.
++
eq
in class LuaValue
val
- The value to compare with.
+TRUE
if values are comparable and (this == rhs)
,
+ FALSE
if comparable but not equal,
+ LuaValue
if metatag processing occurs.LuaValue.eq_b(LuaValue)
,
+LuaValue.raweq(LuaValue)
,
+LuaValue.neq(LuaValue)
,
+LuaValue.eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
,
+LuaValue.EQ
+public boolean eq_b(LuaValue val)+
LuaValue
EQ
,
+ and return java boolean
++
eq_b
in class LuaValue
val
- The value to compare with.
+(this == rhs)
,
+ false if comparable but not equal,
+ result converted to java boolean if metatag processing occurs.LuaValue.eq(LuaValue)
,
+LuaValue.raweq(LuaValue)
,
+LuaValue.neq_b(LuaValue)
,
+LuaValue.eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
,
+LuaValue.EQ
+public boolean raweq(LuaValue val)+
LuaValue
+
raweq
in class LuaValue
val
- The value to compare with.
+(this == rhs)
, false otherwiseLuaValue.eq(LuaValue)
,
+LuaValue.raweq(LuaUserdata)
,
+LuaValue.raweq(LuaString)
,
+LuaValue.raweq(double)
,
+LuaValue.raweq(int)
,
+LuaValue.EQ
+public boolean raweq(double val)+
LuaValue
+
raweq
in class LuaValue
val
- The double value to compare with.
+this
is a LuaNumber
+ whose value equals val,
+ otherwise false+public boolean raweq(int val)+
LuaValue
+
raweq
in class LuaValue
val
- The double value to compare with.
+this
is a LuaNumber
+ whose value equals val,
+ otherwise false+public LuaValue add(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
add
in class LuaValue
rhs
- The right-hand-side value to perform the add with
+(this + rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue add(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
add
in class LuaValue
lhs
- The right-hand-side value to perform the add with
+(this + rhs)
if this is numericLuaValue.add(LuaValue)
+public LuaValue sub(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
sub
in class LuaValue
rhs
- The right-hand-side value to perform the subtract with
+(this - rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue sub(double rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
sub
in class LuaValue
rhs
- The right-hand-side value to perform the subtract with
+(this - rhs)
if this is numericLuaValue.sub(LuaValue)
+public LuaValue sub(int rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
sub
in class LuaValue
rhs
- The right-hand-side value to perform the subtract with
+(this - rhs)
if this is numericLuaValue.sub(LuaValue)
+public LuaValue subFrom(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
subFrom
in class LuaValue
lhs
- The left-hand-side value from which to perform the subtraction
+(lhs - this)
if this is numericLuaValue.sub(LuaValue)
,
+LuaValue.sub(double)
,
+LuaValue.sub(int)
+public LuaValue mul(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
mul
in class LuaValue
rhs
- The right-hand-side value to perform the multiply with
+(this * rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue mul(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
mul
in class LuaValue
lhs
- The right-hand-side value to perform the multiply with
+(this * rhs)
if this is numericLuaValue.mul(LuaValue)
+public LuaValue mul(int lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
mul
in class LuaValue
lhs
- The right-hand-side value to perform the multiply with
+(this * rhs)
if this is numericLuaValue.mul(LuaValue)
+public LuaValue pow(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
pow
in class LuaValue
rhs
- The power to raise this value to
+(this ^ rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue pow(double rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
pow
in class LuaValue
rhs
- The power to raise this value to
+(this ^ rhs)
if this is numericLuaValue.pow(LuaValue)
+public LuaValue pow(int rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
pow
in class LuaValue
rhs
- The power to raise this value to
+(this ^ rhs)
if this is numericLuaValue.pow(LuaValue)
+public LuaValue powWith(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
powWith
in class LuaValue
lhs
- The left-hand-side value which will be raised to this power
+(lhs ^ this)
if this is numericLuaValue.pow(LuaValue)
,
+LuaValue.pow(double)
,
+LuaValue.pow(int)
+public LuaValue powWith(int lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
powWith
in class LuaValue
lhs
- The left-hand-side value which will be raised to this power
+(lhs ^ this)
if this is numericLuaValue.pow(LuaValue)
,
+LuaValue.pow(double)
,
+LuaValue.pow(int)
+public LuaValue div(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
div
in class LuaValue
rhs
- The right-hand-side value to perform the divulo with
+(this / rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue div(double rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing LuaValue.div(LuaValue)
must be used
+
+
div
in class LuaValue
rhs
- The right-hand-side value to perform the divulo with
+(this / rhs)
if this is numericLuaValue.div(LuaValue)
+public LuaValue div(int rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing LuaValue.div(LuaValue)
must be used
+
+
div
in class LuaValue
rhs
- The right-hand-side value to perform the divulo with
+(this / rhs)
if this is numericLuaValue.div(LuaValue)
+public LuaValue divInto(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
divInto
in class LuaValue
lhs
- The left-hand-side value which will be divided by this
+(lhs / this)
if this is numericLuaValue.div(LuaValue)
,
+LuaValue.div(double)
,
+LuaValue.div(int)
+public LuaValue mod(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
mod
in class LuaValue
rhs
- The right-hand-side value to perform the modulo with
+(this % rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue mod(double rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing LuaValue.mod(LuaValue)
must be used
+
+
mod
in class LuaValue
rhs
- The right-hand-side value to perform the modulo with
+(this % rhs)
if this is numericLuaValue.mod(LuaValue)
+public LuaValue mod(int rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing LuaValue.mod(LuaValue)
must be used
+
+
mod
in class LuaValue
rhs
- The right-hand-side value to perform the modulo with
+(this % rhs)
if this is numericLuaValue.mod(LuaValue)
+public LuaValue modFrom(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
modFrom
in class LuaValue
lhs
- The left-hand-side value which will be modulo'ed by this
+(lhs % this)
if this is numericLuaValue.mod(LuaValue)
,
+LuaValue.mod(double)
,
+LuaValue.mod(int)
+public static LuaValue ddiv(double lhs, + double rhs)+
LuaValue
result.
++
lhs
- Left-hand-side of the division.rhs
- Right-hand-side of the division.
+LuaValue
for the result of the division,
+ taking into account positive and negiative infinity, and Nanddiv_d(double, double)
+public static double ddiv_d(double lhs, + double rhs)+
+
lhs
- Left-hand-side of the division.rhs
- Right-hand-side of the division.
+ddiv(double, double)
+public static LuaValue dmod(double lhs, + double rhs)+
LuaValue
result.
++
lhs
- Left-hand-side of the modulo.rhs
- Right-hand-side of the modulo.
+LuaValue
for the result of the modulo,
+ using lua's rules for modulodmod_d(double, double)
+public static double dmod_d(double lhs, + double rhs)+
+
lhs
- Left-hand-side of the modulo.rhs
- Right-hand-side of the modulo.
+dmod(double, double)
+public LuaValue lt(LuaValue rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lt
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this < rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue lt(double rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
lt
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this < rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(double)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue lt(int rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
lt
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this < rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lt_b(LuaValue rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this < rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lt_b(int rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
lt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this < rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lt_b(double rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this < rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue lteq(LuaValue rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lteq
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this <= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue lteq(double rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
lteq
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this <= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(double)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue lteq(int rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
lteq
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this <= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lteq_b(LuaValue rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this <= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lteq_b(int rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
lteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this <= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lteq_b(double rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
lteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this <= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(double)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue gt(LuaValue rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gt
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this > rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue gt(double rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
gt
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this > rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(double)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue gt(int rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
gt
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this > rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gt_b(LuaValue rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this > rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gt_b(int rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
gt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this > rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gt_b(double rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this > rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue gteq(LuaValue rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gteq
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this >= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue gteq(double rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
gteq
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this >= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(double)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue gteq(int rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
gteq
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this >= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gteq_b(LuaValue rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this >= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gteq_b(int rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
gteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this >= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gteq_b(double rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
gteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this >= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(double)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public int strcmp(LuaString rhs)+
LuaValue
LuaString
+ using string comparison based on byte values.
+
+ Only strings can be compared, meaning
+ each operand must derive from LuaString
.
+
+
strcmp
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with+public java.lang.String tojstring()+
LuaValue
+
tojstring
in class LuaValue
LuaValue.tostring()
,
+LuaValue.optjstring(String)
,
+LuaValue.checkjstring()
,
+LuaValue.isstring()
,
+TSTRING
+public LuaString strvalue()+
LuaValue
LuaString
or LuaNumber
,
+ or throw a LuaError
if it is not
++
strvalue
in class LuaValue
LuaString
corresponding to the value if a string or number+public LuaString optstring(LuaString defval)+
LuaValue
LuaString
++
optstring
in class LuaValue
defval
- LuaString
to return if this
is nil or none
+this
converted to LuaString
if a string or number,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.tojstring()
,
+LuaValue.optjstring(String)
,
+LuaValue.checkstring()
,
+LuaValue.toString()
,
+LuaValue.TSTRING
+public LuaValue tostring()+
LuaValue
+ In lua all numbers are strings, so this function will return
+ the LuaValue
this
if it is a string or number,
+ and NIL
for all other cases.
+
+ This allows values to be tested for their "string-ness" without + the penalty of throwing exceptions. +
+
tostring
in class LuaValue
this
if it is a LuaString
or LuaNumber
,
+ otherwise NIL
LuaValue.tonumber()
,
+LuaValue.tojstring()
,
+LuaValue.optstring(LuaString)
,
+LuaValue.checkstring()
,
+LuaValue.toString()
+public java.lang.String optjstring(java.lang.String defval)+
LuaValue
+
optjstring
in class LuaValue
defval
- LuaString
to return if this
is nil or none
+this
converted to String if a string or number,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.tojstring()
,
+LuaValue.optstring(LuaString)
,
+LuaValue.checkjstring()
,
+LuaValue.toString()
,
+LuaValue.TSTRING
+public LuaNumber optnumber(LuaNumber defval)+
LuaValue
LuaNumber
++
optnumber
in class LuaNumber
defval
- LuaNumber
to return if this
is nil or none
+this
cast to LuaNumber
if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optlong(long)
,
+LuaValue.optint(int)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public boolean isnumber()+
LuaValue
this
is a number
++
isnumber
in class LuaNumber
number
,
+ meaning derives from LuaNumber
+ or derives from LuaString
and is convertible to a number,
+ otherwise falseLuaValue.tonumber()
,
+LuaValue.checknumber()
,
+LuaValue.optnumber(LuaNumber)
,
+LuaValue.TNUMBER
+public boolean isstring()+
LuaValue
this
is a string
++
isstring
in class LuaNumber
string
,
+ meaning derives from LuaString
or LuaNumber
,
+ otherwise falseLuaValue.tostring()
,
+LuaValue.checkstring()
,
+LuaValue.optstring(LuaString)
,
+LuaValue.TSTRING
+public LuaValue tonumber()+
LuaValue
+ In lua all numbers are strings, but not all strings are numbers.
+ This function will return
+ the LuaValue
this
if it is a number
+ or a string convertible to a number,
+ and NIL
for all other cases.
+
+ This allows values to be tested for their "numeric-ness" without + the penalty of throwing exceptions, + nor the cost of converting the type and creating storage for it. +
+
tonumber
in class LuaNumber
this
if it is a LuaNumber
+ or LuaString
that can be converted to a number,
+ otherwise LuaValue.NIL
LuaValue.tostring()
,
+LuaValue.optnumber(LuaNumber)
,
+LuaValue.checknumber()
,
+LuaValue.toint()
,
+LuaValue.todouble()
+public int checkint()+
LuaValue
LuaError
if not numeric
+
+ Values that are LuaNumber
will be cast to int and may lose precision.
+ Values that are LuaString
that can be converted to a number will be converted,
+ then cast to int, so may also lose precision.
+
+
checkint
in class LuaValue
LuaValue.checkinteger()
,
+LuaValue.checklong()
,
+LuaValue.checkdouble()
,
+LuaValue.optint(int)
,
+LuaValue.TNUMBER
+public long checklong()+
LuaValue
LuaError
if not numeric
+
+ Values that are LuaNumber
will be cast to long and may lose precision.
+ Values that are LuaString
that can be converted to a number will be converted,
+ then cast to long, so may also lose precision.
+
+
checklong
in class LuaValue
LuaValue.checkint()
,
+LuaValue.checkinteger()
,
+LuaValue.checkdouble()
,
+LuaValue.optlong(long)
,
+LuaValue.TNUMBER
+public LuaNumber checknumber()+
LuaValue
LuaError
+
+ Values that are LuaString
that can be converted to a number will be converted and returned.
+
+
checknumber
in class LuaNumber
LuaNumber
if numericLuaValue.checkint()
,
+LuaValue.checkinteger()
,
+LuaValue.checkdouble()
,
+LuaValue.checklong()
,
+LuaValue.optnumber(LuaNumber)
,
+LuaValue.TNUMBER
+public double checkdouble()+
LuaValue
LuaError
if not numeric
+
+ Values that are LuaNumber
and values that are LuaString
+ that can be converted to a number will be converted to double.
+
+
checkdouble
in class LuaValue
LuaValue.checkint()
,
+LuaValue.checkinteger()
,
+LuaValue.checklong()
,
+LuaValue.optdouble(double)
,
+LuaValue.TNUMBER
+public java.lang.String checkjstring()+
LuaValue
+ The string representations here will roughly match what is produced by the + C lua distribution, however hash codes have no relationship, + and there may be differences in number formatting. +
+
checkjstring
in class LuaValue
LuaValue.checkstring()
,
+LuaValue.optjstring(String)
,
+LuaValue.tojstring()
,
+LuaValue.isstring()
,
+LuaValue.TSTRING
+public LuaString checkstring()+
LuaValue
LuaError
if it is not.
+
+ In lua all numbers are strings, so this will succeed for
+ anything that derives from LuaString
or LuaNumber
.
+ Numbers will be converted to LuaString
.
+
+
checkstring
in class LuaValue
LuaString
representation of the value if it is a LuaString
or LuaNumber
LuaValue.checkjstring()
,
+LuaValue.optstring(LuaString)
,
+LuaValue.tostring()
,
+LuaValue.isstring()
,
+LuaValue.TSTRING
+public LuaValue checkvalidkey()+
LuaValue
LuaError
if not
++
checkvalidkey
in class LuaValue
this
if valid as a table keyLuaValue.isnil()
,
+LuaValue.isinttype()
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + java.lang.Throwable + java.lang.Exception + java.lang.RuntimeException + org.luaj.vm2.LuaError ++
public class LuaError
+RuntimeException that is thrown and caught in response to a lua error. +
+ LuaError
is used wherever a lua call to error()
+ would be used within a script.
+
+ Since it is an unchecked exception inheriting from RuntimeException
,
+ Java method signatures do notdeclare this exception, althoug it can
+ be thrown on almost any luaj Java operation.
+ This is analagous to the fact that any lua script can throw a lua error at any time.
+
+
+ +
+
+Constructor Summary | +|
---|---|
LuaError(java.lang.String message)
+
++ Construct a LuaError with a specific message. |
+|
LuaError(java.lang.String message,
+ int level)
+
++ Construct a LuaError with a message, and level to draw line number information from. |
+|
LuaError(java.lang.Throwable cause)
+
++ Construct LuaError when a program exception occurs. |
+
+Method Summary | +|
---|---|
+ java.lang.Throwable |
+getCause()
+
++ Get the cause, if any. |
+
+ void |
+printStackTrace()
+
++ Print the message and stack trace |
+
Methods inherited from class java.lang.Throwable | +
---|
fillInStackTrace, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, setStackTrace, toString |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public LuaError(java.lang.Throwable cause)+
+ All errors generated from lua code should throw LuaError(String) instead. +
+
cause
- the Throwable that caused the error, if known.+public LuaError(java.lang.String message)+
+
message
- message to supply+public LuaError(java.lang.String message, + int level)+
+
message
- message to supplylevel
- where to supply line info from in call stack+Method Detail | +
---|
+public void printStackTrace()+
+
printStackTrace
in class java.lang.Throwable
+public java.lang.Throwable getCause()+
+
getCause
in class java.lang.Throwable
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction ++
public abstract class LuaFunction
+Base class for functions implemented in Java. +
+ Direct subclass include LibFunction
which is the base class for
+ all built-in library functions coded in Java,
+ and LuaClosure
, which represents a lua closure
+ whose bytecode is interpreted when the function is invoked.
+
+ +
+
LuaValue
,
+LibFunction
,
+LuaClosure
+Field Summary | +|
---|---|
+protected LuaValue |
+env
+
++ |
+
+static LuaValue |
+s_metatable
+
++ Shared static metatable for all functions and closures. |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
LuaFunction()
+
++ |
+|
LuaFunction(LuaValue env)
+
++ |
+
+Method Summary | +|
---|---|
+ LuaValue |
+checkfunction()
+
++ Check that the value is a function , or throw LuaError if not |
+
+ LuaValue |
+getfenv()
+
++ Get the environemnt for an instance. |
+
+ LuaValue |
+getmetatable()
+
++ Get the metatable for this LuaValue |
+
+ boolean |
+isfunction()
+
++ Check if this is a function |
+
+ LuaFunction |
+optfunction(LuaFunction defval)
+
++ Check that optional argument is a function and return as LuaFunction |
+
+ void |
+setfenv(LuaValue env)
+
++ Set the environment on an object. |
+
+ int |
+type()
+
++ Get the enumeration value for the type of this value. |
+
+ java.lang.String |
+typename()
+
++ Get the String name of the type of this value. |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static LuaValue s_metatable+
+
+protected LuaValue env+
+Constructor Detail | +
---|
+public LuaFunction()+
+public LuaFunction(LuaValue env)+
+Method Detail | +
---|
+public int type()+
LuaValue
+
type
in class LuaValue
TNIL
,
+ TBOOLEAN
,
+ TNUMBER
,
+ TSTRING
,
+ TTABLE
,
+ TFUNCTION
,
+ TUSERDATA
,
+ TTHREAD
LuaValue.typename()
+public java.lang.String typename()+
LuaValue
+
+
typename
in class LuaValue
LuaValue.TYPE_NAMES
+ corresponding to the type of this value:
+ "nil", "boolean", "number", "string",
+ "table", "function", "userdata", "thread"LuaValue.type()
+public boolean isfunction()+
LuaValue
this
is a function
++
isfunction
in class LuaValue
function
, otherwise falseLuaValue.isclosure()
,
+LuaValue.checkfunction()
,
+#optfunciton(LuaFunction)
,
+LuaValue.TFUNCTION
+public LuaValue checkfunction()+
LuaValue
LuaError
if not
+
+ A function is considered anything whose LuaValue.type()
returns TFUNCTION
.
+ In practice it will be either a built-in Java function, typically deriving from
+ LuaFunction
or a LuaClosure
which represents lua source compiled
+ into lua bytecode.
+
+
checkfunction
in class LuaValue
this
if if a lua function or closureLuaValue.checkclosure()
+public LuaFunction optfunction(LuaFunction defval)+
LuaValue
LuaFunction
+
+ A LuaFunction
may either be a Java function that implements
+ functionality directly in Java,
+ or a LuaClosure
+ which is a LuaFunction
that executes lua bytecode.
+
+
optfunction
in class LuaValue
defval
- LuaFunction
to return if this
is nil or none
+this
cast to LuaFunction
if a function,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.checkfunction()
,
+LuaValue.isfunction()
,
+LuaValue.TFUNCTION
+public LuaValue getmetatable()+
LuaValue
LuaValue
+
+ For LuaTable
and LuaUserdata
instances,
+ the metatable returned is this instance metatable.
+ For all other types, the class metatable value will be returned.
+
+
getmetatable
in class LuaValue
LuaBoolean.s_metatable
,
+LuaNumber.s_metatable
,
+LuaNil.s_metatable
,
+s_metatable
,
+LuaThread.s_metatable
+public LuaValue getfenv()+
LuaValue
+
getfenv
in class LuaValue
LuaValue
currently set as the instances environent.+public void setfenv(LuaValue env)+
LuaValue
+ Typically the environment is created once per application via a platform
+ helper method such as JsePlatform.standardGlobals()
+ However, any object can serve as an environment if it contains suitable metatag
+ values to implement LuaValue.get(LuaValue)
to provide the environment values.
+
+
setfenv
in class LuaValue
env
- LuaValue
(typically a LuaTable
) containing the environment.JmePlatform
,
+JsePlatform
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaNumber + org.luaj.vm2.LuaInteger ++
public class LuaInteger
+Extension of LuaNumber
which can hold a Java int as its value.
+
+ These instance are not instantiated directly by clients, but indirectly
+ via the static functions LuaValue.valueOf(int)
or LuaValue.valueOf(double)
+ functions. This ensures that policies regarding pooling of instances are
+ encapsulated.
+
+ There are no API's specific to LuaInteger that are useful beyond what is already
+ exposed in LuaValue
.
+
+ +
+
LuaValue
,
+LuaNumber
,
+LuaDouble
,
+LuaValue.valueOf(int)
,
+LuaValue.valueOf(double)
+Field Summary | +|
---|---|
+ int |
+v
+
++ The value being held by this instance. |
+
Fields inherited from class org.luaj.vm2.LuaNumber | +
---|
s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Method Summary | +|
---|---|
+ LuaValue |
+add(double lhs)
+
++ Add: Perform numeric add operation with another value + of double type with metatag processing |
+
+ LuaValue |
+add(int lhs)
+
++ Add: Perform numeric add operation with another value + of int type with metatag processing |
+
+ LuaValue |
+add(LuaValue rhs)
+
++ Add: Perform numeric add operation with another value + including metatag processing. |
+
+ double |
+checkdouble()
+
++ Check that the value is numeric and return the value as a double, + or throw LuaError if not numeric |
+
+ int |
+checkint()
+
++ Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric |
+
+ LuaInteger |
+checkinteger()
+
++ Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric |
+
+ java.lang.String |
+checkjstring()
+
++ Convert this value to a Java String. |
+
+ long |
+checklong()
+
++ Check that the value is numeric, and convert and cast value to long, or throw LuaError if not numeric |
+
+ LuaString |
+checkstring()
+
++ Check that this is a lua string, or throw LuaError if it is not. |
+
+ LuaValue |
+div(double rhs)
+
++ Divide: Perform numeric divide operation by another value + of double type without metatag processing |
+
+ LuaValue |
+div(int rhs)
+
++ Divide: Perform numeric divide operation by another value + of int type without metatag processing |
+
+ LuaValue |
+div(LuaValue rhs)
+
++ Divide: Perform numeric divide operation by another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+divInto(double lhs)
+
++ Reverse-divide: Perform numeric divide operation into another value + with metatag processing |
+
+ boolean |
+eq_b(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ ,
+ and return java boolean |
+
+ LuaValue |
+eq(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ . |
+
+ boolean |
+equals(java.lang.Object o)
+
++ |
+
+ boolean |
+gt_b(double rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ boolean |
+gt_b(int rhs)
+
++ Greater than: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+gt_b(LuaValue rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+gt(double rhs)
+
++ Greater than: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+gt(int rhs)
+
++ Greater than: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+gt(LuaValue rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ boolean |
+gteq_b(double rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+gteq_b(int rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+gteq_b(LuaValue rhs)
+
++ Greater than or equals: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+gteq(double rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+gteq(int rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+gteq(LuaValue rhs)
+
++ Greater than or equals: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ int |
+hashCode()
+
++ |
+
+ boolean |
+isint()
+
++ Check if this is a number and is representable by java int
+ without rounding or truncation |
+
+ boolean |
+isinttype()
+
++ Check if this is a LuaInteger |
+
+ boolean |
+islong()
+
++ Check if this is a number and is representable by java long
+ without rounding or truncation |
+
+ boolean |
+isstring()
+
++ Check if this is a string |
+
+ boolean |
+lt_b(double rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ boolean |
+lt_b(int rhs)
+
++ Less than: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+lt_b(LuaValue rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+lt(double rhs)
+
++ Less than: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+lt(int rhs)
+
++ Less than: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+lt(LuaValue rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ boolean |
+lteq_b(double rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+lteq_b(int rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+lteq_b(LuaValue rhs)
+
++ Less than or equals: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+lteq(double rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+lteq(int rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+lteq(LuaValue rhs)
+
++ Less than or equals: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+mod(double rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of double type without metatag processing |
+
+ LuaValue |
+mod(int rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of int type without metatag processing |
+
+ LuaValue |
+mod(LuaValue rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+modFrom(double lhs)
+
++ Reverse-modulo: Perform numeric modulo operation from another value + with metatag processing |
+
+ LuaValue |
+mul(double lhs)
+
++ Multiply: Perform numeric multiply operation with another value + of double type with metatag processing |
+
+ LuaValue |
+mul(int lhs)
+
++ Multiply: Perform numeric multiply operation with another value + of int type with metatag processing |
+
+ LuaValue |
+mul(LuaValue rhs)
+
++ Multiply: Perform numeric multiply operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+neg()
+
++ Unary minus: return negative value (-this) as defined by lua unary minus operator |
+
+ double |
+optdouble(double defval)
+
++ Check that optional argument is a number or string convertible to number and return as double |
+
+ int |
+optint(int defval)
+
++ Check that optional argument is a number or string convertible to number and return as int |
+
+ LuaInteger |
+optinteger(LuaInteger defval)
+
++ Check that optional argument is a number or string convertible to number and return as LuaInteger |
+
+ java.lang.String |
+optjstring(java.lang.String defval)
+
++ Check that optional argument is a string or number and return as Java String |
+
+ long |
+optlong(long defval)
+
++ Check that optional argument is a number or string convertible to number and return as long |
+
+ LuaString |
+optstring(LuaString defval)
+
++ Check that optional argument is a string or number and return as LuaString |
+
+ LuaValue |
+pow(double rhs)
+
++ Raise to power: Raise this value to a power + of double type with metatag processing |
+
+ LuaValue |
+pow(int rhs)
+
++ Raise to power: Raise this value to a power + of int type with metatag processing |
+
+ LuaValue |
+pow(LuaValue rhs)
+
++ Raise to power: Raise this value to a power + including metatag processing. |
+
+ LuaValue |
+powWith(double lhs)
+
++ Reverse-raise to power: Raise another value of double type to this power + with metatag processing |
+
+ LuaValue |
+powWith(int lhs)
+
++ Reverse-raise to power: Raise another value of double type to this power + with metatag processing |
+
+ boolean |
+raweq(double val)
+
++ Equals: Perform direct equality comparison with a double value + without metatag processing. |
+
+ boolean |
+raweq(int val)
+
++ Equals: Perform direct equality comparison with a int value + without metatag processing. |
+
+ boolean |
+raweq(LuaValue val)
+
++ Equals: Perform direct equality comparison with another value + without metatag processing. |
+
+ int |
+strcmp(LuaString rhs)
+
++ Perform string comparison with another value + known to be a LuaString
+ using string comparison based on byte values. |
+
+ LuaString |
+strvalue()
+
++ Convert this value to a string if it is a LuaString or LuaNumber ,
+ or throw a LuaError if it is not |
+
+ LuaValue |
+sub(double rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of double type with metatag processing |
+
+ LuaValue |
+sub(int rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of int type with metatag processing |
+
+ LuaValue |
+sub(LuaValue rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+subFrom(double lhs)
+
++ Reverse-subtract: Perform numeric subtract operation from an int value + with metatag processing |
+
+ LuaValue |
+subFrom(int lhs)
+
++ Reverse-subtract: Perform numeric subtract operation from a double value + without metatag processing |
+
+ byte |
+tobyte()
+
++ Convert to byte if numeric, or 0 if not. |
+
+ char |
+tochar()
+
++ Convert to char if numeric, or 0 if not. |
+
+ double |
+todouble()
+
++ Convert to double if numeric, or 0 if not. |
+
+ float |
+tofloat()
+
++ Convert to float if numeric, or 0 if not. |
+
+ int |
+toint()
+
++ Convert to int if numeric, or 0 if not. |
+
+ java.lang.String |
+tojstring()
+
++ Convert to human readable String for any type. |
+
+ long |
+tolong()
+
++ Convert to long if numeric, or 0 if not. |
+
+ short |
+toshort()
+
++ Convert to short if numeric, or 0 if not. |
+
+ LuaValue |
+tostring()
+
++ Conditionally convert to lua string without throwing errors. |
+
+static LuaInteger |
+valueOf(int i)
+
++ |
+
+static LuaNumber |
+valueOf(long l)
+
++ Return a LuaNumber that represents the value provided |
+
Methods inherited from class org.luaj.vm2.LuaNumber | +
---|
checknumber, checknumber, concat, concat, concatTo, concatTo, getmetatable, isnumber, optnumber, tonumber, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public final int v+
+
+Method Detail | +
---|
+public static LuaInteger valueOf(int i)+
+public static LuaNumber valueOf(long l)+
+
l
- long value to represent.
+LuaValue.valueOf(int)
,
+LuaValue.valueOf(double)
+public boolean isint()+
LuaValue
this
is a number
and is representable by java int
+ without rounding or truncation
++
isint
in class LuaValue
number
+ meaning derives from LuaNumber
+ or derives from LuaString
and is convertible to a number,
+ and can be represented by int,
+ otherwise falseLuaValue.isinttype()
,
+LuaValue.islong()
,
+LuaValue.tonumber()
,
+LuaValue.checkint()
,
+LuaValue.optint(int)
,
+LuaValue.TNUMBER
+public boolean isinttype()+
LuaValue
this
is a LuaInteger
+ + No attempt to convert from string will be made by this call. +
+
isinttype
in class LuaValue
LuaInteger
,
+ otherwise falseLuaValue.isint()
,
+LuaValue.isnumber()
,
+LuaValue.tonumber()
,
+LuaValue.TNUMBER
+public boolean islong()+
LuaValue
this
is a number
and is representable by java long
+ without rounding or truncation
++
islong
in class LuaValue
number
+ meaning derives from LuaNumber
+ or derives from LuaString
and is convertible to a number,
+ and can be represented by long,
+ otherwise falseLuaValue.tonumber()
,
+LuaValue.checklong()
,
+LuaValue.optlong(long)
,
+LuaValue.TNUMBER
+public byte tobyte()+
LuaValue
+
tobyte
in class LuaValue
LuaValue.toint()
,
+LuaValue.todouble()
,
+#optbyte(byte)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public char tochar()+
LuaValue
+
tochar
in class LuaValue
LuaValue.toint()
,
+LuaValue.todouble()
,
+#optchar(char)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public double todouble()+
LuaValue
+
todouble
in class LuaValue
LuaValue.toint()
,
+LuaValue.tobyte()
,
+LuaValue.tochar()
,
+LuaValue.toshort()
,
+LuaValue.tolong()
,
+LuaValue.tofloat()
,
+LuaValue.optdouble(double)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public float tofloat()+
LuaValue
+
tofloat
in class LuaValue
LuaValue.toint()
,
+LuaValue.todouble()
,
+#optfloat(float)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public int toint()+
LuaValue
+
toint
in class LuaValue
LuaValue.tobyte()
,
+LuaValue.tochar()
,
+LuaValue.toshort()
,
+LuaValue.tolong()
,
+LuaValue.tofloat()
,
+LuaValue.todouble()
,
+LuaValue.optint(int)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public long tolong()+
LuaValue
+
tolong
in class LuaValue
LuaValue.isint()
,
+LuaValue.isinttype()
,
+LuaValue.toint()
,
+LuaValue.todouble()
,
+LuaValue.optlong(long)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public short toshort()+
LuaValue
+
toshort
in class LuaValue
LuaValue.toint()
,
+LuaValue.todouble()
,
+#optshort(short)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public double optdouble(double defval)+
LuaValue
+
optdouble
in class LuaValue
defval
- double to return if this
is nil or none
+this
cast to double if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optint(int)
,
+LuaValue.optinteger(LuaInteger)
,
+LuaValue.checkdouble()
,
+LuaValue.todouble()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public int optint(int defval)+
LuaValue
+
optint
in class LuaValue
defval
- int to return if this
is nil or none
+this
cast to int if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optlong(long)
,
+LuaValue.optinteger(LuaInteger)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public LuaInteger optinteger(LuaInteger defval)+
LuaValue
LuaInteger
++
optinteger
in class LuaValue
defval
- LuaInteger
to return if this
is nil or none
+this
converted and wrapped in LuaInteger
if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optint(int)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public long optlong(long defval)+
LuaValue
+
optlong
in class LuaValue
defval
- long to return if this
is nil or none
+this
cast to long if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optint(int)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public java.lang.String tojstring()+
LuaValue
+
tojstring
in class LuaValue
LuaValue.tostring()
,
+LuaValue.optjstring(String)
,
+LuaValue.checkjstring()
,
+LuaValue.isstring()
,
+TSTRING
+public LuaString strvalue()+
LuaValue
LuaString
or LuaNumber
,
+ or throw a LuaError
if it is not
++
strvalue
in class LuaValue
LuaString
corresponding to the value if a string or number+public LuaString optstring(LuaString defval)+
LuaValue
LuaString
++
optstring
in class LuaValue
defval
- LuaString
to return if this
is nil or none
+this
converted to LuaString
if a string or number,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.tojstring()
,
+LuaValue.optjstring(String)
,
+LuaValue.checkstring()
,
+LuaValue.toString()
,
+LuaValue.TSTRING
+public LuaValue tostring()+
LuaValue
+ In lua all numbers are strings, so this function will return
+ the LuaValue
this
if it is a string or number,
+ and NIL
for all other cases.
+
+ This allows values to be tested for their "string-ness" without + the penalty of throwing exceptions. +
+
tostring
in class LuaValue
this
if it is a LuaString
or LuaNumber
,
+ otherwise NIL
LuaValue.tonumber()
,
+LuaValue.tojstring()
,
+LuaValue.optstring(LuaString)
,
+LuaValue.checkstring()
,
+LuaValue.toString()
+public java.lang.String optjstring(java.lang.String defval)+
LuaValue
+
optjstring
in class LuaValue
defval
- LuaString
to return if this
is nil or none
+this
converted to String if a string or number,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.tojstring()
,
+LuaValue.optstring(LuaString)
,
+LuaValue.checkjstring()
,
+LuaValue.toString()
,
+LuaValue.TSTRING
+public LuaInteger checkinteger()+
LuaValue
LuaError
if not numeric
+
+ Values that are LuaNumber
will be cast to int and may lose precision.
+ Values that are LuaString
that can be converted to a number will be converted,
+ then cast to int, so may also lose precision.
+
+
checkinteger
in class LuaValue
LuaInteger
if numericLuaValue.checkint()
,
+LuaValue.checklong()
,
+LuaValue.checkdouble()
,
+LuaValue.optinteger(LuaInteger)
,
+LuaValue.TNUMBER
+public boolean isstring()+
LuaValue
this
is a string
++
isstring
in class LuaNumber
string
,
+ meaning derives from LuaString
or LuaNumber
,
+ otherwise falseLuaValue.tostring()
,
+LuaValue.checkstring()
,
+LuaValue.optstring(LuaString)
,
+LuaValue.TSTRING
+public int hashCode()+
hashCode
in class java.lang.Object
+public LuaValue neg()+
LuaValue
(-this)
as defined by lua unary minus operator
++
neg
in class LuaValue
LuaBoolean
if boolean or nil,
+ numeric inverse as if numeric,
+ or metatag processing result if UNM
metatag is defined+public boolean equals(java.lang.Object o)+
equals
in class LuaValue
+public LuaValue eq(LuaValue val)+
LuaValue
EQ
.
++
eq
in class LuaValue
val
- The value to compare with.
+TRUE
if values are comparable and (this == rhs)
,
+ FALSE
if comparable but not equal,
+ LuaValue
if metatag processing occurs.LuaValue.eq_b(LuaValue)
,
+LuaValue.raweq(LuaValue)
,
+LuaValue.neq(LuaValue)
,
+LuaValue.eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
,
+LuaValue.EQ
+public boolean eq_b(LuaValue val)+
LuaValue
EQ
,
+ and return java boolean
++
eq_b
in class LuaValue
val
- The value to compare with.
+(this == rhs)
,
+ false if comparable but not equal,
+ result converted to java boolean if metatag processing occurs.LuaValue.eq(LuaValue)
,
+LuaValue.raweq(LuaValue)
,
+LuaValue.neq_b(LuaValue)
,
+LuaValue.eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
,
+LuaValue.EQ
+public boolean raweq(LuaValue val)+
LuaValue
+
raweq
in class LuaValue
val
- The value to compare with.
+(this == rhs)
, false otherwiseLuaValue.eq(LuaValue)
,
+LuaValue.raweq(LuaUserdata)
,
+LuaValue.raweq(LuaString)
,
+LuaValue.raweq(double)
,
+LuaValue.raweq(int)
,
+LuaValue.EQ
+public boolean raweq(double val)+
LuaValue
+
raweq
in class LuaValue
val
- The double value to compare with.
+this
is a LuaNumber
+ whose value equals val,
+ otherwise false+public boolean raweq(int val)+
LuaValue
+
raweq
in class LuaValue
val
- The double value to compare with.
+this
is a LuaNumber
+ whose value equals val,
+ otherwise false+public LuaValue add(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
add
in class LuaValue
rhs
- The right-hand-side value to perform the add with
+(this + rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue add(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
add
in class LuaValue
lhs
- The right-hand-side value to perform the add with
+(this + rhs)
if this is numericLuaValue.add(LuaValue)
+public LuaValue add(int lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
add
in class LuaValue
lhs
- The right-hand-side value to perform the add with
+(this + rhs)
if this is numericLuaValue.add(LuaValue)
+public LuaValue sub(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
sub
in class LuaValue
rhs
- The right-hand-side value to perform the subtract with
+(this - rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue sub(double rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
sub
in class LuaValue
rhs
- The right-hand-side value to perform the subtract with
+(this - rhs)
if this is numericLuaValue.sub(LuaValue)
+public LuaValue sub(int rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
sub
in class LuaValue
rhs
- The right-hand-side value to perform the subtract with
+(this - rhs)
if this is numericLuaValue.sub(LuaValue)
+public LuaValue subFrom(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
subFrom
in class LuaValue
lhs
- The left-hand-side value from which to perform the subtraction
+(lhs - this)
if this is numericLuaValue.sub(LuaValue)
,
+LuaValue.sub(double)
,
+LuaValue.sub(int)
+public LuaValue subFrom(int lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing LuaValue.sub(LuaValue)
must be used
+
+
subFrom
in class LuaValue
lhs
- The left-hand-side value from which to perform the subtraction
+(lhs - this)
if this is numericLuaValue.sub(LuaValue)
,
+LuaValue.sub(double)
,
+LuaValue.sub(int)
+public LuaValue mul(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
mul
in class LuaValue
rhs
- The right-hand-side value to perform the multiply with
+(this * rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue mul(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
mul
in class LuaValue
lhs
- The right-hand-side value to perform the multiply with
+(this * rhs)
if this is numericLuaValue.mul(LuaValue)
+public LuaValue mul(int lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
mul
in class LuaValue
lhs
- The right-hand-side value to perform the multiply with
+(this * rhs)
if this is numericLuaValue.mul(LuaValue)
+public LuaValue pow(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
pow
in class LuaValue
rhs
- The power to raise this value to
+(this ^ rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue pow(double rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
pow
in class LuaValue
rhs
- The power to raise this value to
+(this ^ rhs)
if this is numericLuaValue.pow(LuaValue)
+public LuaValue pow(int rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
pow
in class LuaValue
rhs
- The power to raise this value to
+(this ^ rhs)
if this is numericLuaValue.pow(LuaValue)
+public LuaValue powWith(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
powWith
in class LuaValue
lhs
- The left-hand-side value which will be raised to this power
+(lhs ^ this)
if this is numericLuaValue.pow(LuaValue)
,
+LuaValue.pow(double)
,
+LuaValue.pow(int)
+public LuaValue powWith(int lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
powWith
in class LuaValue
lhs
- The left-hand-side value which will be raised to this power
+(lhs ^ this)
if this is numericLuaValue.pow(LuaValue)
,
+LuaValue.pow(double)
,
+LuaValue.pow(int)
+public LuaValue div(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
div
in class LuaValue
rhs
- The right-hand-side value to perform the divulo with
+(this / rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue div(double rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing LuaValue.div(LuaValue)
must be used
+
+
div
in class LuaValue
rhs
- The right-hand-side value to perform the divulo with
+(this / rhs)
if this is numericLuaValue.div(LuaValue)
+public LuaValue div(int rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing LuaValue.div(LuaValue)
must be used
+
+
div
in class LuaValue
rhs
- The right-hand-side value to perform the divulo with
+(this / rhs)
if this is numericLuaValue.div(LuaValue)
+public LuaValue divInto(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
divInto
in class LuaValue
lhs
- The left-hand-side value which will be divided by this
+(lhs / this)
if this is numericLuaValue.div(LuaValue)
,
+LuaValue.div(double)
,
+LuaValue.div(int)
+public LuaValue mod(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
mod
in class LuaValue
rhs
- The right-hand-side value to perform the modulo with
+(this % rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue mod(double rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing LuaValue.mod(LuaValue)
must be used
+
+
mod
in class LuaValue
rhs
- The right-hand-side value to perform the modulo with
+(this % rhs)
if this is numericLuaValue.mod(LuaValue)
+public LuaValue mod(int rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing LuaValue.mod(LuaValue)
must be used
+
+
mod
in class LuaValue
rhs
- The right-hand-side value to perform the modulo with
+(this % rhs)
if this is numericLuaValue.mod(LuaValue)
+public LuaValue modFrom(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
modFrom
in class LuaValue
lhs
- The left-hand-side value which will be modulo'ed by this
+(lhs % this)
if this is numericLuaValue.mod(LuaValue)
,
+LuaValue.mod(double)
,
+LuaValue.mod(int)
+public LuaValue lt(LuaValue rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lt
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this < rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue lt(double rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
lt
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this < rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(double)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue lt(int rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
lt
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this < rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lt_b(LuaValue rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this < rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lt_b(int rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
lt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this < rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lt_b(double rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this < rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue lteq(LuaValue rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lteq
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this <= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue lteq(double rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
lteq
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this <= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(double)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue lteq(int rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
lteq
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this <= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lteq_b(LuaValue rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this <= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lteq_b(int rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
lteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this <= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lteq_b(double rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
lteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this <= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(double)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue gt(LuaValue rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gt
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this > rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue gt(double rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
gt
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this > rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(double)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue gt(int rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
gt
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this > rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gt_b(LuaValue rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this > rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gt_b(int rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
gt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this > rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gt_b(double rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this > rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue gteq(LuaValue rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gteq
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this >= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue gteq(double rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
gteq
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this >= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(double)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue gteq(int rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
gteq
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this >= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gteq_b(LuaValue rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this >= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gteq_b(int rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
gteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this >= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gteq_b(double rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
gteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this >= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(double)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public int strcmp(LuaString rhs)+
LuaValue
LuaString
+ using string comparison based on byte values.
+
+ Only strings can be compared, meaning
+ each operand must derive from LuaString
.
+
+
strcmp
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with+public int checkint()+
LuaValue
LuaError
if not numeric
+
+ Values that are LuaNumber
will be cast to int and may lose precision.
+ Values that are LuaString
that can be converted to a number will be converted,
+ then cast to int, so may also lose precision.
+
+
checkint
in class LuaValue
LuaValue.checkinteger()
,
+LuaValue.checklong()
,
+LuaValue.checkdouble()
,
+LuaValue.optint(int)
,
+LuaValue.TNUMBER
+public long checklong()+
LuaValue
LuaError
if not numeric
+
+ Values that are LuaNumber
will be cast to long and may lose precision.
+ Values that are LuaString
that can be converted to a number will be converted,
+ then cast to long, so may also lose precision.
+
+
checklong
in class LuaValue
LuaValue.checkint()
,
+LuaValue.checkinteger()
,
+LuaValue.checkdouble()
,
+LuaValue.optlong(long)
,
+LuaValue.TNUMBER
+public double checkdouble()+
LuaValue
LuaError
if not numeric
+
+ Values that are LuaNumber
and values that are LuaString
+ that can be converted to a number will be converted to double.
+
+
checkdouble
in class LuaValue
LuaValue.checkint()
,
+LuaValue.checkinteger()
,
+LuaValue.checklong()
,
+LuaValue.optdouble(double)
,
+LuaValue.TNUMBER
+public java.lang.String checkjstring()+
LuaValue
+ The string representations here will roughly match what is produced by the + C lua distribution, however hash codes have no relationship, + and there may be differences in number formatting. +
+
checkjstring
in class LuaValue
LuaValue.checkstring()
,
+LuaValue.optjstring(String)
,
+LuaValue.tojstring()
,
+LuaValue.isstring()
,
+LuaValue.TSTRING
+public LuaString checkstring()+
LuaValue
LuaError
if it is not.
+
+ In lua all numbers are strings, so this will succeed for
+ anything that derives from LuaString
or LuaNumber
.
+ Numbers will be converted to LuaString
.
+
+
checkstring
in class LuaValue
LuaString
representation of the value if it is a LuaString
or LuaNumber
LuaValue.checkjstring()
,
+LuaValue.optstring(LuaString)
,
+LuaValue.tostring()
,
+LuaValue.isstring()
,
+LuaValue.TSTRING
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaNil ++
public class LuaNil
+Class to encapsulate behavior of the singleton instance nil
+
+ There will be one instance of this class, LuaValue.NIL
,
+ per Java virtual machine.
+ However, the Varargs
instance LuaValue.NONE
+ which is the empty list,
+ is also considered treated as a nil value by default.
+
+ Although it is possible to test for nil using Java == operator,
+ the recommended approach is to use the method LuaValue.isnil()
+ instead. By using that any ambiguities between
+ LuaValue.NIL
and LuaValue.NONE
are avoided.
+
+ +
+
LuaValue
,
+LuaValue.NIL
+Field Summary | +|
---|---|
+static LuaValue |
+s_metatable
+
++ |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Method Summary | +|
---|---|
+ LuaValue |
+checknotnil()
+
++ Check that this is not the value NIL , or throw LuaError if it is |
+
+ LuaValue |
+checkvalidkey()
+
++ Check that this is a valid key in a table index operation, or throw LuaError if not |
+
+ boolean |
+equals(java.lang.Object o)
+
++ |
+
+ LuaValue |
+getmetatable()
+
++ Get the metatable for this LuaValue |
+
+ boolean |
+isnil()
+
++ Check if this is nil |
+
+ LuaValue |
+not()
+
++ Unary not: return inverse boolean value (~this) as defined by lua not operator |
+
+ boolean |
+optboolean(boolean defval)
+
++ Check that optional argument is a boolean and return its boolean value |
+
+ LuaClosure |
+optclosure(LuaClosure defval)
+
++ Check that optional argument is a closure and return as LuaClosure |
+
+ double |
+optdouble(double defval)
+
++ Check that optional argument is a number or string convertible to number and return as double |
+
+ LuaFunction |
+optfunction(LuaFunction defval)
+
++ Check that optional argument is a function and return as LuaFunction |
+
+ int |
+optint(int defval)
+
++ Check that optional argument is a number or string convertible to number and return as int |
+
+ LuaInteger |
+optinteger(LuaInteger defval)
+
++ Check that optional argument is a number or string convertible to number and return as LuaInteger |
+
+ java.lang.String |
+optjstring(java.lang.String defval)
+
++ Check that optional argument is a string or number and return as Java String |
+
+ long |
+optlong(long defval)
+
++ Check that optional argument is a number or string convertible to number and return as long |
+
+ LuaNumber |
+optnumber(LuaNumber defval)
+
++ Check that optional argument is a number or string convertible to number and return as LuaNumber |
+
+ LuaString |
+optstring(LuaString defval)
+
++ Check that optional argument is a string or number and return as LuaString |
+
+ LuaTable |
+opttable(LuaTable defval)
+
++ Check that optional argument is a table and return as LuaTable |
+
+ LuaThread |
+optthread(LuaThread defval)
+
++ Check that optional argument is a thread and return as LuaThread |
+
+ java.lang.Object |
+optuserdata(java.lang.Class c,
+ java.lang.Object defval)
+
++ Check that optional argument is a userdata whose instance is of a type + and return the Object instance |
+
+ java.lang.Object |
+optuserdata(java.lang.Object defval)
+
++ Check that optional argument is a userdata and return the Object instance |
+
+ LuaValue |
+optvalue(LuaValue defval)
+
++ Perform argument check that this is not nil or none. |
+
+ boolean |
+toboolean()
+
++ Convert to boolean false if LuaValue.NIL or FALSE , true if anything else |
+
+ java.lang.String |
+tojstring()
+
++ Convert to human readable String for any type. |
+
+ int |
+type()
+
++ Get the enumeration value for the type of this value. |
+
+ java.lang.String |
+typename()
+
++ Get the String name of the type of this value. |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static LuaValue s_metatable+
+Method Detail | +
---|
+public int type()+
LuaValue
+
type
in class LuaValue
TNIL
,
+ TBOOLEAN
,
+ TNUMBER
,
+ TSTRING
,
+ TTABLE
,
+ TFUNCTION
,
+ TUSERDATA
,
+ TTHREAD
LuaValue.typename()
+public java.lang.String typename()+
LuaValue
+
+
typename
in class LuaValue
LuaValue.TYPE_NAMES
+ corresponding to the type of this value:
+ "nil", "boolean", "number", "string",
+ "table", "function", "userdata", "thread"LuaValue.type()
+public java.lang.String tojstring()+
LuaValue
+
tojstring
in class LuaValue
LuaValue.tostring()
,
+LuaValue.optjstring(String)
,
+LuaValue.checkjstring()
,
+LuaValue.isstring()
,
+TSTRING
+public LuaValue not()+
LuaValue
(~this)
as defined by lua not operator
++
not
in class LuaValue
TRUE
if NIL
or FALSE
, otherwise FALSE
+public boolean toboolean()+
LuaValue
LuaValue.NIL
or FALSE
, true if anything else
++
toboolean
in class LuaValue
LuaValue.optboolean(boolean)
,
+LuaValue.checkboolean()
,
+LuaValue.isboolean()
,
+TBOOLEAN
+public boolean isnil()+
LuaValue
this
is nil
++
isnil
in class LuaValue
nil
, otherwise falseLuaValue.NIL
,
+LuaValue.NONE
,
+LuaValue.checknotnil()
,
+LuaValue.optvalue(LuaValue)
,
+Varargs.isnoneornil(int)
,
+LuaValue.TNIL
,
+LuaValue.TNONE
+public LuaValue getmetatable()+
LuaValue
LuaValue
+
+ For LuaTable
and LuaUserdata
instances,
+ the metatable returned is this instance metatable.
+ For all other types, the class metatable value will be returned.
+
+
getmetatable
in class LuaValue
LuaBoolean.s_metatable
,
+LuaNumber.s_metatable
,
+s_metatable
,
+LuaFunction.s_metatable
,
+LuaThread.s_metatable
+public boolean equals(java.lang.Object o)+
equals
in class LuaValue
+public LuaValue checknotnil()+
LuaValue
NIL
, or throw LuaError
if it is
++
checknotnil
in class LuaValue
this
if it is not NIL
LuaValue.optvalue(LuaValue)
+public LuaValue checkvalidkey()+
LuaValue
LuaError
if not
++
checkvalidkey
in class LuaValue
this
if valid as a table keyLuaValue.isnil()
,
+LuaValue.isinttype()
+public boolean optboolean(boolean defval)+
LuaValue
+
optboolean
in class LuaValue
defval
- boolean value to return if this
is nil or none
+this
cast to boolean if a ,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.checkboolean()
,
+LuaValue.isboolean()
,
+LuaValue.TBOOLEAN
+public LuaClosure optclosure(LuaClosure defval)+
LuaValue
LuaClosure
+
+ A LuaClosure
is a that executes lua byteccode.
+
+
optclosure
in class LuaValue
defval
- LuaClosure
to return if this
is nil or none
+this
cast to LuaClosure
if a function,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.checkclosure()
,
+LuaValue.isclosure()
,
+LuaValue.TFUNCTION
+public double optdouble(double defval)+
LuaValue
+
optdouble
in class LuaValue
defval
- double to return if this
is nil or none
+this
cast to double if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optint(int)
,
+LuaValue.optinteger(LuaInteger)
,
+LuaValue.checkdouble()
,
+LuaValue.todouble()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public LuaFunction optfunction(LuaFunction defval)+
LuaValue
LuaFunction
+
+ A LuaFunction
may either be a Java function that implements
+ functionality directly in Java,
+ or a LuaClosure
+ which is a LuaFunction
that executes lua bytecode.
+
+
optfunction
in class LuaValue
defval
- LuaFunction
to return if this
is nil or none
+this
cast to LuaFunction
if a function,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.checkfunction()
,
+LuaValue.isfunction()
,
+LuaValue.TFUNCTION
+public int optint(int defval)+
LuaValue
+
optint
in class LuaValue
defval
- int to return if this
is nil or none
+this
cast to int if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optlong(long)
,
+LuaValue.optinteger(LuaInteger)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public LuaInteger optinteger(LuaInteger defval)+
LuaValue
LuaInteger
++
optinteger
in class LuaValue
defval
- LuaInteger
to return if this
is nil or none
+this
converted and wrapped in LuaInteger
if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optint(int)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public long optlong(long defval)+
LuaValue
+
optlong
in class LuaValue
defval
- long to return if this
is nil or none
+this
cast to long if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optint(int)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public LuaNumber optnumber(LuaNumber defval)+
LuaValue
LuaNumber
++
optnumber
in class LuaValue
defval
- LuaNumber
to return if this
is nil or none
+this
cast to LuaNumber
if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optlong(long)
,
+LuaValue.optint(int)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public LuaTable opttable(LuaTable defval)+
LuaValue
LuaTable
++
opttable
in class LuaValue
defval
- LuaTable
to return if this
is nil or none
+this
cast to LuaTable
if a table,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.checktable()
,
+LuaValue.istable()
,
+LuaValue.TTABLE
+public LuaThread optthread(LuaThread defval)+
LuaValue
LuaThread
++
optthread
in class LuaValue
defval
- LuaThread
to return if this
is nil or none
+this
cast to LuaTable
if a thread,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.checkthread()
,
+LuaValue.isthread()
,
+LuaValue.TTHREAD
+public java.lang.String optjstring(java.lang.String defval)+
LuaValue
+
optjstring
in class LuaValue
defval
- LuaString
to return if this
is nil or none
+this
converted to String if a string or number,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.tojstring()
,
+LuaValue.optstring(LuaString)
,
+LuaValue.checkjstring()
,
+LuaValue.toString()
,
+LuaValue.TSTRING
+public LuaString optstring(LuaString defval)+
LuaValue
LuaString
++
optstring
in class LuaValue
defval
- LuaString
to return if this
is nil or none
+this
converted to LuaString
if a string or number,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.tojstring()
,
+LuaValue.optjstring(String)
,
+LuaValue.checkstring()
,
+LuaValue.toString()
,
+LuaValue.TSTRING
+public java.lang.Object optuserdata(java.lang.Object defval)+
LuaValue
+
optuserdata
in class LuaValue
defval
- Object to return if this
is nil or none
+LuaUserdata
,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.checkuserdata()
,
+LuaValue.isuserdata()
,
+LuaValue.optuserdata(Class, Object)
,
+LuaValue.TUSERDATA
+public java.lang.Object optuserdata(java.lang.Class c, + java.lang.Object defval)+
LuaValue
+
optuserdata
in class LuaValue
c
- Class to test userdata instance againstdefval
- Object to return if this
is nil or none
+LuaUserdata
and instance is assignable to c
,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.checkuserdata(Class)
,
+LuaValue.isuserdata(Class)
,
+LuaValue.optuserdata(Object)
,
+LuaValue.TUSERDATA
+public LuaValue optvalue(LuaValue defval)+
LuaValue
+
optvalue
in class LuaValue
defval
- LuaValue
to return if this
is nil or none
+this
if not nil or none, else defval
LuaValue.NIL
,
+LuaValue.NONE
,
+LuaValue.isnil()
,
+Varargs.isnoneornil(int)
,
+LuaValue.TNIL
,
+LuaValue.TNONE
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaNumber ++
public abstract class LuaNumber
+Base class for representing numbers as lua values directly. +
+ The main subclasses are LuaInteger
which holds values that fit in a java int,
+ and LuaDouble
which holds all other number values.
+
+ +
+
LuaInteger
,
+LuaDouble
,
+LuaValue
+Field Summary | +|
---|---|
+static LuaValue |
+s_metatable
+
++ Shared static metatable for all number values represented in lua. |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
LuaNumber()
+
++ |
+
+Method Summary | +|
---|---|
+ LuaNumber |
+checknumber()
+
++ Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError |
+
+ LuaNumber |
+checknumber(java.lang.String errmsg)
+
++ Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError |
+
+ Buffer |
+concat(Buffer rhs)
+
++ Concatenate a Buffer onto this value and return the result
+ using rules of lua string concatenation including metatag processing. |
+
+ LuaValue |
+concat(LuaValue rhs)
+
++ Concatenate another value onto this value and return the result + using rules of lua string concatenation including metatag processing. |
+
+ LuaValue |
+concatTo(LuaNumber lhs)
+
++ Reverse-concatenation: concatenate this value onto another value + known to be a LuaNumber
+ and return the result using rules of lua string concatenation including
+ metatag processing. |
+
+ LuaValue |
+concatTo(LuaString lhs)
+
++ Reverse-concatenation: concatenate this value onto another value + known to be a LuaString
+ and return the result using rules of lua string concatenation including
+ metatag processing. |
+
+ LuaValue |
+getmetatable()
+
++ Get the metatable for this LuaValue |
+
+ boolean |
+isnumber()
+
++ Check if this is a number |
+
+ boolean |
+isstring()
+
++ Check if this is a string |
+
+ LuaNumber |
+optnumber(LuaNumber defval)
+
++ Check that optional argument is a number or string convertible to number and return as LuaNumber |
+
+ LuaValue |
+tonumber()
+
++ Conditionally convert to lua number without throwing errors. |
+
+ int |
+type()
+
++ Get the enumeration value for the type of this value. |
+
+ java.lang.String |
+typename()
+
++ Get the String name of the type of this value. |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static LuaValue s_metatable+
+
+Constructor Detail | +
---|
+public LuaNumber()+
+Method Detail | +
---|
+public int type()+
LuaValue
+
type
in class LuaValue
TNIL
,
+ TBOOLEAN
,
+ TNUMBER
,
+ TSTRING
,
+ TTABLE
,
+ TFUNCTION
,
+ TUSERDATA
,
+ TTHREAD
LuaValue.typename()
+public java.lang.String typename()+
LuaValue
+
+
typename
in class LuaValue
LuaValue.TYPE_NAMES
+ corresponding to the type of this value:
+ "nil", "boolean", "number", "string",
+ "table", "function", "userdata", "thread"LuaValue.type()
+public LuaNumber checknumber()+
LuaValue
LuaError
+
+ Values that are LuaString
that can be converted to a number will be converted and returned.
+
+
checknumber
in class LuaValue
LuaNumber
if numericLuaValue.checkint()
,
+LuaValue.checkinteger()
,
+LuaValue.checkdouble()
,
+LuaValue.checklong()
,
+LuaValue.optnumber(LuaNumber)
,
+LuaValue.TNUMBER
+public LuaNumber checknumber(java.lang.String errmsg)+
LuaValue
LuaError
+
+ Values that are LuaString
that can be converted to a number will be converted and returned.
+
+
checknumber
in class LuaValue
errmsg
- String message to supply if conversion fails
+LuaNumber
if numericLuaValue.checkint()
,
+LuaValue.checkinteger()
,
+LuaValue.checkdouble()
,
+LuaValue.checklong()
,
+LuaValue.optnumber(LuaNumber)
,
+LuaValue.TNUMBER
+public LuaNumber optnumber(LuaNumber defval)+
LuaValue
LuaNumber
++
optnumber
in class LuaValue
defval
- LuaNumber
to return if this
is nil or none
+this
cast to LuaNumber
if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optlong(long)
,
+LuaValue.optint(int)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public LuaValue tonumber()+
LuaValue
+ In lua all numbers are strings, but not all strings are numbers.
+ This function will return
+ the LuaValue
this
if it is a number
+ or a string convertible to a number,
+ and NIL
for all other cases.
+
+ This allows values to be tested for their "numeric-ness" without + the penalty of throwing exceptions, + nor the cost of converting the type and creating storage for it. +
+
tonumber
in class LuaValue
this
if it is a LuaNumber
+ or LuaString
that can be converted to a number,
+ otherwise LuaValue.NIL
LuaValue.tostring()
,
+LuaValue.optnumber(LuaNumber)
,
+LuaValue.checknumber()
,
+LuaValue.toint()
,
+LuaValue.todouble()
+public boolean isnumber()+
LuaValue
this
is a number
++
isnumber
in class LuaValue
number
,
+ meaning derives from LuaNumber
+ or derives from LuaString
and is convertible to a number,
+ otherwise falseLuaValue.tonumber()
,
+LuaValue.checknumber()
,
+LuaValue.optnumber(LuaNumber)
,
+LuaValue.TNUMBER
+public boolean isstring()+
LuaValue
this
is a string
++
isstring
in class LuaValue
string
,
+ meaning derives from LuaString
or LuaNumber
,
+ otherwise falseLuaValue.tostring()
,
+LuaValue.checkstring()
,
+LuaValue.optstring(LuaString)
,
+LuaValue.TSTRING
+public LuaValue getmetatable()+
LuaValue
LuaValue
+
+ For LuaTable
and LuaUserdata
instances,
+ the metatable returned is this instance metatable.
+ For all other types, the class metatable value will be returned.
+
+
getmetatable
in class LuaValue
LuaBoolean.s_metatable
,
+s_metatable
,
+LuaNil.s_metatable
,
+LuaFunction.s_metatable
,
+LuaThread.s_metatable
+public LuaValue concat(LuaValue rhs)+
LuaValue
+ Only strings and numbers as represented can be concatenated, meaning
+ each operand must derive from LuaString
or LuaNumber
.
+
+
concat
in class LuaValue
rhs
- The right-hand-side value to perform the operation with+public Buffer concat(Buffer rhs)+
LuaValue
Buffer
onto this value and return the result
+ using rules of lua string concatenation including metatag processing.
+
+ Only strings and numbers as represented can be concatenated, meaning
+ each operand must derive from LuaString
or LuaNumber
.
+
+
concat
in class LuaValue
rhs
- The right-hand-side Buffer
to perform the operation with
+(this .. rhs)
+public LuaValue concatTo(LuaNumber lhs)+
LuaValue
LuaNumber
+ and return the result using rules of lua string concatenation including
+ metatag processing.
+
+ Only strings and numbers as represented can be concatenated, meaning
+ each operand must derive from LuaString
or LuaNumber
.
+
+
concatTo
in class LuaValue
lhs
- The left-hand-side value onto which this will be concatenatedLuaValue.concat(LuaValue)
+public LuaValue concatTo(LuaString lhs)+
LuaValue
LuaString
+ and return the result using rules of lua string concatenation including
+ metatag processing.
+
+ Only strings and numbers as represented can be concatenated, meaning
+ each operand must derive from LuaString
or LuaNumber
.
+
+
concatTo
in class LuaValue
lhs
- The left-hand-side value onto which this will be concatenatedLuaValue.concat(LuaValue)
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaString ++
public class LuaString
+Subclass of LuaValue
for representing lua strings.
+
+ Because lua string values are more nearly sequences of bytes than
+ sequences of characters or unicode code points, the LuaString
+ implementation holds the string value in an internal byte array.
+
+ LuaString
values are generally not mutable once constructed,
+ so multiple LuaString
values can chare a single byte array.
+
+ Currently LuaString
s are pooled via a centrally managed weak table.
+ To ensure that as many string values as possible take advantage of this,
+ Constructors are not exposed directly. As with number, booleans, and nil,
+ instance construction should be via LuaValue.valueOf(byte[])
or similar API.
+
+ When Java Strings are used to initialize LuaString
data, the UTF8 encoding is assumed.
+ The functions
+ LuaString#lengthAsUtf8(char[]),
+ {@link LuaString#encodeToUtf8(char[], byte[], int)}, and
+ {@link LuaString#decodeAsUtf8(byte[], int, int)
+ are used to convert back and forth between UTF8 byte arrays and character arrays.
+
+ +
+
LuaValue
,
+LuaValue.valueOf(String)
,
+LuaValue.valueOf(byte[])
+Field Summary | +|
---|---|
+ byte[] |
+m_bytes
+
++ The bytes for the string |
+
+ int |
+m_length
+
++ The number of bytes that comprise this string |
+
+ int |
+m_offset
+
++ The offset into the byte array, 0 means start at the first byte |
+
+static LuaValue |
+s_metatable
+
++ The singleton instance representing lua true |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Method Summary | +|
---|---|
+ LuaValue |
+add(double rhs)
+
++ Add: Perform numeric add operation with another value + of double type with metatag processing |
+
+ LuaValue |
+add(int rhs)
+
++ Add: Perform numeric add operation with another value + of int type with metatag processing |
+
+ LuaValue |
+add(LuaValue rhs)
+
++ Add: Perform numeric add operation with another value + including metatag processing. |
+
+ int |
+charAt(int index)
+
++ |
+
+ double |
+checkdouble()
+
++ Check that the value is numeric and return the value as a double, + or throw LuaError if not numeric |
+
+ int |
+checkint()
+
++ Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric |
+
+ LuaInteger |
+checkinteger()
+
++ Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric |
+
+ java.lang.String |
+checkjstring()
+
++ Convert this value to a Java String. |
+
+ long |
+checklong()
+
++ Check that the value is numeric, and convert and cast value to long, or throw LuaError if not numeric |
+
+ LuaNumber |
+checknumber()
+
++ Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError |
+
+ LuaNumber |
+checknumber(java.lang.String msg)
+
++ Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError |
+
+ LuaString |
+checkstring()
+
++ Check that this is a lua string, or throw LuaError if it is not. |
+
+ Buffer |
+concat(Buffer rhs)
+
++ Concatenate a Buffer onto this value and return the result
+ using rules of lua string concatenation including metatag processing. |
+
+ LuaValue |
+concat(LuaValue rhs)
+
++ Concatenate another value onto this value and return the result + using rules of lua string concatenation including metatag processing. |
+
+ LuaValue |
+concatTo(LuaNumber lhs)
+
++ Reverse-concatenation: concatenate this value onto another value + known to be a LuaNumber
+ and return the result using rules of lua string concatenation including
+ metatag processing. |
+
+ LuaValue |
+concatTo(LuaString lhs)
+
++ Reverse-concatenation: concatenate this value onto another value + known to be a LuaString
+ and return the result using rules of lua string concatenation including
+ metatag processing. |
+
+ void |
+copyInto(int strOffset,
+ byte[] bytes,
+ int arrayOffset,
+ int len)
+
++ Copy the bytes of the string into the given byte array. |
+
+static java.lang.String |
+decodeAsUtf8(byte[] bytes,
+ int offset,
+ int length)
+
++ Convert to Java String interpreting as utf8 characters. |
+
+ LuaValue |
+div(double rhs)
+
++ Divide: Perform numeric divide operation by another value + of double type without metatag processing |
+
+ LuaValue |
+div(int rhs)
+
++ Divide: Perform numeric divide operation by another value + of int type without metatag processing |
+
+ LuaValue |
+div(LuaValue rhs)
+
++ Divide: Perform numeric divide operation by another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+divInto(double lhs)
+
++ Reverse-divide: Perform numeric divide operation into another value + with metatag processing |
+
+static void |
+encodeToUtf8(char[] chars,
+ byte[] bytes,
+ int off)
+
++ Encode the given Java string as UTF-8 bytes, writing the result to bytes + starting at offset. |
+
+ boolean |
+eq_b(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ ,
+ and return java boolean |
+
+ LuaValue |
+eq(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ . |
+
+static boolean |
+equals(byte[] a,
+ int i,
+ byte[] b,
+ int j,
+ int n)
+
++ |
+
+static boolean |
+equals(LuaString a,
+ int i,
+ LuaString b,
+ int j,
+ int n)
+
++ |
+
+ boolean |
+equals(java.lang.Object o)
+
++ |
+
+ LuaValue |
+get(LuaValue key)
+
++ Get a value in a table including metatag processing using INDEX . |
+
+ LuaValue |
+getmetatable()
+
++ Get the metatable for this LuaValue |
+
+ boolean |
+gt_b(double rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ boolean |
+gt_b(int rhs)
+
++ Greater than: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+gt_b(LuaValue rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+gt(LuaValue rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ boolean |
+gteq_b(double rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+gteq_b(int rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+gteq_b(LuaValue rhs)
+
++ Greater than or equals: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+gteq(LuaValue rhs)
+
++ Greater than or equals: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ int |
+hashCode()
+
++ |
+
+ int |
+indexOf(byte b,
+ int start)
+
++ Find the index of a byte starting at a point in this string |
+
+ int |
+indexOf(LuaString s,
+ int start)
+
++ Find the index of a string starting at a point in this string |
+
+ int |
+indexOfAny(LuaString accept)
+
++ Java version of strpbrk - find index of any byte that in an accept string. |
+
+ boolean |
+isint()
+
++ Check if this is a number and is representable by java int
+ without rounding or truncation |
+
+ boolean |
+islong()
+
++ Check if this is a number and is representable by java long
+ without rounding or truncation |
+
+ boolean |
+isnumber()
+
++ Check if this is a number |
+
+ boolean |
+isstring()
+
++ Check if this is a string |
+
+ boolean |
+isValidUtf8()
+
++ Check that a byte sequence is valid UTF-8 |
+
+ int |
+lastIndexOf(LuaString s)
+
++ Find the last index of a string in this string |
+
+ LuaValue |
+len()
+
++ Length operator: return lua length of object (#this) including metatag processing as java int |
+
+ int |
+length()
+
++ Length operator: return lua length of object (#this) including metatag processing as java int |
+
+static int |
+lengthAsUtf8(char[] chars)
+
++ Count the number of bytes required to encode the string as UTF-8. |
+
+ boolean |
+lt_b(double rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ boolean |
+lt_b(int rhs)
+
++ Less than: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+lt_b(LuaValue rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+lt(LuaValue rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ boolean |
+lteq_b(double rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+lteq_b(int rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+lteq_b(LuaValue rhs)
+
++ Less than or equals: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+lteq(LuaValue rhs)
+
++ Less than or equals: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ int |
+luaByte(int index)
+
++ |
+
+ LuaValue |
+mod(double rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of double type without metatag processing |
+
+ LuaValue |
+mod(int rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of int type without metatag processing |
+
+ LuaValue |
+mod(LuaValue rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+modFrom(double lhs)
+
++ Reverse-modulo: Perform numeric modulo operation from another value + with metatag processing |
+
+ LuaValue |
+mul(double rhs)
+
++ Multiply: Perform numeric multiply operation with another value + of double type with metatag processing |
+
+ LuaValue |
+mul(int rhs)
+
++ Multiply: Perform numeric multiply operation with another value + of int type with metatag processing |
+
+ LuaValue |
+mul(LuaValue rhs)
+
++ Multiply: Perform numeric multiply operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+neg()
+
++ Unary minus: return negative value (-this) as defined by lua unary minus operator |
+
+ double |
+optdouble(double defval)
+
++ Check that optional argument is a number or string convertible to number and return as double |
+
+ int |
+optint(int defval)
+
++ Check that optional argument is a number or string convertible to number and return as int |
+
+ LuaInteger |
+optinteger(LuaInteger defval)
+
++ Check that optional argument is a number or string convertible to number and return as LuaInteger |
+
+ java.lang.String |
+optjstring(java.lang.String defval)
+
++ Check that optional argument is a string or number and return as Java String |
+
+ long |
+optlong(long defval)
+
++ Check that optional argument is a number or string convertible to number and return as long |
+
+ LuaNumber |
+optnumber(LuaNumber defval)
+
++ Check that optional argument is a number or string convertible to number and return as LuaNumber |
+
+ LuaString |
+optstring(LuaString defval)
+
++ Check that optional argument is a string or number and return as LuaString |
+
+ LuaValue |
+pow(double rhs)
+
++ Raise to power: Raise this value to a power + of double type with metatag processing |
+
+ LuaValue |
+pow(int rhs)
+
++ Raise to power: Raise this value to a power + of int type with metatag processing |
+
+ LuaValue |
+pow(LuaValue rhs)
+
++ Raise to power: Raise this value to a power + including metatag processing. |
+
+ LuaValue |
+powWith(double lhs)
+
++ Reverse-raise to power: Raise another value of double type to this power + with metatag processing |
+
+ LuaValue |
+powWith(int lhs)
+
++ Reverse-raise to power: Raise another value of double type to this power + with metatag processing |
+
+ boolean |
+raweq(LuaString s)
+
++ Equals: Perform direct equality comparison with a LuaString value
+ without metatag processing. |
+
+ boolean |
+raweq(LuaValue val)
+
++ Equals: Perform direct equality comparison with another value + without metatag processing. |
+
+ double |
+scannumber(int base)
+
++ Convert to a number in a base, or return Double.NaN if not a number. |
+
+ int |
+strcmp(LuaString rhs)
+
++ Perform string comparison with another value + known to be a LuaString
+ using string comparison based on byte values. |
+
+ int |
+strcmp(LuaValue lhs)
+
++ Perform string comparison with another value + of any type + using string comparison based on byte values. |
+
+ LuaString |
+strvalue()
+
++ Convert this value to a string if it is a LuaString or LuaNumber ,
+ or throw a LuaError if it is not |
+
+ LuaValue |
+sub(double rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of double type with metatag processing |
+
+ LuaValue |
+sub(int rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of int type with metatag processing |
+
+ LuaValue |
+sub(LuaValue rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+subFrom(double lhs)
+
++ Reverse-subtract: Perform numeric subtract operation from an int value + with metatag processing |
+
+ LuaString |
+substring(int beginIndex,
+ int endIndex)
+
++ |
+
+ byte |
+tobyte()
+
++ Convert to byte if numeric, or 0 if not. |
+
+ char |
+tochar()
+
++ Convert to char if numeric, or 0 if not. |
+
+ double |
+todouble()
+
++ Convert to double if numeric, or 0 if not. |
+
+ float |
+tofloat()
+
++ Convert to float if numeric, or 0 if not. |
+
+ java.io.InputStream |
+toInputStream()
+
++ Convert value to an input stream. |
+
+ int |
+toint()
+
++ Convert to int if numeric, or 0 if not. |
+
+ java.lang.String |
+tojstring()
+
++ Convert to human readable String for any type. |
+
+ long |
+tolong()
+
++ Convert to long if numeric, or 0 if not. |
+
+ LuaValue |
+tonumber()
+
++ Conditionally convert to lua number without throwing errors. |
+
+ LuaValue |
+tonumber(int base)
+
++ convert to a number using a supplied base, or NIL if it can't be converted |
+
+ short |
+toshort()
+
++ Convert to short if numeric, or 0 if not. |
+
+ LuaValue |
+tostring()
+
++ Conditionally convert to lua string without throwing errors. |
+
+ int |
+type()
+
++ Get the enumeration value for the type of this value. |
+
+ java.lang.String |
+typename()
+
++ Get the String name of the type of this value. |
+
+static LuaString |
+valueOf(byte[] bytes)
+
++ Construct a LuaString around a byte array without copying the contents. |
+
+static LuaString |
+valueOf(byte[] bytes,
+ int off,
+ int len)
+
++ Construct a LuaString around a byte array without copying the contents. |
+
+static LuaString |
+valueOf(char[] bytes)
+
++ Construct a LuaString using the supplied characters as byte values. |
+
+static LuaString |
+valueOf(java.lang.String string)
+
++ Get a LuaString instance whose bytes match
+ the supplied Java String using the UTF8 encoding. |
+
+ void |
+write(java.io.DataOutputStream writer,
+ int i,
+ int len)
+
++ |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static LuaValue s_metatable+
true
++
+public final byte[] m_bytes+
+
+public final int m_offset+
+
+public final int m_length+
+
+Method Detail | +
---|
+public static LuaString valueOf(java.lang.String string)+
LuaString
instance whose bytes match
+ the supplied Java String using the UTF8 encoding.
++
string
- Java String containing characters to encode as UTF8
+LuaString
with UTF8 bytes corresponding to the supplied String+public static LuaString valueOf(byte[] bytes, + int off, + int len)+
LuaString
around a byte array without copying the contents.
+ + The array is used directly after this is called, so clients must not change contents. +
+
+
bytes
- byte bufferoff
- offset into the byte bufferlen
- length of the byte buffer
+LuaString
wrapping the byte buffer+public static LuaString valueOf(char[] bytes)+
LuaString
using the supplied characters as byte values.
+ + Only th elow-order 8-bits of each character are used, the remainder is ignored. +
+ This is most useful for constructing byte sequences that do not conform to UTF8. +
+
bytes
- array of char, whose values are truncated at 8-bits each and put into a byte array.
+LuaString
wrapping a copy of the byte buffer+public static LuaString valueOf(byte[] bytes)+
LuaString
around a byte array without copying the contents.
+ + The array is used directly after this is called, so clients must not change contents. +
+
+
bytes
- byte buffer
+LuaString
wrapping the byte buffer+public boolean isstring()+
LuaValue
this
is a string
++
isstring
in class LuaValue
string
,
+ meaning derives from LuaString
or LuaNumber
,
+ otherwise falseLuaValue.tostring()
,
+LuaValue.checkstring()
,
+LuaValue.optstring(LuaString)
,
+LuaValue.TSTRING
+public LuaValue getmetatable()+
LuaValue
LuaValue
+
+ For LuaTable
and LuaUserdata
instances,
+ the metatable returned is this instance metatable.
+ For all other types, the class metatable value will be returned.
+
+
getmetatable
in class LuaValue
LuaBoolean.s_metatable
,
+LuaNumber.s_metatable
,
+LuaNil.s_metatable
,
+LuaFunction.s_metatable
,
+LuaThread.s_metatable
+public int type()+
LuaValue
+
type
in class LuaValue
TNIL
,
+ TBOOLEAN
,
+ TNUMBER
,
+ TSTRING
,
+ TTABLE
,
+ TFUNCTION
,
+ TUSERDATA
,
+ TTHREAD
LuaValue.typename()
+public java.lang.String typename()+
LuaValue
+
+
typename
in class LuaValue
LuaValue.TYPE_NAMES
+ corresponding to the type of this value:
+ "nil", "boolean", "number", "string",
+ "table", "function", "userdata", "thread"LuaValue.type()
+public java.lang.String tojstring()+
LuaValue
+
tojstring
in class LuaValue
LuaValue.tostring()
,
+LuaValue.optjstring(String)
,
+LuaValue.checkjstring()
,
+LuaValue.isstring()
,
+TSTRING
+public LuaValue get(LuaValue key)+
LuaValue
INDEX
.
++
get
in class LuaValue
key
- the key to look up, must not be NIL
or null
+LuaValue
for that key, or NIL
if not found and no metatagLuaValue.get(int)
,
+LuaValue.get(String)
,
+LuaValue.rawget(LuaValue)
+public LuaValue neg()+
LuaValue
(-this)
as defined by lua unary minus operator
++
neg
in class LuaValue
LuaBoolean
if boolean or nil,
+ numeric inverse as if numeric,
+ or metatag processing result if UNM
metatag is defined+public LuaValue add(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
add
in class LuaValue
rhs
- The right-hand-side value to perform the add with
+(this + rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue add(double rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
add
in class LuaValue
rhs
- The right-hand-side value to perform the add with
+(this + rhs)
if this is numericLuaValue.add(LuaValue)
+public LuaValue add(int rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
add
in class LuaValue
rhs
- The right-hand-side value to perform the add with
+(this + rhs)
if this is numericLuaValue.add(LuaValue)
+public LuaValue sub(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
sub
in class LuaValue
rhs
- The right-hand-side value to perform the subtract with
+(this - rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue sub(double rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
sub
in class LuaValue
rhs
- The right-hand-side value to perform the subtract with
+(this - rhs)
if this is numericLuaValue.sub(LuaValue)
+public LuaValue sub(int rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
sub
in class LuaValue
rhs
- The right-hand-side value to perform the subtract with
+(this - rhs)
if this is numericLuaValue.sub(LuaValue)
+public LuaValue subFrom(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
subFrom
in class LuaValue
lhs
- The left-hand-side value from which to perform the subtraction
+(lhs - this)
if this is numericLuaValue.sub(LuaValue)
,
+LuaValue.sub(double)
,
+LuaValue.sub(int)
+public LuaValue mul(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
mul
in class LuaValue
rhs
- The right-hand-side value to perform the multiply with
+(this * rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue mul(double rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
mul
in class LuaValue
rhs
- The right-hand-side value to perform the multiply with
+(this * rhs)
if this is numericLuaValue.mul(LuaValue)
+public LuaValue mul(int rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
mul
in class LuaValue
rhs
- The right-hand-side value to perform the multiply with
+(this * rhs)
if this is numericLuaValue.mul(LuaValue)
+public LuaValue pow(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
pow
in class LuaValue
rhs
- The power to raise this value to
+(this ^ rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue pow(double rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
pow
in class LuaValue
rhs
- The power to raise this value to
+(this ^ rhs)
if this is numericLuaValue.pow(LuaValue)
+public LuaValue pow(int rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
pow
in class LuaValue
rhs
- The power to raise this value to
+(this ^ rhs)
if this is numericLuaValue.pow(LuaValue)
+public LuaValue powWith(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
powWith
in class LuaValue
lhs
- The left-hand-side value which will be raised to this power
+(lhs ^ this)
if this is numericLuaValue.pow(LuaValue)
,
+LuaValue.pow(double)
,
+LuaValue.pow(int)
+public LuaValue powWith(int lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
powWith
in class LuaValue
lhs
- The left-hand-side value which will be raised to this power
+(lhs ^ this)
if this is numericLuaValue.pow(LuaValue)
,
+LuaValue.pow(double)
,
+LuaValue.pow(int)
+public LuaValue div(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
div
in class LuaValue
rhs
- The right-hand-side value to perform the divulo with
+(this / rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue div(double rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing LuaValue.div(LuaValue)
must be used
+
+
div
in class LuaValue
rhs
- The right-hand-side value to perform the divulo with
+(this / rhs)
if this is numericLuaValue.div(LuaValue)
+public LuaValue div(int rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing LuaValue.div(LuaValue)
must be used
+
+
div
in class LuaValue
rhs
- The right-hand-side value to perform the divulo with
+(this / rhs)
if this is numericLuaValue.div(LuaValue)
+public LuaValue divInto(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
divInto
in class LuaValue
lhs
- The left-hand-side value which will be divided by this
+(lhs / this)
if this is numericLuaValue.div(LuaValue)
,
+LuaValue.div(double)
,
+LuaValue.div(int)
+public LuaValue mod(LuaValue rhs)+
LuaValue
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
mod
in class LuaValue
rhs
- The right-hand-side value to perform the modulo with
+(this % rhs)
if both are numeric,
+ or LuaValue
if metatag processing occursLuaValue.arithmt(LuaValue, LuaValue)
+public LuaValue mod(double rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing LuaValue.mod(LuaValue)
must be used
+
+
mod
in class LuaValue
rhs
- The right-hand-side value to perform the modulo with
+(this % rhs)
if this is numericLuaValue.mod(LuaValue)
+public LuaValue mod(int rhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing LuaValue.mod(LuaValue)
must be used
+
+
mod
in class LuaValue
rhs
- The right-hand-side value to perform the modulo with
+(this % rhs)
if this is numericLuaValue.mod(LuaValue)
+public LuaValue modFrom(double lhs)+
LuaValue
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
modFrom
in class LuaValue
lhs
- The left-hand-side value which will be modulo'ed by this
+(lhs % this)
if this is numericLuaValue.mod(LuaValue)
,
+LuaValue.mod(double)
,
+LuaValue.mod(int)
+public LuaValue lt(LuaValue rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lt
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this < rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lt_b(LuaValue rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this < rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lt_b(int rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
lt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this < rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lt_b(double rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this < rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue lteq(LuaValue rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lteq
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this <= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lteq_b(LuaValue rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
lteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this <= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lteq_b(int rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
lteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this <= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean lteq_b(double rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
lteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this <= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(double)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue gt(LuaValue rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gt
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this > rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gt_b(LuaValue rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this > rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gt_b(int rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
gt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this > rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gt_b(double rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gt_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this > rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue gteq(LuaValue rhs)+
LuaValue
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gteq
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this >= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occursLuaValue.gteq_b(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gteq_b(LuaValue rhs)+
LuaValue
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
gteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this >= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(LuaValue)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gteq_b(int rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
gteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this >= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(int)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public boolean gteq_b(double rhs)+
LuaValue
+ To be comparable, this must derive from LuaNumber
.
+
+
gteq_b
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with
+(this >= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.LuaValue.gteq(double)
,
+LuaValue.comparemt(LuaValue, LuaValue)
+public LuaValue concat(LuaValue rhs)+
LuaValue
+ Only strings and numbers as represented can be concatenated, meaning
+ each operand must derive from LuaString
or LuaNumber
.
+
+
concat
in class LuaValue
rhs
- The right-hand-side value to perform the operation with+public Buffer concat(Buffer rhs)+
LuaValue
Buffer
onto this value and return the result
+ using rules of lua string concatenation including metatag processing.
+
+ Only strings and numbers as represented can be concatenated, meaning
+ each operand must derive from LuaString
or LuaNumber
.
+
+
concat
in class LuaValue
rhs
- The right-hand-side Buffer
to perform the operation with
+(this .. rhs)
+public LuaValue concatTo(LuaNumber lhs)+
LuaValue
LuaNumber
+ and return the result using rules of lua string concatenation including
+ metatag processing.
+
+ Only strings and numbers as represented can be concatenated, meaning
+ each operand must derive from LuaString
or LuaNumber
.
+
+
concatTo
in class LuaValue
lhs
- The left-hand-side value onto which this will be concatenatedLuaValue.concat(LuaValue)
+public LuaValue concatTo(LuaString lhs)+
LuaValue
LuaString
+ and return the result using rules of lua string concatenation including
+ metatag processing.
+
+ Only strings and numbers as represented can be concatenated, meaning
+ each operand must derive from LuaString
or LuaNumber
.
+
+
concatTo
in class LuaValue
lhs
- The left-hand-side value onto which this will be concatenatedLuaValue.concat(LuaValue)
+public int strcmp(LuaValue lhs)+
LuaValue
+ Only strings can be compared, meaning
+ each operand must derive from LuaString
.
+
+
strcmp
in class LuaValue
lhs
- The right-hand-side value to perform the comparison with+public int strcmp(LuaString rhs)+
LuaValue
LuaString
+ using string comparison based on byte values.
+
+ Only strings can be compared, meaning
+ each operand must derive from LuaString
.
+
+
strcmp
in class LuaValue
rhs
- The right-hand-side value to perform the comparison with+public int checkint()+
LuaValue
LuaError
if not numeric
+
+ Values that are LuaNumber
will be cast to int and may lose precision.
+ Values that are LuaString
that can be converted to a number will be converted,
+ then cast to int, so may also lose precision.
+
+
checkint
in class LuaValue
LuaValue.checkinteger()
,
+LuaValue.checklong()
,
+LuaValue.checkdouble()
,
+LuaValue.optint(int)
,
+LuaValue.TNUMBER
+public LuaInteger checkinteger()+
LuaValue
LuaError
if not numeric
+
+ Values that are LuaNumber
will be cast to int and may lose precision.
+ Values that are LuaString
that can be converted to a number will be converted,
+ then cast to int, so may also lose precision.
+
+
checkinteger
in class LuaValue
LuaInteger
if numericLuaValue.checkint()
,
+LuaValue.checklong()
,
+LuaValue.checkdouble()
,
+LuaValue.optinteger(LuaInteger)
,
+LuaValue.TNUMBER
+public long checklong()+
LuaValue
LuaError
if not numeric
+
+ Values that are LuaNumber
will be cast to long and may lose precision.
+ Values that are LuaString
that can be converted to a number will be converted,
+ then cast to long, so may also lose precision.
+
+
checklong
in class LuaValue
LuaValue.checkint()
,
+LuaValue.checkinteger()
,
+LuaValue.checkdouble()
,
+LuaValue.optlong(long)
,
+LuaValue.TNUMBER
+public double checkdouble()+
LuaValue
LuaError
if not numeric
+
+ Values that are LuaNumber
and values that are LuaString
+ that can be converted to a number will be converted to double.
+
+
checkdouble
in class LuaValue
LuaValue.checkint()
,
+LuaValue.checkinteger()
,
+LuaValue.checklong()
,
+LuaValue.optdouble(double)
,
+LuaValue.TNUMBER
+public LuaNumber checknumber()+
LuaValue
LuaError
+
+ Values that are LuaString
that can be converted to a number will be converted and returned.
+
+
checknumber
in class LuaValue
LuaNumber
if numericLuaValue.checkint()
,
+LuaValue.checkinteger()
,
+LuaValue.checkdouble()
,
+LuaValue.checklong()
,
+LuaValue.optnumber(LuaNumber)
,
+LuaValue.TNUMBER
+public LuaNumber checknumber(java.lang.String msg)+
LuaValue
LuaError
+
+ Values that are LuaString
that can be converted to a number will be converted and returned.
+
+
checknumber
in class LuaValue
msg
- String message to supply if conversion fails
+LuaNumber
if numericLuaValue.checkint()
,
+LuaValue.checkinteger()
,
+LuaValue.checkdouble()
,
+LuaValue.checklong()
,
+LuaValue.optnumber(LuaNumber)
,
+LuaValue.TNUMBER
+public LuaValue tonumber()+
LuaValue
+ In lua all numbers are strings, but not all strings are numbers.
+ This function will return
+ the LuaValue
this
if it is a number
+ or a string convertible to a number,
+ and NIL
for all other cases.
+
+ This allows values to be tested for their "numeric-ness" without + the penalty of throwing exceptions, + nor the cost of converting the type and creating storage for it. +
+
tonumber
in class LuaValue
this
if it is a LuaNumber
+ or LuaString
that can be converted to a number,
+ otherwise LuaValue.NIL
LuaValue.tostring()
,
+LuaValue.optnumber(LuaNumber)
,
+LuaValue.checknumber()
,
+LuaValue.toint()
,
+LuaValue.todouble()
+public boolean isnumber()+
LuaValue
this
is a number
++
isnumber
in class LuaValue
number
,
+ meaning derives from LuaNumber
+ or derives from LuaString
and is convertible to a number,
+ otherwise falseLuaValue.tonumber()
,
+LuaValue.checknumber()
,
+LuaValue.optnumber(LuaNumber)
,
+LuaValue.TNUMBER
+public boolean isint()+
LuaValue
this
is a number
and is representable by java int
+ without rounding or truncation
++
isint
in class LuaValue
number
+ meaning derives from LuaNumber
+ or derives from LuaString
and is convertible to a number,
+ and can be represented by int,
+ otherwise falseLuaValue.isinttype()
,
+LuaValue.islong()
,
+LuaValue.tonumber()
,
+LuaValue.checkint()
,
+LuaValue.optint(int)
,
+LuaValue.TNUMBER
+public boolean islong()+
LuaValue
this
is a number
and is representable by java long
+ without rounding or truncation
++
islong
in class LuaValue
number
+ meaning derives from LuaNumber
+ or derives from LuaString
and is convertible to a number,
+ and can be represented by long,
+ otherwise falseLuaValue.tonumber()
,
+LuaValue.checklong()
,
+LuaValue.optlong(long)
,
+LuaValue.TNUMBER
+public byte tobyte()+
LuaValue
+
tobyte
in class LuaValue
LuaValue.toint()
,
+LuaValue.todouble()
,
+#optbyte(byte)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public char tochar()+
LuaValue
+
tochar
in class LuaValue
LuaValue.toint()
,
+LuaValue.todouble()
,
+#optchar(char)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public double todouble()+
LuaValue
+
todouble
in class LuaValue
LuaValue.toint()
,
+LuaValue.tobyte()
,
+LuaValue.tochar()
,
+LuaValue.toshort()
,
+LuaValue.tolong()
,
+LuaValue.tofloat()
,
+LuaValue.optdouble(double)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public float tofloat()+
LuaValue
+
tofloat
in class LuaValue
LuaValue.toint()
,
+LuaValue.todouble()
,
+#optfloat(float)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public int toint()+
LuaValue
+
toint
in class LuaValue
LuaValue.tobyte()
,
+LuaValue.tochar()
,
+LuaValue.toshort()
,
+LuaValue.tolong()
,
+LuaValue.tofloat()
,
+LuaValue.todouble()
,
+LuaValue.optint(int)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public long tolong()+
LuaValue
+
tolong
in class LuaValue
LuaValue.isint()
,
+LuaValue.isinttype()
,
+LuaValue.toint()
,
+LuaValue.todouble()
,
+LuaValue.optlong(long)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public short toshort()+
LuaValue
+
toshort
in class LuaValue
LuaValue.toint()
,
+LuaValue.todouble()
,
+#optshort(short)
,
+LuaValue.checknumber()
,
+LuaValue.isnumber()
,
+TNUMBER
+public double optdouble(double defval)+
LuaValue
+
optdouble
in class LuaValue
defval
- double to return if this
is nil or none
+this
cast to double if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optint(int)
,
+LuaValue.optinteger(LuaInteger)
,
+LuaValue.checkdouble()
,
+LuaValue.todouble()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public int optint(int defval)+
LuaValue
+
optint
in class LuaValue
defval
- int to return if this
is nil or none
+this
cast to int if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optlong(long)
,
+LuaValue.optinteger(LuaInteger)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public LuaInteger optinteger(LuaInteger defval)+
LuaValue
LuaInteger
++
optinteger
in class LuaValue
defval
- LuaInteger
to return if this
is nil or none
+this
converted and wrapped in LuaInteger
if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optint(int)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public long optlong(long defval)+
LuaValue
+
optlong
in class LuaValue
defval
- long to return if this
is nil or none
+this
cast to long if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optint(int)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public LuaNumber optnumber(LuaNumber defval)+
LuaValue
LuaNumber
++
optnumber
in class LuaValue
defval
- LuaNumber
to return if this
is nil or none
+this
cast to LuaNumber
if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwiseLuaValue.optdouble(double)
,
+LuaValue.optlong(long)
,
+LuaValue.optint(int)
,
+LuaValue.checkint()
,
+LuaValue.toint()
,
+LuaValue.tonumber()
,
+LuaValue.isnumber()
,
+LuaValue.TNUMBER
+public LuaString optstring(LuaString defval)+
LuaValue
LuaString
++
optstring
in class LuaValue
defval
- LuaString
to return if this
is nil or none
+this
converted to LuaString
if a string or number,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.tojstring()
,
+LuaValue.optjstring(String)
,
+LuaValue.checkstring()
,
+LuaValue.toString()
,
+LuaValue.TSTRING
+public LuaValue tostring()+
LuaValue
+ In lua all numbers are strings, so this function will return
+ the LuaValue
this
if it is a string or number,
+ and NIL
for all other cases.
+
+ This allows values to be tested for their "string-ness" without + the penalty of throwing exceptions. +
+
tostring
in class LuaValue
this
if it is a LuaString
or LuaNumber
,
+ otherwise NIL
LuaValue.tonumber()
,
+LuaValue.tojstring()
,
+LuaValue.optstring(LuaString)
,
+LuaValue.checkstring()
,
+LuaValue.toString()
+public java.lang.String optjstring(java.lang.String defval)+
LuaValue
+
optjstring
in class LuaValue
defval
- LuaString
to return if this
is nil or none
+this
converted to String if a string or number,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.tojstring()
,
+LuaValue.optstring(LuaString)
,
+LuaValue.checkjstring()
,
+LuaValue.toString()
,
+LuaValue.TSTRING
+public LuaString strvalue()+
LuaValue
LuaString
or LuaNumber
,
+ or throw a LuaError
if it is not
++
strvalue
in class LuaValue
LuaString
corresponding to the value if a string or number+public LuaString substring(int beginIndex, + int endIndex)+
+public int hashCode()+
hashCode
in class java.lang.Object
+public boolean equals(java.lang.Object o)+
equals
in class LuaValue
+public LuaValue eq(LuaValue val)+
LuaValue
EQ
.
++
eq
in class LuaValue
val
- The value to compare with.
+TRUE
if values are comparable and (this == rhs)
,
+ FALSE
if comparable but not equal,
+ LuaValue
if metatag processing occurs.LuaValue.eq_b(LuaValue)
,
+LuaValue.raweq(LuaValue)
,
+LuaValue.neq(LuaValue)
,
+LuaValue.eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
,
+LuaValue.EQ
+public boolean eq_b(LuaValue val)+
LuaValue
EQ
,
+ and return java boolean
++
eq_b
in class LuaValue
val
- The value to compare with.
+(this == rhs)
,
+ false if comparable but not equal,
+ result converted to java boolean if metatag processing occurs.LuaValue.eq(LuaValue)
,
+LuaValue.raweq(LuaValue)
,
+LuaValue.neq_b(LuaValue)
,
+LuaValue.eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
,
+LuaValue.EQ
+public boolean raweq(LuaValue val)+
LuaValue
+
raweq
in class LuaValue
val
- The value to compare with.
+(this == rhs)
, false otherwiseLuaValue.eq(LuaValue)
,
+LuaValue.raweq(LuaUserdata)
,
+LuaValue.raweq(LuaString)
,
+LuaValue.raweq(double)
,
+LuaValue.raweq(int)
,
+LuaValue.EQ
+public boolean raweq(LuaString s)+
LuaValue
LuaString
value
+ without metatag processing.
++
raweq
in class LuaValue
s
- The LuaString
to compare with.
+this
is a LuaString
+ and their byte sequences match,
+ otherwise false+public static boolean equals(LuaString a, + int i, + LuaString b, + int j, + int n)+
+public static boolean equals(byte[] a, + int i, + byte[] b, + int j, + int n)+
+public void write(java.io.DataOutputStream writer, + int i, + int len) + throws java.io.IOException+
java.io.IOException
+public LuaValue len()+
LuaValue
(#this)
including metatag processing as java int
++
len
in class LuaValue
+public int length()+
LuaValue
(#this)
including metatag processing as java int
++
length
in class LuaValue
LuaValue.toint()
+public int luaByte(int index)+
+public int charAt(int index)+
+public java.lang.String checkjstring()+
LuaValue
+ The string representations here will roughly match what is produced by the + C lua distribution, however hash codes have no relationship, + and there may be differences in number formatting. +
+
checkjstring
in class LuaValue
LuaValue.checkstring()
,
+LuaValue.optjstring(String)
,
+LuaValue.tojstring()
,
+LuaValue.isstring()
,
+LuaValue.TSTRING
+public LuaString checkstring()+
LuaValue
LuaError
if it is not.
+
+ In lua all numbers are strings, so this will succeed for
+ anything that derives from LuaString
or LuaNumber
.
+ Numbers will be converted to LuaString
.
+
+
checkstring
in class LuaValue
LuaString
representation of the value if it is a LuaString
or LuaNumber
LuaValue.checkjstring()
,
+LuaValue.optstring(LuaString)
,
+LuaValue.tostring()
,
+LuaValue.isstring()
,
+LuaValue.TSTRING
+public java.io.InputStream toInputStream()+
+
InputStream
whose data matches the bytes in this LuaString
+public void copyInto(int strOffset, + byte[] bytes, + int arrayOffset, + int len)+
+
strOffset
- offset from which to copybytes
- destination byte arrayarrayOffset
- offset in destinationlen
- number of bytes to copy+public int indexOfAny(LuaString accept)+
+
accept
- LuaString
containing characters to look for.
+accept
string, or -1 if not found.+public int indexOf(byte b, + int start)+
+
b
- the byte to look forstart
- the first index in the string
++public int indexOf(LuaString s, + int start)+
+
s
- the string to search forstart
- the first index in the string
++public int lastIndexOf(LuaString s)+
+
s
- the string to search for
++public static java.lang.String decodeAsUtf8(byte[] bytes, + int offset, + int length)+
+
bytes
- byte array in UTF8 encoding to convertoffset
- starting index in byte arraylength
- number of bytes to convert
+lengthAsUtf8(char[])
,
+encodeToUtf8(char[], byte[], int)
,
+isValidUtf8()
+public static int lengthAsUtf8(char[] chars)+
+
chars
- Array of unicode characters to be encoded as UTF-8
+encodeToUtf8(char[], byte[], int)
,
+decodeAsUtf8(byte[], int, int)
,
+isValidUtf8()
+public static void encodeToUtf8(char[] chars, + byte[] bytes, + int off)+
+ The string should be measured first with lengthAsUtf8 + to make sure the given byte array is large enough. +
+
chars
- Array of unicode characters to be encoded as UTF-8bytes
- byte array to hold the resultoff
- offset into the byte array to start writinglengthAsUtf8(char[])
,
+decodeAsUtf8(byte[], int, int)
,
+isValidUtf8()
+public boolean isValidUtf8()+
+
lengthAsUtf8(char[])
,
+encodeToUtf8(char[], byte[], int)
,
+decodeAsUtf8(byte[], int, int)
+public LuaValue tonumber(int base)+
+
base
- the base to use, such as 10
+LuaValue.tonumber()
+public double scannumber(int base)+
+
base
- the base to use, such as 10
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaTable ++
public class LuaTable
+Subclass of LuaValue
for representing lua tables.
+
+ Almost all API's implemented in LuaTable
are defined and documented in LuaValue
.
+
+ If a table is needed, the one of the type-checking functions can be used such as
+ istable()
,
+ checktable()
, or
+ opttable(LuaTable)
+
+ The main table operations are defined on LuaValue
+ for getting and setting values with and without metatag processing:
+
get(LuaValue)
set(LuaValue,LuaValue)
rawget(LuaValue)
rawset(LuaValue,LuaValue)
LuaValue.get(String)
, get(int)
, and so on+ To iterate over key-value pairs from Java, use +
LuaValue k = LuaValue.NIL;
+ while ( true ) {
+ Varargs n = table.next(k);
+ if ( (k = n.arg1()).isnil() )
+ break;
+ LuaValue v = n.arg(2)
+ process( k, v )
+ }
+
+
+ As with other types, LuaTable
instances should be constructed via one of the table constructor
+ methods on LuaValue
:
+
LuaValue.tableOf()
empty tableLuaValue.tableOf(int, int)
table with capacityLuaValue.listOf(LuaValue[])
initialize array partLuaValue.listOf(LuaValue[], Varargs)
initialize array partLuaValue.tableOf(LuaValue[])
initialize named hash partLuaValue.tableOf(Varargs, int)
initialize named hash partLuaValue.tableOf(LuaValue[], LuaValue[])
initialize array and named partsLuaValue.tableOf(LuaValue[], LuaValue[], Varargs)
initialize array and named parts+ +
+
LuaValue
+Field Summary | +|
---|---|
+protected LuaValue[] |
+array
+
++ the array values |
+
+protected int |
+hashEntries
+
++ the number of hash entries |
+
+protected LuaValue[] |
+hashKeys
+
++ the hash keys |
+
+protected LuaValue[] |
+hashValues
+
++ the hash values |
+
+protected LuaValue |
+m_metatable
+
++ metatable for this table, or null |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
LuaTable()
+
++ Construct empty table |
+|
LuaTable(int narray,
+ int nhash)
+
++ Construct table with preset capacity. |
+|
LuaTable(LuaValue[] named,
+ LuaValue[] unnamed,
+ Varargs lastarg)
+
++ Construct table with named and unnamed parts. |
+|
LuaTable(Varargs varargs)
+
++ Construct table of unnamed elements. |
+|
LuaTable(Varargs varargs,
+ int firstarg)
+
++ Construct table of unnamed elements. |
+
+Method Summary | +|
---|---|
+protected LuaTable |
+changemode(boolean weakkeys,
+ boolean weakvalues)
+
++ Change the mode of a table |
+
+ LuaTable |
+checktable()
+
++ Check that this is a LuaTable , or throw LuaError if it is not |
+
+ LuaValue |
+concat(LuaString sep,
+ int i,
+ int j)
+
++ Concatenate the contents of a table efficiently, using Buffer |
+
+ boolean |
+eq_b(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ ,
+ and return java boolean |
+
+ LuaValue |
+eq(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ . |
+
+ LuaValue |
+foreach(LuaValue func)
+
++ Call the supplied function once for each key-value pair |
+
+ LuaValue |
+foreachi(LuaValue func)
+
++ Call the supplied function once for each key-value pair + in the contiguous array part |
+
+ LuaValue |
+get(int key)
+
++ Get a value in a table including metatag processing using INDEX . |
+
+ LuaValue |
+get(LuaValue key)
+
++ Get a value in a table including metatag processing using INDEX . |
+
+protected int |
+getArrayLength()
+
++ Get the length of the array part of the table. |
+
+protected int |
+getHashLength()
+
++ Get the length of the hash part of the table. |
+
+ LuaValue |
+getmetatable()
+
++ Get the metatable for this LuaValue |
+
+ LuaValue |
+getn()
+
++ Implementation of lua 5.0 getn() function. |
+
+protected void |
+hashClearSlot(int i)
+
++ Clear a particular slot in the table |
+
+ int |
+hashFindSlot(LuaValue key)
+
++ Find the hashtable slot to use |
+
+protected LuaValue |
+hashget(LuaValue key)
+
++ |
+
+ void |
+hashset(LuaValue key,
+ LuaValue value)
+
++ Set a hashtable value |
+
+ Varargs |
+inext(LuaValue key)
+
++ Get the next element after a particular key in the + contiguous array part of a table |
+
+ void |
+insert(int pos,
+ LuaValue value)
+
++ Insert an element at a position in a list-table |
+
+ boolean |
+istable()
+
++ Check if this is a table |
+
+ int |
+keyCount()
+
++ This may be deprecated in a future release. |
+
+ LuaValue[] |
+keys()
+
++ This may be deprecated in a future release. |
+
+ LuaValue |
+len()
+
++ Length operator: return lua length of object (#this) including metatag processing as java int |
+
+ int |
+length()
+
++ Length operator: return lua length of object (#this) including metatag processing as java int |
+
+ int |
+maxn()
+
++ Return table.maxn() as defined by lua 5.0. |
+
+ Varargs |
+next(LuaValue key)
+
++ Get the next element after a particular key in the table |
+
+ LuaTable |
+opttable(LuaTable defval)
+
++ Check that optional argument is a table and return as LuaTable |
+
+ void |
+presize(int narray)
+
++ Preallocate the array part of a table to be a certain size, |
+
+ void |
+presize(int narray,
+ int nhash)
+
++ |
+
+ LuaValue |
+rawget(int key)
+
++ Get a value in a table without metatag processing. |
+
+ LuaValue |
+rawget(LuaValue key)
+
++ Get a value in a table without metatag processing. |
+
+ void |
+rawset(int key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing. |
+
+ void |
+rawset(LuaValue key,
+ LuaValue value)
+
++ caller must ensure key is not nil |
+
+ LuaValue |
+remove(int pos)
+
++ Remove the element at a position in a list-table |
+
+ void |
+set(int key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing using NEWINDEX . |
+
+ void |
+set(LuaValue key,
+ LuaValue value)
+
++ caller must ensure key is not nil |
+
+ LuaValue |
+setmetatable(LuaValue metatable)
+
++ Set the metatable for this LuaValue |
+
+ void |
+sort(LuaValue comparator)
+
++ Sort the table using a comparator. |
+
+ int |
+type()
+
++ Get the enumeration value for the type of this value. |
+
+ java.lang.String |
+typename()
+
++ Get the String name of the type of this value. |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+protected LuaValue[] array+
+
+protected LuaValue[] hashKeys+
+
+protected LuaValue[] hashValues+
+
+protected int hashEntries+
+
+protected LuaValue m_metatable+
+
+Constructor Detail | +
---|
+public LuaTable()+
+
+public LuaTable(int narray, + int nhash)+
+
narray
- capacity of array partnhash
- capacity of hash part+public LuaTable(LuaValue[] named, + LuaValue[] unnamed, + Varargs lastarg)+
+
named
- Named elements in order key-a, value-a, key-b, value-b, ...
unnamed
- Unnamed elements in order value-1, value-2, ...
lastarg
- Additional unnamed values beyond unnamed.length
+public LuaTable(Varargs varargs)+
+
varargs
- Unnamed elements in order value-1, value-2, ...
+public LuaTable(Varargs varargs, + int firstarg)+
+
varargs
- Unnamed elements in order value-1, value-2, ...
firstarg
- the index in varargs of the first argument to include in the table+Method Detail | +
---|
+public int type()+
LuaValue
+
type
in class LuaValue
TNIL
,
+ TBOOLEAN
,
+ TNUMBER
,
+ TSTRING
,
+ TTABLE
,
+ TFUNCTION
,
+ TUSERDATA
,
+ TTHREAD
LuaValue.typename()
+public java.lang.String typename()+
LuaValue
+
+
typename
in class LuaValue
LuaValue.TYPE_NAMES
+ corresponding to the type of this value:
+ "nil", "boolean", "number", "string",
+ "table", "function", "userdata", "thread"LuaValue.type()
+public boolean istable()+
LuaValue
this
is a table
++
istable
in class LuaValue
table
, otherwise falseLuaValue.checktable()
,
+LuaValue.opttable(LuaTable)
,
+LuaValue.TTABLE
+public LuaTable checktable()+
LuaValue
LuaTable
, or throw LuaError
if it is not
++
checktable
in class LuaValue
this
if it is a LuaTable
LuaValue.istable()
,
+LuaValue.opttable(LuaTable)
,
+LuaValue.TTABLE
+public LuaTable opttable(LuaTable defval)+
LuaValue
LuaTable
++
opttable
in class LuaValue
defval
- LuaTable
to return if this
is nil or none
+this
cast to LuaTable
if a table,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.checktable()
,
+LuaValue.istable()
,
+LuaValue.TTABLE
+public void presize(int narray)+
LuaValue
+ Primarily used internally in response to a SETLIST bytecode. +
+
presize
in class LuaValue
narray
- the number of array slots to preallocate in the table.+public void presize(int narray, + int nhash)+
+protected int getArrayLength()+
+
+protected int getHashLength()+
+
+public LuaValue getmetatable()+
LuaValue
LuaValue
+
+ For LuaTable
and LuaUserdata
instances,
+ the metatable returned is this instance metatable.
+ For all other types, the class metatable value will be returned.
+
+
getmetatable
in class LuaValue
LuaBoolean.s_metatable
,
+LuaNumber.s_metatable
,
+LuaNil.s_metatable
,
+LuaFunction.s_metatable
,
+LuaThread.s_metatable
+public LuaValue setmetatable(LuaValue metatable)+
LuaValue
LuaValue
+
+ For LuaTable
and LuaUserdata
instances, the metatable is per instance.
+ For all other types, there is one metatable per type that can be set directly from java
+
+
setmetatable
in class LuaValue
metatable
- LuaValue
instance to serve as the metatable, or null to reset it.
+this
to allow chaining of Java function callsLuaBoolean.s_metatable
,
+LuaNumber.s_metatable
,
+LuaNil.s_metatable
,
+LuaFunction.s_metatable
,
+LuaThread.s_metatable
+protected LuaTable changemode(boolean weakkeys, + boolean weakvalues)+
+
weakkeys
- true to make the table have weak keys going forwardweakvalues
- true to make the table have weak values going forward
+this
or a new WeakTable
if the mode change requires copying.+public LuaValue get(int key)+
LuaValue
INDEX
.
++
get
in class LuaValue
key
- the key to look up
+LuaValue
for that key, or NIL
if not foundLuaValue.get(LuaValue)
,
+LuaValue.rawget(int)
+public LuaValue get(LuaValue key)+
LuaValue
INDEX
.
++
get
in class LuaValue
key
- the key to look up, must not be NIL
or null
+LuaValue
for that key, or NIL
if not found and no metatagLuaValue.get(int)
,
+LuaValue.get(String)
,
+LuaValue.rawget(LuaValue)
+public LuaValue rawget(int key)+
LuaValue
+
rawget
in class LuaValue
key
- the key to look up
+LuaValue
for that key, or NIL
if not found+public LuaValue rawget(LuaValue key)+
LuaValue
+
rawget
in class LuaValue
key
- the key to look up, must not be NIL
or null
+LuaValue
for that key, or NIL
if not found+protected LuaValue hashget(LuaValue key)+
+public void set(int key, + LuaValue value)+
LuaValue
NEWINDEX
.
++
set
in class LuaValue
key
- the key to usevalue
- the value to use, can be NIL
, must not be null+public void set(LuaValue key, + LuaValue value)+
+
set
in class LuaValue
key
- the key to use, must not be NIL
or nullvalue
- the value to use, can be NIL
, must not be null+public void rawset(int key, + LuaValue value)+
LuaValue
+
rawset
in class LuaValue
key
- the key to usevalue
- the value to use, can be NIL
, must not be null+public void rawset(LuaValue key, + LuaValue value)+
+
rawset
in class LuaValue
key
- the key to use, must not be NIL
or nullvalue
- the value to use, can be NIL
, must not be null+public LuaValue remove(int pos)+
+
pos
- the position to remove
+LuaValue.NONE
if not removed+public void insert(int pos, + LuaValue value)+
+
pos
- the position to removevalue
- The value to insert+public LuaValue concat(LuaString sep, + int i, + int j)+
Buffer
++
sep
- LuaString
separater to apply between elementsi
- the first element indexj
- the last element index, inclusive
+LuaString
value of the concatenation+public LuaValue getn()+
LuaValue
+
getn
in class LuaValue
this
is a LuaTable
+public int length()+
LuaValue
(#this)
including metatag processing as java int
++
length
in class LuaValue
LuaValue.toint()
+public LuaValue len()+
LuaValue
(#this)
including metatag processing as java int
++
len
in class LuaValue
+public int maxn()+
+ Provided for compatibility, not a scalable operation. +
+
+public Varargs next(LuaValue key)+
+
next
in class LuaValue
key
- LuaInteger
value identifying a key to start from,
+ or NIL
to start at the beginning
+LuaTable
,
+#inext()
,
+LuaValue.valueOf(int)
,
+Varargs.arg1()
,
+Varargs.arg(int)
,
+LuaValue.isnil()
+public Varargs inext(LuaValue key)+
+
inext
in class LuaValue
key
- LuaInteger
value identifying a key to start from,
+ or NIL
to start at the beginning
+LuaTable
,
+#next()
,
+LuaValue.valueOf(int)
,
+Varargs.arg1()
,
+Varargs.arg(int)
,
+LuaValue.isnil()
+public LuaValue foreach(LuaValue func)+
+
func
- function to call+public LuaValue foreachi(LuaValue func)+
+
func
- +public void hashset(LuaValue key, + LuaValue value)+
+
key
- key to setvalue
- value to set+public int hashFindSlot(LuaValue key)+
+
key
- key to look for
++protected void hashClearSlot(int i)+
+
i
- slot to clear.+public void sort(LuaValue comparator)+
+
comparator
- LuaValue
to be called to compare elements.+public int keyCount()+
+
+public LuaValue[] keys()+
+
+public LuaValue eq(LuaValue val)+
LuaValue
EQ
.
++
eq
in class LuaValue
val
- The value to compare with.
+TRUE
if values are comparable and (this == rhs)
,
+ FALSE
if comparable but not equal,
+ LuaValue
if metatag processing occurs.LuaValue.eq_b(LuaValue)
,
+LuaValue.raweq(LuaValue)
,
+LuaValue.neq(LuaValue)
,
+LuaValue.eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
,
+LuaValue.EQ
+public boolean eq_b(LuaValue val)+
LuaValue
EQ
,
+ and return java boolean
++
eq_b
in class LuaValue
val
- The value to compare with.
+(this == rhs)
,
+ false if comparable but not equal,
+ result converted to java boolean if metatag processing occurs.LuaValue.eq(LuaValue)
,
+LuaValue.raweq(LuaValue)
,
+LuaValue.neq_b(LuaValue)
,
+LuaValue.eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
,
+LuaValue.EQ
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.LuaThread.CallStack ++
public static class LuaThread.CallStack
+
+Constructor Summary | +|
---|---|
LuaThread.CallStack()
+
++ |
+
+Method Summary | +|
---|---|
+ int |
+getCallstackDepth()
+
++ Get number of calls in stack |
+
+ void |
+onReturn()
+
++ Method to signal the end of a call |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Constructor Detail | +
---|
+public LuaThread.CallStack()+
+Method Detail | +
---|
+public final void onReturn()+
+
DebugLib
+public final int getCallstackDepth()+
+
DebugLib
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaThread ++
public class LuaThread
+Subclass of LuaValue
that implements
+ a lua coroutine thread using Java Threads.
+
+ A LuaThread is typically created in response to a scripted call to
+ coroutine.create()
+
+ 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 a call to setGlobals(LuaValue)
+ at some point during globals initialization.
+ See BaseLib
for additional documentation and example code.
+
+ The utility classes JsePlatform
and JmePlatform
+ see to it that this initialization is done properly.
+ For this reason it is highly recommended to use one of these classes
+ when initializing globals.
+
+ 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. +
+ 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
+ OrphanedThread
which is an Error
.
+ Applications should not catch OrphanedThread
, because it can break
+ the thread safety of luaj.
+
+ +
+
LuaValue
,
+JsePlatform
,
+JmePlatform
,
+CoroutineLib
+Nested Class Summary | +|
---|---|
+static class |
+LuaThread.CallStack
+
++ |
+
+Field Summary | +|
---|---|
+static int |
+coroutine_count
+
++ |
+
+ java.lang.Object |
+debugState
+
++ Thread-local used by DebugLib to store debugging state. |
+
+ LuaValue |
+err
+
++ Field to hold state of error condition during debug hook function calls. |
+
+static int |
+GC_INTERVAL
+
++ Interval to check for LuaThread dereferencing. |
+
+static int |
+MAX_CALLSTACK
+
++ |
+
+static LuaValue |
+s_metatable
+
++ |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
LuaThread(LuaValue func,
+ LuaValue env)
+
++ Create a LuaThread around a function and environment |
+
+Method Summary | +|
---|---|
+ LuaThread |
+checkthread()
+
++ Check that this is a LuaThread , or throw LuaError if it is not |
+
+static LuaFunction |
+getCallstackFunction(int level)
+
++ Get the function called as a specific location on the stack. |
+
+ LuaValue |
+getfenv()
+
++ Get the environemnt for an instance. |
+
+static LuaValue |
+getGlobals()
+
++ Get the current thread's environment |
+
+ LuaValue |
+getmetatable()
+
++ Get the metatable for this LuaValue |
+
+static LuaThread |
+getRunning()
+
++ Get the currently running thread. |
+
+ java.lang.String |
+getStatus()
+
++ |
+
+static boolean |
+isMainThread(LuaThread r)
+
++ Test if this is the main thread |
+
+ boolean |
+isthread()
+
++ Check if this is a thread |
+
+static LuaThread.CallStack |
+onCall(LuaFunction function)
+
++ Callback used at the beginning of a call to prepare for possible getfenv/setfenv calls |
+
+ LuaThread |
+optthread(LuaThread defval)
+
++ Check that optional argument is a thread and return as LuaThread |
+
+ Varargs |
+resume(Varargs args)
+
++ Start or resume this thread |
+
+static LuaValue |
+setErrorFunc(LuaValue errfunc)
+
++ Replace the error function of the currently running thread. |
+
+ void |
+setfenv(LuaValue env)
+
++ Set the environment on an object. |
+
+static void |
+setGlobals(LuaValue globals)
+
++ Set the globals of the current thread. |
+
+ int |
+type()
+
++ Get the enumeration value for the type of this value. |
+
+ java.lang.String |
+typename()
+
++ Get the String name of the type of this value. |
+
+static Varargs |
+yield(Varargs args)
+
++ Yield the current thread with arguments |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static LuaValue s_metatable+
+public static int coroutine_count+
+public LuaValue err+
+
+public static final int MAX_CALLSTACK+
+public static int GC_INTERVAL+
+
+public java.lang.Object debugState+
+
+Constructor Detail | +
---|
+public LuaThread(LuaValue func, + LuaValue env)+
+
func
- The function to executeenv
- The environment to apply to the thread+Method Detail | +
---|
+public int type()+
LuaValue
+
type
in class LuaValue
TNIL
,
+ TBOOLEAN
,
+ TNUMBER
,
+ TSTRING
,
+ TTABLE
,
+ TFUNCTION
,
+ TUSERDATA
,
+ TTHREAD
LuaValue.typename()
+public java.lang.String typename()+
LuaValue
+
+
typename
in class LuaValue
LuaValue.TYPE_NAMES
+ corresponding to the type of this value:
+ "nil", "boolean", "number", "string",
+ "table", "function", "userdata", "thread"LuaValue.type()
+public boolean isthread()+
LuaValue
this
is a thread
++
isthread
in class LuaValue
thread
, otherwise falseLuaValue.checkthread()
,
+LuaValue.optthread(LuaThread)
,
+LuaValue.TTHREAD
+public LuaThread optthread(LuaThread defval)+
LuaValue
LuaThread
++
optthread
in class LuaValue
defval
- LuaThread
to return if this
is nil or none
+this
cast to LuaTable
if a thread,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.checkthread()
,
+LuaValue.isthread()
,
+LuaValue.TTHREAD
+public LuaThread checkthread()+
LuaValue
LuaThread
, or throw LuaError
if it is not
++
checkthread
in class LuaValue
this
if it is a LuaThread
LuaValue.isthread()
,
+LuaValue.optthread(LuaThread)
,
+LuaValue.TTHREAD
+public LuaValue getmetatable()+
LuaValue
LuaValue
+
+ For LuaTable
and LuaUserdata
instances,
+ the metatable returned is this instance metatable.
+ For all other types, the class metatable value will be returned.
+
+
getmetatable
in class LuaValue
LuaBoolean.s_metatable
,
+LuaNumber.s_metatable
,
+LuaNil.s_metatable
,
+LuaFunction.s_metatable
,
+s_metatable
+public LuaValue getfenv()+
LuaValue
+
getfenv
in class LuaValue
LuaValue
currently set as the instances environent.+public void setfenv(LuaValue env)+
LuaValue
+ Typically the environment is created once per application via a platform
+ helper method such as JsePlatform.standardGlobals()
+ However, any object can serve as an environment if it contains suitable metatag
+ values to implement LuaValue.get(LuaValue)
to provide the environment values.
+
+
setfenv
in class LuaValue
env
- LuaValue
(typically a LuaTable
) containing the environment.JmePlatform
,
+JsePlatform
+public java.lang.String getStatus()+
+public static LuaThread getRunning()+
+
LuaThread
that is currenly running+public static boolean isMainThread(LuaThread r)+
+
+public static void setGlobals(LuaValue globals)+
+ This must be done once before any other code executes. +
+
globals
- The global variables for the main ghread.+public static LuaValue getGlobals()+
+
LuaValue
containing the global variables of the current thread.+public static final LuaThread.CallStack onCall(LuaFunction function)+
+
function
- Function being called
+DebugLib
+public static final LuaFunction getCallstackFunction(int level)+
+
level
- 1 for the function calling this one, 2 for the next one.
++public static LuaValue setErrorFunc(LuaValue errfunc)+
+
errfunc
- the new error function to use.
++public static Varargs yield(Varargs args)+
+
args
- The arguments to send as return values to resume(Varargs)
+Varargs
provided as arguments to resume(Varargs)
+public Varargs resume(Varargs args)+
+
args
- The arguments to send as return values to yield(Varargs)
+Varargs
provided as arguments to yield(Varargs)
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaUserdata ++
public class LuaUserdata
+
+Field Summary | +|
---|---|
+ java.lang.Object |
+m_instance
+
++ |
+
+ LuaValue |
+m_metatable
+
++ |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
LuaUserdata(java.lang.Object obj)
+
++ |
+|
LuaUserdata(java.lang.Object obj,
+ LuaValue metatable)
+
++ |
+
+Method Summary | +|
---|---|
+ java.lang.Object |
+checkuserdata()
+
++ Check that this is a LuaUserdata , or throw LuaError if it is not |
+
+ java.lang.Object |
+checkuserdata(java.lang.Class c)
+
++ Check that this is a LuaUserdata , or throw LuaError if it is not |
+
+ boolean |
+eq_b(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ ,
+ and return java boolean |
+
+ LuaValue |
+eq(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ . |
+
+ boolean |
+eqmt(LuaValue val)
+
++ |
+
+ boolean |
+equals(java.lang.Object val)
+
++ |
+
+ LuaValue |
+get(LuaValue key)
+
++ Get a value in a table including metatag processing using INDEX . |
+
+ LuaValue |
+getmetatable()
+
++ Get the metatable for this LuaValue |
+
+ int |
+hashCode()
+
++ |
+
+ boolean |
+isuserdata()
+
++ Check if this is a userdata |
+
+ boolean |
+isuserdata(java.lang.Class c)
+
++ Check if this is a userdata of type c |
+
+ java.lang.Object |
+optuserdata(java.lang.Class c,
+ java.lang.Object defval)
+
++ Check that optional argument is a userdata whose instance is of a type + and return the Object instance |
+
+ java.lang.Object |
+optuserdata(java.lang.Object defval)
+
++ Check that optional argument is a userdata and return the Object instance |
+
+ boolean |
+raweq(LuaUserdata val)
+
++ Equals: Perform direct equality comparison with a LuaUserdata value
+ without metatag processing. |
+
+ boolean |
+raweq(LuaValue val)
+
++ Equals: Perform direct equality comparison with another value + without metatag processing. |
+
+ void |
+set(LuaValue key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing using NEWINDEX . |
+
+ LuaValue |
+setmetatable(LuaValue metatable)
+
++ Set the metatable for this LuaValue |
+
+ java.lang.String |
+tojstring()
+
++ Convert to human readable String for any type. |
+
+ java.lang.Object |
+touserdata()
+
++ Convert to userdata instance, or null. |
+
+ java.lang.Object |
+touserdata(java.lang.Class c)
+
++ Convert to userdata instance if specific type, or null. |
+
+ int |
+type()
+
++ Get the enumeration value for the type of this value. |
+
+ java.lang.String |
+typename()
+
++ Get the String name of the type of this value. |
+
+ java.lang.Object |
+userdata()
+
++ |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public final java.lang.Object m_instance+
+public LuaValue m_metatable+
+Constructor Detail | +
---|
+public LuaUserdata(java.lang.Object obj)+
+public LuaUserdata(java.lang.Object obj, + LuaValue metatable)+
+Method Detail | +
---|
+public java.lang.String tojstring()+
LuaValue
+
tojstring
in class LuaValue
LuaValue.tostring()
,
+LuaValue.optjstring(String)
,
+LuaValue.checkjstring()
,
+LuaValue.isstring()
,
+TSTRING
+public int type()+
LuaValue
+
type
in class LuaValue
TNIL
,
+ TBOOLEAN
,
+ TNUMBER
,
+ TSTRING
,
+ TTABLE
,
+ TFUNCTION
,
+ TUSERDATA
,
+ TTHREAD
LuaValue.typename()
+public java.lang.String typename()+
LuaValue
+
+
typename
in class LuaValue
LuaValue.TYPE_NAMES
+ corresponding to the type of this value:
+ "nil", "boolean", "number", "string",
+ "table", "function", "userdata", "thread"LuaValue.type()
+public int hashCode()+
hashCode
in class java.lang.Object
+public java.lang.Object userdata()+
+public boolean isuserdata()+
LuaValue
this
is a userdata
++
isuserdata
in class LuaValue
userdata
, otherwise falseLuaValue.isuserdata(Class)
,
+LuaValue.touserdata()
,
+LuaValue.checkuserdata()
,
+LuaValue.optuserdata(Object)
,
+LuaValue.TUSERDATA
+public boolean isuserdata(java.lang.Class c)+
LuaValue
this
is a userdata
of type c
++
isuserdata
in class LuaValue
c
- Class to test instance against
+userdata
+ and the instance is assignable to c
,
+ otherwise falseLuaValue.isuserdata()
,
+LuaValue.touserdata(Class)
,
+LuaValue.checkuserdata(Class)
,
+#optuserdata(Object,Class)
,
+LuaValue.TUSERDATA
+public java.lang.Object touserdata()+
LuaValue
+
touserdata
in class LuaValue
LuaUserdata
LuaValue.optuserdata(Object)
,
+LuaValue.checkuserdata()
,
+LuaValue.isuserdata()
,
+LuaValue.TUSERDATA
+public java.lang.Object touserdata(java.lang.Class c)+
LuaValue
+
touserdata
in class LuaValue
c
,
+ or null if not LuaUserdata
LuaValue.optuserdata(Class,Object)
,
+LuaValue.checkuserdata(Class)
,
+LuaValue.isuserdata(Class)
,
+LuaValue.TUSERDATA
+public java.lang.Object optuserdata(java.lang.Object defval)+
LuaValue
+
optuserdata
in class LuaValue
defval
- Object to return if this
is nil or none
+LuaUserdata
,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.checkuserdata()
,
+LuaValue.isuserdata()
,
+LuaValue.optuserdata(Class, Object)
,
+LuaValue.TUSERDATA
+public java.lang.Object optuserdata(java.lang.Class c, + java.lang.Object defval)+
LuaValue
+
optuserdata
in class LuaValue
c
- Class to test userdata instance againstdefval
- Object to return if this
is nil or none
+LuaUserdata
and instance is assignable to c
,
+ defval
if nil or none,
+ throws LuaError
if some other typeLuaValue.checkuserdata(Class)
,
+LuaValue.isuserdata(Class)
,
+LuaValue.optuserdata(Object)
,
+LuaValue.TUSERDATA
+public LuaValue getmetatable()+
LuaValue
LuaValue
+
+ For LuaTable
and LuaUserdata
instances,
+ the metatable returned is this instance metatable.
+ For all other types, the class metatable value will be returned.
+
+
getmetatable
in class LuaValue
LuaBoolean.s_metatable
,
+LuaNumber.s_metatable
,
+LuaNil.s_metatable
,
+LuaFunction.s_metatable
,
+LuaThread.s_metatable
+public LuaValue setmetatable(LuaValue metatable)+
LuaValue
LuaValue
+
+ For LuaTable
and LuaUserdata
instances, the metatable is per instance.
+ For all other types, there is one metatable per type that can be set directly from java
+
+
setmetatable
in class LuaValue
metatable
- LuaValue
instance to serve as the metatable, or null to reset it.
+this
to allow chaining of Java function callsLuaBoolean.s_metatable
,
+LuaNumber.s_metatable
,
+LuaNil.s_metatable
,
+LuaFunction.s_metatable
,
+LuaThread.s_metatable
+public java.lang.Object checkuserdata()+
LuaValue
LuaUserdata
, or throw LuaError
if it is not
++
checkuserdata
in class LuaValue
this
if it is a LuaUserdata
LuaValue.isuserdata()
,
+LuaValue.optuserdata(Object)
,
+LuaValue.checkuserdata(Class)
,
+LuaValue.TUSERDATA
+public java.lang.Object checkuserdata(java.lang.Class c)+
LuaValue
LuaUserdata
, or throw LuaError
if it is not
++
checkuserdata
in class LuaValue
this
if it is a LuaUserdata
LuaValue.isuserdata(Class)
,
+LuaValue.optuserdata(Class, Object)
,
+LuaValue.checkuserdata()
,
+LuaValue.TUSERDATA
+public LuaValue get(LuaValue key)+
LuaValue
INDEX
.
++
get
in class LuaValue
key
- the key to look up, must not be NIL
or null
+LuaValue
for that key, or NIL
if not found and no metatagLuaValue.get(int)
,
+LuaValue.get(String)
,
+LuaValue.rawget(LuaValue)
+public void set(LuaValue key, + LuaValue value)+
LuaValue
NEWINDEX
.
++
set
in class LuaValue
key
- the key to use, must not be NIL
or nullvalue
- the value to use, can be NIL
, must not be null+public boolean equals(java.lang.Object val)+
equals
in class LuaValue
+public LuaValue eq(LuaValue val)+
LuaValue
EQ
.
++
eq
in class LuaValue
val
- The value to compare with.
+TRUE
if values are comparable and (this == rhs)
,
+ FALSE
if comparable but not equal,
+ LuaValue
if metatag processing occurs.LuaValue.eq_b(LuaValue)
,
+LuaValue.raweq(LuaValue)
,
+LuaValue.neq(LuaValue)
,
+LuaValue.eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
,
+LuaValue.EQ
+public boolean eq_b(LuaValue val)+
LuaValue
EQ
,
+ and return java boolean
++
eq_b
in class LuaValue
val
- The value to compare with.
+(this == rhs)
,
+ false if comparable but not equal,
+ result converted to java boolean if metatag processing occurs.LuaValue.eq(LuaValue)
,
+LuaValue.raweq(LuaValue)
,
+LuaValue.neq_b(LuaValue)
,
+LuaValue.eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
,
+LuaValue.EQ
+public boolean raweq(LuaValue val)+
LuaValue
+
raweq
in class LuaValue
val
- The value to compare with.
+(this == rhs)
, false otherwiseLuaValue.eq(LuaValue)
,
+LuaValue.raweq(LuaUserdata)
,
+LuaValue.raweq(LuaString)
,
+LuaValue.raweq(double)
,
+LuaValue.raweq(int)
,
+LuaValue.EQ
+public boolean raweq(LuaUserdata val)+
LuaValue
LuaUserdata
value
+ without metatag processing.
++
raweq
in class LuaValue
val
- The LuaUserdata
to compare with.
+this
is userdata
+ and their metatables are the same using ==
+ and their instances are equal using LuaValue.equals(Object)
,
+ otherwise falseLuaValue.eq(LuaValue)
,
+LuaValue.raweq(LuaValue)
+public boolean eqmt(LuaValue val)+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue ++
public abstract class LuaValue
+Base class for all concrete lua type values. +
+ Establishes base implementations for all the operations on lua types.
+ This allows Java clients to deal essentially with one type for all Java values, namely LuaValue
.
+
+ Constructors are provided as static methods for common Java types, such as
+ valueOf(int)
or valueOf(String)
+ to allow for instance pooling.
+
+ Constants are defined for the lua values
+ NIL
, TRUE
, and FALSE
.
+ A constant NONE
is defined which is a Varargs
list having no values.
+
+ Operations are performed on values directly via their Java methods. + For example, the following code divides two numbers: +
LuaValue a = LuaValue.valueOf( 5 );
+ LuaValue b = LuaValue.valueOf( 4 );
+ LuaValue c = a.div(b);
+
+ Note that in this example, c will be a LuaDouble
, but would be a LuaInteger
+ if the value of a were changed to 8, say.
+ In general the value of c in practice will vary depending on both the types and values of a and b
+ as well as any metatable/metatag processing that occurs.
+ + Field access and function calls are similar, with common overloads to simplify Java usage: +
LuaValue globals = JsePlatform.standardGlobals();
+ LuaValue sqrt = globals.get("math").get("sqrt");
+ LuaValue print = globals.get("print");
+ LuaValue d = sqrt.call( a );
+ print.call( LuaValue.valueOf("sqrt(5):"), a );
+
+
+ To supply variable arguments or get multiple return values, use
+ invoke(Varargs)
or invokemethod(LuaValue, Varargs)
methods:
+
LuaValue modf = globals.get("math").get("modf");
+ Varargs r = modf.invoke( d );
+ print.call( r.arg(1), r.arg(2) );
+
+
+ To load and run a script, LoadState
is used:
+
LoadState.load( new FileInputStream("main.lua"), "main.lua", globals ).call();
+
+
+ although require
could also be used:
+
globals.get("require").call(LuaValue.valueOf("main"));
+
+ For this to work the file must be in the current directory, or in the class path,
+ dependening on the platform.
+ See JsePlatform
and JmePlatform
for details.
+
+ In general a LuaError
may be thrown on any operation when the
+ types supplied to any operation are illegal from a lua perspective.
+ Examples could be attempting to concatenate a NIL value, or attempting arithmetic
+ on values that are not number.
+
+ There are several methods for preinitializing tables, such as: +
listOf(LuaValue[])
for unnamed elementstableOf(LuaValue[])
for named elementstableOf(LuaValue[], LuaValue[], Varargs)
for mixtures
+ Predefined constants exist for the standard lua type constants
+ TNIL
, TBOOLEAN
, TLIGHTUSERDATA
, TNUMBER
, TSTRING
,
+ TTABLE
, TFUNCTION
, TUSERDATA
, TTHREAD
,
+ and extended lua type constants
+ TINT
, TNONE
, TVALUE
+
+ Predefined constants exist for all strings used as metatags:
+ INDEX
, NEWINDEX
, CALL
, MODE
, METATABLE
,
+ ADD
, SUB
, DIV
, MUL
, POW
,
+ MOD
, UNM
, LEN
, EQ
, LT
,
+ LE
, TOSTRING
, and CONCAT
.
+
+ +
+
JsePlatform
,
+JmePlatform
,
+LoadState
,
+Varargs
+Field Summary | +|
---|---|
+static LuaString |
+ADD
+
++ LuaString constant with value "__add" for use as metatag |
+
+static LuaString |
+CALL
+
++ LuaString constant with value "__call" for use as metatag |
+
+static LuaString |
+CONCAT
+
++ LuaString constant with value "__concat" for use as metatag |
+
+static LuaString |
+DIV
+
++ LuaString constant with value "__div" for use as metatag |
+
+static LuaString |
+EMPTYSTRING
+
++ LuaString constant with value "" |
+
+static LuaString |
+EQ
+
++ LuaString constant with value "__eq" for use as metatag |
+
+static LuaBoolean |
+FALSE
+
++ LuaBoolean constant corresponding to lua false |
+
+static LuaString |
+INDEX
+
++ LuaString constant with value "__index" for use as metatag |
+
+static LuaString |
+LE
+
++ LuaString constant with value "__le" for use as metatag |
+
+static LuaString |
+LEN
+
++ LuaString constant with value "__len" for use as metatag |
+
+static LuaString |
+LT
+
++ LuaString constant with value "__lt" for use as metatag |
+
+static LuaString |
+METATABLE
+
++ LuaString constant with value "__metatable" for use as metatag |
+
+static LuaNumber |
+MINUSONE
+
++ LuaValue number constant equal to -1 |
+
+static LuaString |
+MOD
+
++ LuaString constant with value "__mod" for use as metatag |
+
+static LuaString |
+MODE
+
++ LuaString constant with value "__mode" for use as metatag |
+
+static LuaString |
+MUL
+
++ LuaString constant with value "__mul" for use as metatag |
+
+static LuaString |
+NEWINDEX
+
++ LuaString constant with value "__newindex" for use as metatag |
+
+static LuaValue |
+NIL
+
++ LuaValue constant corresponding to lua nil |
+
+static LuaValue[] |
+NILS
+
++ Array of NIL values to optimize filling stacks using System.arraycopy(). |
+
+static LuaValue |
+NONE
+
++ LuaValue constant corresponding to a Varargs list of no values |
+
+static LuaValue[] |
+NOVALS
+
++ LuaValue array constant with no values |
+
+static LuaNumber |
+ONE
+
++ LuaValue number constant equal to 1 |
+
+static LuaString |
+POW
+
++ LuaString constant with value "__pow" for use as metatag |
+
+static LuaString |
+SUB
+
++ LuaString constant with value "__sub" for use as metatag |
+
+static int |
+TBOOLEAN
+
++ Type enumeration constant for lua booleans |
+
+static int |
+TFUNCTION
+
++ Type enumeration constant for lua functions |
+
+static int |
+TINT
+
++ Type enumeration constant for lua numbers that are ints, for compatibility with lua 5.1 number patch only |
+
+static int |
+TLIGHTUSERDATA
+
++ Type enumeration constant for lua light userdata, for compatibility with C-based lua only |
+
+static int |
+TNIL
+
++ Type enumeration constant for lua nil |
+
+static int |
+TNONE
+
++ Type enumeration constant for lua values that have no type, for example weak table entries |
+
+static int |
+TNUMBER
+
++ Type enumeration constant for lua numbers |
+
+static LuaString |
+TOSTRING
+
++ LuaString constant with value "__tostring" for use as metatag |
+
+static LuaBoolean |
+TRUE
+
++ LuaBoolean constant corresponding to lua true |
+
+static int |
+TSTRING
+
++ Type enumeration constant for lua strings |
+
+static int |
+TTABLE
+
++ Type enumeration constant for lua tables |
+
+static int |
+TTHREAD
+
++ Type enumeration constant for lua threads |
+
+static int |
+TUSERDATA
+
++ Type enumeration constant for lua userdatas |
+
+static int |
+TVALUE
+
++ Type enumeration constant for unknown values, for compatibility with C-based lua only |
+
+static java.lang.String[] |
+TYPE_NAMES
+
++ String array constant containing names of each of the lua value types |
+
+static LuaString |
+UNM
+
++ LuaString constant with value "__unm" for use as metatag |
+
+static LuaNumber |
+ZERO
+
++ LuaValue number constant equal to 0 |
+
+Constructor Summary | +|
---|---|
LuaValue()
+
++ |
+
+Method Summary | +|
---|---|
+ LuaValue |
+add(double rhs)
+
++ Add: Perform numeric add operation with another value + of double type with metatag processing |
+
+ LuaValue |
+add(int rhs)
+
++ Add: Perform numeric add operation with another value + of int type with metatag processing |
+
+ LuaValue |
+add(LuaValue rhs)
+
++ Add: Perform numeric add operation with another value + including metatag processing. |
+
+ LuaValue |
+and(LuaValue rhs)
+
++ Perform boolean and with another operand, based on lua rules for boolean evaluation. |
+
+ LuaValue |
+arg(int index)
+
++ Get the n-th argument value (1-based). |
+
+ LuaValue |
+arg1()
+
++ Get the first argument in the list. |
+
+static LuaValue |
+argerror(int iarg,
+ java.lang.String msg)
+
++ Throw a LuaError indicating an invalid argument was supplied to a function |
+
+protected LuaValue |
+argerror(java.lang.String expected)
+
++ Throw a LuaError indicating an invalid argument was supplied to a function |
+
+protected LuaValue |
+aritherror()
+
++ Throw a LuaError based on an arithmetic error such as add, or pow,
+ typically due to an invalid operand type |
+
+protected LuaValue |
+aritherror(java.lang.String fun)
+
++ Throw a LuaError based on an arithmetic error such as add, or pow,
+ typically due to an invalid operand type |
+
+protected LuaValue |
+arithmt(LuaValue tag,
+ LuaValue op2)
+
++ Perform metatag processing for arithmetic operations. |
+
+protected LuaValue |
+arithmtwith(LuaValue tag,
+ double op1)
+
++ Perform metatag processing for arithmetic operations when the left-hand-side is a number. |
+
+static void |
+assert_(boolean b,
+ java.lang.String msg)
+
++ Assert a condition is true, or throw a LuaError if not |
+
+ Buffer |
+buffer()
+
++ Convert the value to a Buffer for more efficient concatenation of
+ multiple strings. |
+
+ LuaValue |
+call()
+
++ Call this with 0 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2)
+
++ Call this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ Call this with 3 arguments, including metatag processing,
+ and return only the first return value. |
+
+protected LuaValue |
+callmt()
+
++ Get the metatag value for the CALL metatag, if it exists. |
+
+ boolean |
+checkboolean()
+
++ Check that the value is a LuaBoolean ,
+ or throw LuaError if not |
+
+ LuaClosure |
+checkclosure()
+
++ Check that the value is a LuaClosure ,
+ or throw LuaError if not |
+
+ double |
+checkdouble()
+
++ Check that the value is numeric and return the value as a double, + or throw LuaError if not numeric |
+
+ LuaValue |
+checkfunction()
+
++ Check that the value is a function , or throw LuaError if not |
+
+ int |
+checkint()
+
++ Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric |
+
+ LuaInteger |
+checkinteger()
+
++ Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric |
+
+ java.lang.String |
+checkjstring()
+
++ Convert this value to a Java String. |
+
+ long |
+checklong()
+
++ Check that the value is numeric, and convert and cast value to long, or throw LuaError if not numeric |
+
+protected LuaValue |
+checkmetatag(LuaValue tag,
+ java.lang.String reason)
+
++ Get particular metatag, or throw LuaError if it doesn't exist |
+
+ LuaValue |
+checknotnil()
+
++ Check that this is not the value NIL , or throw LuaError if it is |
+
+ LuaNumber |
+checknumber()
+
++ Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError |
+
+ LuaNumber |
+checknumber(java.lang.String msg)
+
++ Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError |
+
+ LuaString |
+checkstring()
+
++ Check that this is a lua string, or throw LuaError if it is not. |
+
+ LuaTable |
+checktable()
+
++ Check that this is a LuaTable , or throw LuaError if it is not |
+
+ LuaThread |
+checkthread()
+
++ Check that this is a LuaThread , or throw LuaError if it is not |
+
+ java.lang.Object |
+checkuserdata()
+
++ Check that this is a LuaUserdata , or throw LuaError if it is not |
+
+ java.lang.Object |
+checkuserdata(java.lang.Class c)
+
++ Check that this is a LuaUserdata , or throw LuaError if it is not |
+
+ LuaValue |
+checkvalidkey()
+
++ Check that this is a valid key in a table index operation, or throw LuaError if not |
+
+protected LuaValue |
+compareerror(LuaValue rhs)
+
++ Throw a LuaError based on a comparison error such as greater-than or less-than,
+ typically due to an invalid operand type |
+
+protected LuaValue |
+compareerror(java.lang.String rhs)
+
++ Throw a LuaError based on a comparison error such as greater-than or less-than,
+ typically due to an invalid operand type |
+
+ LuaValue |
+comparemt(LuaValue tag,
+ LuaValue op1)
+
++ Perform metatag processing for comparison operations. |
+
+ Buffer |
+concat(Buffer rhs)
+
++ Concatenate a Buffer onto this value and return the result
+ using rules of lua string concatenation including metatag processing. |
+
+ LuaValue |
+concat(LuaValue rhs)
+
++ Concatenate another value onto this value and return the result + using rules of lua string concatenation including metatag processing. |
+
+ LuaValue |
+concatmt(LuaValue rhs)
+
++ Perform metatag processing for concatenation operations. |
+
+ LuaValue |
+concatTo(LuaNumber lhs)
+
++ Reverse-concatenation: concatenate this value onto another value + known to be a LuaNumber
+ and return the result using rules of lua string concatenation including
+ metatag processing. |
+
+ LuaValue |
+concatTo(LuaString lhs)
+
++ Reverse-concatenation: concatenate this value onto another value + known to be a LuaString
+ and return the result using rules of lua string concatenation including
+ metatag processing. |
+
+ LuaValue |
+concatTo(LuaValue lhs)
+
++ Reverse-concatenation: concatenate this value onto another value + whose type is unknwon + and return the result using rules of lua string concatenation including + metatag processing. |
+
+ LuaValue |
+div(double rhs)
+
++ Divide: Perform numeric divide operation by another value + of double type without metatag processing |
+
+ LuaValue |
+div(int rhs)
+
++ Divide: Perform numeric divide operation by another value + of int type without metatag processing |
+
+ LuaValue |
+div(LuaValue rhs)
+
++ Divide: Perform numeric divide operation by another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+divInto(double lhs)
+
++ Reverse-divide: Perform numeric divide operation into another value + with metatag processing |
+
+ boolean |
+eq_b(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ ,
+ and return java boolean |
+
+ LuaValue |
+eq(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ . |
+
+static boolean |
+eqmtcall(LuaValue lhs,
+ LuaValue lhsmt,
+ LuaValue rhs,
+ LuaValue rhsmt)
+
++ Perform equality testing metatag processing |
+
+ boolean |
+equals(java.lang.Object obj)
+
++ |
+
+static LuaValue |
+error(java.lang.String message)
+
++ Throw a LuaError with a particular message |
+
+ LuaValue |
+get(int key)
+
++ Get a value in a table including metatag processing using INDEX . |
+
+ LuaValue |
+get(LuaValue key)
+
++ Get a value in a table including metatag processing using INDEX . |
+
+ LuaValue |
+get(java.lang.String key)
+
++ Get a value in a table including metatag processing using INDEX . |
+
+ LuaValue |
+getfenv()
+
++ Get the environemnt for an instance. |
+
+ LuaValue |
+getmetatable()
+
++ Get the metatable for this LuaValue |
+
+ LuaValue |
+getn()
+
++ Implementation of lua 5.0 getn() function. |
+
+protected static LuaValue |
+gettable(LuaValue t,
+ LuaValue key)
+
++ get value from metatable operations, or NIL if not defined by metatables |
+
+ boolean |
+gt_b(double rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ boolean |
+gt_b(int rhs)
+
++ Greater than: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+gt_b(LuaValue rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+gt(double rhs)
+
++ Greater than: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+gt(int rhs)
+
++ Greater than: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+gt(LuaValue rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ boolean |
+gteq_b(double rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+gteq_b(int rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+gteq_b(LuaValue rhs)
+
++ Greater than or equals: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+gteq(double rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+gteq(int rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+gteq(LuaValue rhs)
+
++ Greater than or equals: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+protected LuaValue |
+illegal(java.lang.String op,
+ java.lang.String typename)
+
++ Throw a LuaError indicating an illegal operation occurred,
+ typically involved in managing weak references |
+
+ Varargs |
+inext(LuaValue index)
+
++ Find the next integer-key,value pair if this is a table,
+ return NIL if there are no more, or throw a LuaError if not a table. |
+
+ Varargs |
+invoke()
+
++ Call this with 0 arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+invoke(LuaValue[] args)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+invoke(LuaValue[] args,
+ Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+invoke(LuaValue arg1,
+ LuaValue arg2,
+ Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+invoke(LuaValue arg,
+ Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+invoke(Varargs args)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+invokemethod(LuaValue name)
+
++ Call named method on this with 0 arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+invokemethod(LuaValue name,
+ LuaValue[] args)
+
++ Call named method on this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+invokemethod(LuaValue name,
+ Varargs args)
+
++ Call named method on this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+invokemethod(java.lang.String name)
+
++ Call named method on this with 0 arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+invokemethod(java.lang.String name,
+ LuaValue[] args)
+
++ Call named method on this with 1 argument, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+invokemethod(java.lang.String name,
+ Varargs args)
+
++ Call named method on this with 1 argument, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ boolean |
+isboolean()
+
++ Check if this is a boolean |
+
+ boolean |
+isclosure()
+
++ Check if this is a function that is a closure,
+ meaning interprets lua bytecode for its execution |
+
+ boolean |
+isfunction()
+
++ Check if this is a function |
+
+ boolean |
+isint()
+
++ Check if this is a number and is representable by java int
+ without rounding or truncation |
+
+ boolean |
+isinttype()
+
++ Check if this is a LuaInteger |
+
+ boolean |
+islong()
+
++ Check if this is a number and is representable by java long
+ without rounding or truncation |
+
+ boolean |
+isnil()
+
++ Check if this is nil |
+
+ boolean |
+isnumber()
+
++ Check if this is a number |
+
+ boolean |
+isstring()
+
++ Check if this is a string |
+
+ boolean |
+istable()
+
++ Check if this is a table |
+
+ boolean |
+isthread()
+
++ Check if this is a thread |
+
+ boolean |
+isuserdata()
+
++ Check if this is a userdata |
+
+ boolean |
+isuserdata(java.lang.Class c)
+
++ Check if this is a userdata of type c |
+
+ boolean |
+isweaknil()
+
++ Test if this is a weak reference and its value no longer is referenced. |
+
+ LuaValue |
+len()
+
++ Length operator: return lua length of object (#this) including metatag processing as java int |
+
+protected LuaValue |
+lenerror()
+
++ Throw a LuaError based on the len operator,
+ typically due to an invalid operand type |
+
+ int |
+length()
+
++ Length operator: return lua length of object (#this) including metatag processing as java int |
+
+static LuaTable |
+listOf(LuaValue[] unnamedValues)
+
++ Construct a LuaTable initialized with supplied array values. |
+
+static LuaTable |
+listOf(LuaValue[] unnamedValues,
+ Varargs lastarg)
+
++ Construct a LuaTable initialized with supplied array values. |
+
+ LuaValue |
+load(LuaValue library)
+
++ Load a library instance by setting its environment to this
+ and calling it, which should iniitalize the library instance and
+ install itself into this instance. |
+
+ boolean |
+lt_b(double rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ boolean |
+lt_b(int rhs)
+
++ Less than: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+lt_b(LuaValue rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+lt(double rhs)
+
++ Less than: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+lt(int rhs)
+
++ Less than: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+lt(LuaValue rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ boolean |
+lteq_b(double rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+lteq_b(int rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, + and returning java boolean. |
+
+ boolean |
+lteq_b(LuaValue rhs)
+
++ Less than or equals: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+lteq(double rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+lteq(int rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+lteq(LuaValue rhs)
+
++ Less than or equals: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+metatag(LuaValue tag)
+
++ Get particular metatag, or return NIL if it doesn't exist |
+
+ LuaValue |
+method(LuaValue name)
+
++ Call named method on this with 0 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+method(LuaValue name,
+ LuaValue arg)
+
++ Call named method on this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+method(LuaValue name,
+ LuaValue arg1,
+ LuaValue arg2)
+
++ Call named method on this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+method(java.lang.String name)
+
++ Call named method on this with 0 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+method(java.lang.String name,
+ LuaValue arg)
+
++ Call named method on this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+method(java.lang.String name,
+ LuaValue arg1,
+ LuaValue arg2)
+
++ Call named method on this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+mod(double rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of double type without metatag processing |
+
+ LuaValue |
+mod(int rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of int type without metatag processing |
+
+ LuaValue |
+mod(LuaValue rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+modFrom(double lhs)
+
++ Reverse-modulo: Perform numeric modulo operation from another value + with metatag processing |
+
+ LuaValue |
+mul(double rhs)
+
++ Multiply: Perform numeric multiply operation with another value + of double type with metatag processing |
+
+ LuaValue |
+mul(int rhs)
+
++ Multiply: Perform numeric multiply operation with another value + of int type with metatag processing |
+
+ LuaValue |
+mul(LuaValue rhs)
+
++ Multiply: Perform numeric multiply operation with another value + of unknown type, + including metatag processing. |
+
+ int |
+narg()
+
++ Get the number of arguments, or 0 if there are none. |
+
+ LuaValue |
+neg()
+
++ Unary minus: return negative value (-this) as defined by lua unary minus operator |
+
+ boolean |
+neq_b(LuaValue val)
+
++ Notquals: Perform inequality comparison with another value + including metatag processing using EQ . |
+
+ LuaValue |
+neq(LuaValue val)
+
++ Notquals: Perform inequality comparison with another value + including metatag processing using EQ . |
+
+ Varargs |
+next(LuaValue index)
+
++ Find the next key,value pair if this is a table,
+ return NIL if there are no more, or throw a LuaError if not a table. |
+
+ LuaValue |
+not()
+
++ Unary not: return inverse boolean value (~this) as defined by lua not operator |
+
+ Varargs |
+onInvoke(Varargs args)
+
++ Callback used during tail call processing to invoke the function once. |
+
+ boolean |
+optboolean(boolean defval)
+
++ Check that optional argument is a boolean and return its boolean value |
+
+ LuaClosure |
+optclosure(LuaClosure defval)
+
++ Check that optional argument is a closure and return as LuaClosure |
+
+ double |
+optdouble(double defval)
+
++ Check that optional argument is a number or string convertible to number and return as double |
+
+ LuaFunction |
+optfunction(LuaFunction defval)
+
++ Check that optional argument is a function and return as LuaFunction |
+
+ int |
+optint(int defval)
+
++ Check that optional argument is a number or string convertible to number and return as int |
+
+ LuaInteger |
+optinteger(LuaInteger defval)
+
++ Check that optional argument is a number or string convertible to number and return as LuaInteger |
+
+ java.lang.String |
+optjstring(java.lang.String defval)
+
++ Check that optional argument is a string or number and return as Java String |
+
+ long |
+optlong(long defval)
+
++ Check that optional argument is a number or string convertible to number and return as long |
+
+ LuaNumber |
+optnumber(LuaNumber defval)
+
++ Check that optional argument is a number or string convertible to number and return as LuaNumber |
+
+ LuaString |
+optstring(LuaString defval)
+
++ Check that optional argument is a string or number and return as LuaString |
+
+ LuaTable |
+opttable(LuaTable defval)
+
++ Check that optional argument is a table and return as LuaTable |
+
+ LuaThread |
+optthread(LuaThread defval)
+
++ Check that optional argument is a thread and return as LuaThread |
+
+ java.lang.Object |
+optuserdata(java.lang.Class c,
+ java.lang.Object defval)
+
++ Check that optional argument is a userdata whose instance is of a type + and return the Object instance |
+
+ java.lang.Object |
+optuserdata(java.lang.Object defval)
+
++ Check that optional argument is a userdata and return the Object instance |
+
+ LuaValue |
+optvalue(LuaValue defval)
+
++ Perform argument check that this is not nil or none. |
+
+ LuaValue |
+or(LuaValue rhs)
+
++ Perform boolean or with another operand, based on lua rules for boolean evaluation. |
+
+ LuaValue |
+pow(double rhs)
+
++ Raise to power: Raise this value to a power + of double type with metatag processing |
+
+ LuaValue |
+pow(int rhs)
+
++ Raise to power: Raise this value to a power + of int type with metatag processing |
+
+ LuaValue |
+pow(LuaValue rhs)
+
++ Raise to power: Raise this value to a power + including metatag processing. |
+
+ LuaValue |
+powWith(double lhs)
+
++ Reverse-raise to power: Raise another value of double type to this power + with metatag processing |
+
+ LuaValue |
+powWith(int lhs)
+
++ Reverse-raise to power: Raise another value of double type to this power + with metatag processing |
+
+ void |
+presize(int i)
+
++ Preallocate the array part of a table to be a certain size, |
+
+ boolean |
+raweq(double val)
+
++ Equals: Perform direct equality comparison with a double value + without metatag processing. |
+
+ boolean |
+raweq(int val)
+
++ Equals: Perform direct equality comparison with a int value + without metatag processing. |
+
+ boolean |
+raweq(LuaString val)
+
++ Equals: Perform direct equality comparison with a LuaString value
+ without metatag processing. |
+
+ boolean |
+raweq(LuaUserdata val)
+
++ Equals: Perform direct equality comparison with a LuaUserdata value
+ without metatag processing. |
+
+ boolean |
+raweq(LuaValue val)
+
++ Equals: Perform direct equality comparison with another value + without metatag processing. |
+
+ LuaValue |
+rawget(int key)
+
++ Get a value in a table without metatag processing. |
+
+ LuaValue |
+rawget(LuaValue key)
+
++ Get a value in a table without metatag processing. |
+
+ LuaValue |
+rawget(java.lang.String key)
+
++ Get a value in a table without metatag processing. |
+
+ void |
+rawset(int key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing. |
+
+ void |
+rawset(int key,
+ java.lang.String value)
+
++ Set a value in a table without metatag processing. |
+
+ void |
+rawset(LuaValue key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing. |
+
+ void |
+rawset(java.lang.String key,
+ double value)
+
++ Set a value in a table without metatag processing. |
+
+ void |
+rawset(java.lang.String key,
+ int value)
+
++ Set a value in a table without metatag processing. |
+
+ void |
+rawset(java.lang.String key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing. |
+
+ void |
+rawset(java.lang.String key,
+ java.lang.String value)
+
++ Set a value in a table without metatag processing. |
+
+ void |
+rawsetlist(int key0,
+ Varargs values)
+
++ Set list values in a table without invoking metatag processing |
+
+ void |
+set(int key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing using NEWINDEX . |
+
+ void |
+set(int key,
+ java.lang.String value)
+
++ Set a value in a table without metatag processing using NEWINDEX . |
+
+ void |
+set(LuaValue key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing using NEWINDEX . |
+
+ void |
+set(java.lang.String key,
+ double value)
+
++ Set a value in a table without metatag processing using NEWINDEX . |
+
+ void |
+set(java.lang.String key,
+ int value)
+
++ Set a value in a table without metatag processing using NEWINDEX . |
+
+ void |
+set(java.lang.String key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing using NEWINDEX . |
+
+ void |
+set(java.lang.String key,
+ java.lang.String value)
+
++ Set a value in a table without metatag processing using NEWINDEX . |
+
+ void |
+setfenv(LuaValue env)
+
++ Set the environment on an object. |
+
+ LuaValue |
+setmetatable(LuaValue metatable)
+
++ Set the metatable for this LuaValue |
+
+protected static boolean |
+settable(LuaValue t,
+ LuaValue key,
+ LuaValue value)
+
++ Perform field assignment including metatag processing. |
+
+ int |
+strcmp(LuaString rhs)
+
++ Perform string comparison with another value + known to be a LuaString
+ using string comparison based on byte values. |
+
+ int |
+strcmp(LuaValue rhs)
+
++ Perform string comparison with another value + of any type + using string comparison based on byte values. |
+
+ LuaValue |
+strongkey()
+
++ Return the key part of this value if it is a weak table entry, or NIL if it was weak and is no longer referenced. |
+
+ LuaValue |
+strongvalue()
+
++ Return this value as a strong reference, or NIL if it was weak and is no longer referenced. |
+
+ LuaString |
+strvalue()
+
++ Convert this value to a string if it is a LuaString or LuaNumber ,
+ or throw a LuaError if it is not |
+
+ LuaValue |
+sub(double rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of double type with metatag processing |
+
+ LuaValue |
+sub(int rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of int type with metatag processing |
+
+ LuaValue |
+sub(LuaValue rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+subFrom(double lhs)
+
++ Reverse-subtract: Perform numeric subtract operation from an int value + with metatag processing |
+
+ LuaValue |
+subFrom(int lhs)
+
++ Reverse-subtract: Perform numeric subtract operation from a double value + without metatag processing |
+
+static LuaTable |
+tableOf()
+
++ Construct an empty LuaTable . |
+
+static LuaTable |
+tableOf(int narray,
+ int nhash)
+
++ Construct an empty LuaTable preallocated to hold array and hashed elements |
+
+static LuaTable |
+tableOf(LuaValue[] namedValues)
+
++ Construct a LuaTable initialized with supplied named values. |
+
+static LuaTable |
+tableOf(LuaValue[] namedValues,
+ LuaValue[] unnamedValues)
+
++ Construct a LuaTable initialized with supplied named values and sequential elements. |
+
+static LuaTable |
+tableOf(LuaValue[] namedValues,
+ LuaValue[] unnamedValues,
+ Varargs lastarg)
+
++ Construct a LuaTable initialized with supplied named values and sequential elements in an array part and as varargs. |
+
+static LuaTable |
+tableOf(Varargs varargs,
+ int firstarg)
+
++ Construct a LuaTable initialized with supplied array values. |
+
+static Varargs |
+tailcallOf(LuaValue func,
+ Varargs args)
+
++ Construct a TailcallVarargs around a function and arguments. |
+
+ boolean |
+testfor_b(LuaValue limit,
+ LuaValue step)
+
++ Perform end-condition test in for-loop processing. |
+
+ boolean |
+toboolean()
+
++ Convert to boolean false if NIL or FALSE , true if anything else |
+
+ byte |
+tobyte()
+
++ Convert to byte if numeric, or 0 if not. |
+
+ char |
+tochar()
+
++ Convert to char if numeric, or 0 if not. |
+
+ double |
+todouble()
+
++ Convert to double if numeric, or 0 if not. |
+
+ float |
+tofloat()
+
++ Convert to float if numeric, or 0 if not. |
+
+ int |
+toint()
+
++ Convert to int if numeric, or 0 if not. |
+
+ java.lang.String |
+tojstring()
+
++ Convert to human readable String for any type. |
+
+ long |
+tolong()
+
++ Convert to long if numeric, or 0 if not. |
+
+ LuaValue |
+tonumber()
+
++ Conditionally convert to lua number without throwing errors. |
+
+ short |
+toshort()
+
++ Convert to short if numeric, or 0 if not. |
+
+ LuaValue |
+tostring()
+
++ Conditionally convert to lua string without throwing errors. |
+
+ java.lang.String |
+toString()
+
++ Convert the value to a human readable string using tojstring() |
+
+ java.lang.Object |
+touserdata()
+
++ Convert to userdata instance, or null. |
+
+ java.lang.Object |
+touserdata(java.lang.Class c)
+
++ Convert to userdata instance if specific type, or null. |
+
+abstract int |
+type()
+
++ Get the enumeration value for the type of this value. |
+
+abstract java.lang.String |
+typename()
+
++ Get the String name of the type of this value. |
+
+protected LuaValue |
+typerror(java.lang.String expected)
+
++ Throw a LuaError indicating an invalid type was supplied to a function |
+
+protected LuaValue |
+unimplemented(java.lang.String fun)
+
++ Throw a LuaError indicating an operation is not implemented |
+
+static LuaUserdata |
+userdataOf(java.lang.Object o)
+
++ Construct a LuaUserdata for an object. |
+
+static LuaUserdata |
+userdataOf(java.lang.Object o,
+ LuaValue metatable)
+
++ Construct a LuaUserdata for an object with a user supplied metatable. |
+
+static LuaBoolean |
+valueOf(boolean b)
+
++ Convert java boolean to a LuaValue . |
+
+static LuaString |
+valueOf(byte[] bytes)
+
++ Convert bytes in an array to a LuaValue . |
+
+static LuaString |
+valueOf(byte[] bytes,
+ int off,
+ int len)
+
++ Convert bytes in an array to a LuaValue . |
+
+static LuaNumber |
+valueOf(double d)
+
++ Convert java double to a LuaValue . |
+
+static LuaInteger |
+valueOf(int i)
+
++ Convert java int to a LuaValue . |
+
+static LuaString |
+valueOf(java.lang.String s)
+
++ Convert java string to a LuaValue . |
+
+static Varargs |
+varargsOf(LuaValue[] v)
+
++ Construct a Varargs around an array of LuaValue s. |
+
+static Varargs |
+varargsOf(LuaValue[] v,
+ int offset,
+ int length)
+
++ Construct a Varargs around an array of LuaValue s. |
+
+static Varargs |
+varargsOf(LuaValue[] v,
+ int offset,
+ int length,
+ Varargs more)
+
++ Construct a Varargs around an array of LuaValue s. |
+
+static Varargs |
+varargsOf(LuaValue[] v,
+ Varargs r)
+
++ Construct a Varargs around an array of LuaValue s. |
+
+static Varargs |
+varargsOf(LuaValue v1,
+ LuaValue v2,
+ Varargs v3)
+
++ Construct a Varargs around a set of 3 or more LuaValue s. |
+
+static Varargs |
+varargsOf(LuaValue v,
+ Varargs r)
+
++ Construct a Varargs around a set of 2 or more LuaValue s. |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static final int TINT+
+
+public static final int TNONE+
+
+public static final int TNIL+
+
+public static final int TBOOLEAN+
+
+public static final int TLIGHTUSERDATA+
+
+public static final int TNUMBER+
+
+public static final int TSTRING+
+
+public static final int TTABLE+
+
+public static final int TFUNCTION+
+
+public static final int TUSERDATA+
+
+public static final int TTHREAD+
+
+public static final int TVALUE+
+
+public static final java.lang.String[] TYPE_NAMES+
+
type()
,
+typename()
+public static final LuaValue NIL+
nil
++
+public static final LuaBoolean TRUE+
true
++
+public static final LuaBoolean FALSE+
false
++
+public static final LuaValue NONE+
Varargs
list of no values
++
+public static final LuaNumber ZERO+
+
+public static final LuaNumber ONE+
+
+public static final LuaNumber MINUSONE+
+
+public static final LuaValue[] NOVALS+
+
+public static final LuaString INDEX+
+
+public static final LuaString NEWINDEX+
+
+public static final LuaString CALL+
+
+public static final LuaString MODE+
+
+public static final LuaString METATABLE+
+
+public static final LuaString ADD+
+
+public static final LuaString SUB+
+
+public static final LuaString DIV+
+
+public static final LuaString MUL+
+
+public static final LuaString POW+
+
+public static final LuaString MOD+
+
+public static final LuaString UNM+
+
+public static final LuaString LEN+
+
+public static final LuaString EQ+
+
+public static final LuaString LT+
+
+public static final LuaString LE+
+
+public static final LuaString TOSTRING+
+
+public static final LuaString CONCAT+
+
+public static final LuaString EMPTYSTRING+
+
+public static final LuaValue[] NILS+
NIL
values to optimize filling stacks using System.arraycopy().
+ Must not be modified.
++
+Constructor Detail | +
---|
+public LuaValue()+
+Method Detail | +
---|
+public abstract int type()+
+
TNIL
,
+ TBOOLEAN
,
+ TNUMBER
,
+ TSTRING
,
+ TTABLE
,
+ TFUNCTION
,
+ TUSERDATA
,
+ TTHREAD
typename()
+public abstract java.lang.String typename()+
+
+
TYPE_NAMES
+ corresponding to the type of this value:
+ "nil", "boolean", "number", "string",
+ "table", "function", "userdata", "thread"type()
+public boolean isboolean()+
this
is a boolean
++
boolean
, otherwise falseisboolean()
,
+toboolean()
,
+checkboolean()
,
+optboolean(boolean)
,
+#TOBOLEAN
+public boolean isclosure()+
this
is a function
that is a closure,
+ meaning interprets lua bytecode for its execution
++
closure
, otherwise falseisfunction()
,
+checkclosure()
,
+optclosure(LuaClosure)
,
+TFUNCTION
+public boolean isfunction()+
this
is a function
++
function
, otherwise falseisclosure()
,
+checkfunction()
,
+#optfunciton(LuaFunction)
,
+TFUNCTION
+public boolean isint()+
this
is a number
and is representable by java int
+ without rounding or truncation
++
number
+ meaning derives from LuaNumber
+ or derives from LuaString
and is convertible to a number,
+ and can be represented by int,
+ otherwise falseisinttype()
,
+islong()
,
+tonumber()
,
+checkint()
,
+optint(int)
,
+TNUMBER
+public boolean isinttype()+
this
is a LuaInteger
+ + No attempt to convert from string will be made by this call. +
+
LuaInteger
,
+ otherwise falseisint()
,
+isnumber()
,
+tonumber()
,
+TNUMBER
+public boolean islong()+
this
is a number
and is representable by java long
+ without rounding or truncation
++
number
+ meaning derives from LuaNumber
+ or derives from LuaString
and is convertible to a number,
+ and can be represented by long,
+ otherwise falsetonumber()
,
+checklong()
,
+optlong(long)
,
+TNUMBER
+public boolean isnil()+
this
is nil
++
nil
, otherwise falseNIL
,
+NONE
,
+checknotnil()
,
+optvalue(LuaValue)
,
+Varargs.isnoneornil(int)
,
+TNIL
,
+TNONE
+public boolean isnumber()+
this
is a number
++
number
,
+ meaning derives from LuaNumber
+ or derives from LuaString
and is convertible to a number,
+ otherwise falsetonumber()
,
+checknumber()
,
+optnumber(LuaNumber)
,
+TNUMBER
+public boolean isstring()+
this
is a string
++
string
,
+ meaning derives from LuaString
or LuaNumber
,
+ otherwise falsetostring()
,
+checkstring()
,
+optstring(LuaString)
,
+TSTRING
+public boolean isthread()+
this
is a thread
++
thread
, otherwise falsecheckthread()
,
+optthread(LuaThread)
,
+TTHREAD
+public boolean istable()+
this
is a table
++
table
, otherwise falsechecktable()
,
+opttable(LuaTable)
,
+TTABLE
+public boolean isuserdata()+
this
is a userdata
++
userdata
, otherwise falseisuserdata(Class)
,
+touserdata()
,
+checkuserdata()
,
+optuserdata(Object)
,
+TUSERDATA
+public boolean isuserdata(java.lang.Class c)+
this
is a userdata
of type c
++
c
- Class to test instance against
+userdata
+ and the instance is assignable to c
,
+ otherwise falseisuserdata()
,
+touserdata(Class)
,
+checkuserdata(Class)
,
+#optuserdata(Object,Class)
,
+TUSERDATA
+public boolean toboolean()+
NIL
or FALSE
, true if anything else
++
optboolean(boolean)
,
+checkboolean()
,
+isboolean()
,
+TBOOLEAN
+public byte tobyte()+
+
toint()
,
+todouble()
,
+#optbyte(byte)
,
+checknumber()
,
+isnumber()
,
+TNUMBER
+public char tochar()+
+
toint()
,
+todouble()
,
+#optchar(char)
,
+checknumber()
,
+isnumber()
,
+TNUMBER
+public double todouble()+
+
toint()
,
+tobyte()
,
+tochar()
,
+toshort()
,
+tolong()
,
+tofloat()
,
+optdouble(double)
,
+checknumber()
,
+isnumber()
,
+TNUMBER
+public float tofloat()+
+
toint()
,
+todouble()
,
+#optfloat(float)
,
+checknumber()
,
+isnumber()
,
+TNUMBER
+public int toint()+
+
tobyte()
,
+tochar()
,
+toshort()
,
+tolong()
,
+tofloat()
,
+todouble()
,
+optint(int)
,
+checknumber()
,
+isnumber()
,
+TNUMBER
+public long tolong()+
+
isint()
,
+isinttype()
,
+toint()
,
+todouble()
,
+optlong(long)
,
+checknumber()
,
+isnumber()
,
+TNUMBER
+public short toshort()+
+
toint()
,
+todouble()
,
+#optshort(short)
,
+checknumber()
,
+isnumber()
,
+TNUMBER
+public java.lang.String tojstring()+
+
tojstring
in class Varargs
tostring()
,
+optjstring(String)
,
+checkjstring()
,
+isstring()
,
+TSTRING
+public java.lang.Object touserdata()+
+
LuaUserdata
optuserdata(Object)
,
+checkuserdata()
,
+isuserdata()
,
+TUSERDATA
+public java.lang.Object touserdata(java.lang.Class c)+
+
c
,
+ or null if not LuaUserdata
optuserdata(Class,Object)
,
+checkuserdata(Class)
,
+isuserdata(Class)
,
+TUSERDATA
+public java.lang.String toString()+
tojstring()
++
toString
in class Varargs
tostring()
,
+tojstring()
,
+optstring(LuaString)
,
+checkstring()
,
+toString()
+public LuaValue tonumber()+
+ In lua all numbers are strings, but not all strings are numbers.
+ This function will return
+ the LuaValue
this
if it is a number
+ or a string convertible to a number,
+ and NIL
for all other cases.
+
+ This allows values to be tested for their "numeric-ness" without + the penalty of throwing exceptions, + nor the cost of converting the type and creating storage for it. +
+
this
if it is a LuaNumber
+ or LuaString
that can be converted to a number,
+ otherwise NIL
tostring()
,
+optnumber(LuaNumber)
,
+checknumber()
,
+toint()
,
+todouble()
+public LuaValue tostring()+
+ In lua all numbers are strings, so this function will return
+ the LuaValue
this
if it is a string or number,
+ and NIL
for all other cases.
+
+ This allows values to be tested for their "string-ness" without + the penalty of throwing exceptions. +
+
this
if it is a LuaString
or LuaNumber
,
+ otherwise NIL
tonumber()
,
+tojstring()
,
+optstring(LuaString)
,
+checkstring()
,
+toString()
+public boolean optboolean(boolean defval)+
+
defval
- boolean value to return if this
is nil or none
+this
cast to boolean if a ,
+ defval
if nil or none,
+ throws LuaError
otherwise
+LuaError
- if was not a boolean or nil or none.checkboolean()
,
+isboolean()
,
+TBOOLEAN
+public LuaClosure optclosure(LuaClosure defval)+
LuaClosure
+
+ A LuaClosure
is a that executes lua byteccode.
+
+
defval
- LuaClosure
to return if this
is nil or none
+this
cast to LuaClosure
if a function,
+ defval
if nil or none,
+ throws LuaError
otherwise
+LuaError
- if was not a closure or nil or none.checkclosure()
,
+isclosure()
,
+TFUNCTION
+public double optdouble(double defval)+
+
defval
- double to return if this
is nil or none
+this
cast to double if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwise
+LuaError
- if was not numeric or nil or none.optint(int)
,
+optinteger(LuaInteger)
,
+checkdouble()
,
+todouble()
,
+tonumber()
,
+isnumber()
,
+TNUMBER
+public LuaFunction optfunction(LuaFunction defval)+
LuaFunction
+
+ A LuaFunction
may either be a Java function that implements
+ functionality directly in Java,
+ or a LuaClosure
+ which is a LuaFunction
that executes lua bytecode.
+
+
defval
- LuaFunction
to return if this
is nil or none
+this
cast to LuaFunction
if a function,
+ defval
if nil or none,
+ throws LuaError
otherwise
+LuaError
- if was not a function or nil or none.checkfunction()
,
+isfunction()
,
+TFUNCTION
+public int optint(int defval)+
+
defval
- int to return if this
is nil or none
+this
cast to int if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwise
+LuaError
- if was not numeric or nil or none.optdouble(double)
,
+optlong(long)
,
+optinteger(LuaInteger)
,
+checkint()
,
+toint()
,
+tonumber()
,
+isnumber()
,
+TNUMBER
+public LuaInteger optinteger(LuaInteger defval)+
LuaInteger
++
defval
- LuaInteger
to return if this
is nil or none
+this
converted and wrapped in LuaInteger
if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwise
+LuaError
- if was not numeric or nil or none.optdouble(double)
,
+optint(int)
,
+checkint()
,
+toint()
,
+tonumber()
,
+isnumber()
,
+TNUMBER
+public long optlong(long defval)+
+
defval
- long to return if this
is nil or none
+this
cast to long if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwise
+LuaError
- if was not numeric or nil or none.optdouble(double)
,
+optint(int)
,
+checkint()
,
+toint()
,
+tonumber()
,
+isnumber()
,
+TNUMBER
+public LuaNumber optnumber(LuaNumber defval)+
LuaNumber
++
defval
- LuaNumber
to return if this
is nil or none
+this
cast to LuaNumber
if numeric,
+ defval
if nil or none,
+ throws LuaError
otherwise
+LuaError
- if was not numeric or nil or none.optdouble(double)
,
+optlong(long)
,
+optint(int)
,
+checkint()
,
+toint()
,
+tonumber()
,
+isnumber()
,
+TNUMBER
+public java.lang.String optjstring(java.lang.String defval)+
+
defval
- LuaString
to return if this
is nil or none
+this
converted to String if a string or number,
+ defval
if nil or none,
+ throws LuaError
if some other type
+LuaError
- if was not a string or number or nil or none.tojstring()
,
+optstring(LuaString)
,
+checkjstring()
,
+toString()
,
+TSTRING
+public LuaString optstring(LuaString defval)+
LuaString
++
defval
- LuaString
to return if this
is nil or none
+this
converted to LuaString
if a string or number,
+ defval
if nil or none,
+ throws LuaError
if some other type
+LuaError
- if was not a string or number or nil or none.tojstring()
,
+optjstring(String)
,
+checkstring()
,
+toString()
,
+TSTRING
+public LuaTable opttable(LuaTable defval)+
LuaTable
++
defval
- LuaTable
to return if this
is nil or none
+this
cast to LuaTable
if a table,
+ defval
if nil or none,
+ throws LuaError
if some other type
+LuaError
- if was not a table or nil or none.checktable()
,
+istable()
,
+TTABLE
+public LuaThread optthread(LuaThread defval)+
LuaThread
++
defval
- LuaThread
to return if this
is nil or none
+this
cast to LuaTable
if a thread,
+ defval
if nil or none,
+ throws LuaError
if some other type
+LuaError
- if was not a thread or nil or none.checkthread()
,
+isthread()
,
+TTHREAD
+public java.lang.Object optuserdata(java.lang.Object defval)+
+
defval
- Object to return if this
is nil or none
+LuaUserdata
,
+ defval
if nil or none,
+ throws LuaError
if some other type
+LuaError
- if was not a userdata or nil or none.checkuserdata()
,
+isuserdata()
,
+optuserdata(Class, Object)
,
+TUSERDATA
+public java.lang.Object optuserdata(java.lang.Class c, + java.lang.Object defval)+
+
c
- Class to test userdata instance againstdefval
- Object to return if this
is nil or none
+LuaUserdata
and instance is assignable to c
,
+ defval
if nil or none,
+ throws LuaError
if some other type
+LuaError
- if was not a userdata whose instance is assignable to c
or nil or none.checkuserdata(Class)
,
+isuserdata(Class)
,
+optuserdata(Object)
,
+TUSERDATA
+public LuaValue optvalue(LuaValue defval)+
+
defval
- LuaValue
to return if this
is nil or none
+this
if not nil or none, else defval
NIL
,
+NONE
,
+isnil()
,
+Varargs.isnoneornil(int)
,
+TNIL
,
+TNONE
+public boolean checkboolean()+
LuaBoolean
,
+ or throw LuaError
if not
++
this
if it is a LuaBoolean
+LuaError
- if not a LuaBoolean
optboolean(boolean)
,
+TBOOLEAN
+public LuaClosure checkclosure()+
LuaClosure
,
+ or throw LuaError
if not
+
+ LuaClosure
is a subclass of that interprets lua bytecode.
+
+
this
cast as LuaClosure
+LuaError
- if not a LuaClosure
checkfunction()
,
+optclosure(LuaClosure)
,
+isclosure()
,
+TFUNCTION
+public double checkdouble()+
LuaError
if not numeric
+
+ Values that are LuaNumber
and values that are LuaString
+ that can be converted to a number will be converted to double.
+
+
LuaError
- if not a LuaNumber
or is a LuaString
that can't be converted to numbercheckint()
,
+checkinteger()
,
+checklong()
,
+optdouble(double)
,
+TNUMBER
+public LuaValue checkfunction()+
LuaError
if not
+
+ A function is considered anything whose type()
returns TFUNCTION
.
+ In practice it will be either a built-in Java function, typically deriving from
+ LuaFunction
or a LuaClosure
which represents lua source compiled
+ into lua bytecode.
+
+
this
if if a lua function or closure
+LuaError
- if not a functioncheckclosure()
+public int checkint()+
LuaError
if not numeric
+
+ Values that are LuaNumber
will be cast to int and may lose precision.
+ Values that are LuaString
that can be converted to a number will be converted,
+ then cast to int, so may also lose precision.
+
+
LuaError
- if not a LuaNumber
or is a LuaString
that can't be converted to numbercheckinteger()
,
+checklong()
,
+checkdouble()
,
+optint(int)
,
+TNUMBER
+public LuaInteger checkinteger()+
LuaError
if not numeric
+
+ Values that are LuaNumber
will be cast to int and may lose precision.
+ Values that are LuaString
that can be converted to a number will be converted,
+ then cast to int, so may also lose precision.
+
+
LuaInteger
if numeric
+LuaError
- if not a LuaNumber
or is a LuaString
that can't be converted to numbercheckint()
,
+checklong()
,
+checkdouble()
,
+optinteger(LuaInteger)
,
+TNUMBER
+public long checklong()+
LuaError
if not numeric
+
+ Values that are LuaNumber
will be cast to long and may lose precision.
+ Values that are LuaString
that can be converted to a number will be converted,
+ then cast to long, so may also lose precision.
+
+
LuaError
- if not a LuaNumber
or is a LuaString
that can't be converted to numbercheckint()
,
+checkinteger()
,
+checkdouble()
,
+optlong(long)
,
+TNUMBER
+public LuaNumber checknumber()+
LuaError
+
+ Values that are LuaString
that can be converted to a number will be converted and returned.
+
+
LuaNumber
if numeric
+LuaError
- if not a LuaNumber
or is a LuaString
that can't be converted to numbercheckint()
,
+checkinteger()
,
+checkdouble()
,
+checklong()
,
+optnumber(LuaNumber)
,
+TNUMBER
+public LuaNumber checknumber(java.lang.String msg)+
LuaError
+
+ Values that are LuaString
that can be converted to a number will be converted and returned.
+
+
msg
- String message to supply if conversion fails
+LuaNumber
if numeric
+LuaError
- if not a LuaNumber
or is a LuaString
that can't be converted to numbercheckint()
,
+checkinteger()
,
+checkdouble()
,
+checklong()
,
+optnumber(LuaNumber)
,
+TNUMBER
+public java.lang.String checkjstring()+
+ The string representations here will roughly match what is produced by the + C lua distribution, however hash codes have no relationship, + and there may be differences in number formatting. +
+
checkstring()
,
+optjstring(String)
,
+tojstring()
,
+isstring()
,
+TSTRING
+public LuaString checkstring()+
LuaError
if it is not.
+
+ In lua all numbers are strings, so this will succeed for
+ anything that derives from LuaString
or LuaNumber
.
+ Numbers will be converted to LuaString
.
+
+
LuaString
representation of the value if it is a LuaString
or LuaNumber
+LuaError
- if this
is not a LuaTable
checkjstring()
,
+optstring(LuaString)
,
+tostring()
,
+isstring()
,
+TSTRING
+public LuaTable checktable()+
LuaTable
, or throw LuaError
if it is not
++
this
if it is a LuaTable
+LuaError
- if this
is not a LuaTable
istable()
,
+opttable(LuaTable)
,
+TTABLE
+public LuaThread checkthread()+
LuaThread
, or throw LuaError
if it is not
++
this
if it is a LuaThread
+LuaError
- if this
is not a LuaThread
isthread()
,
+optthread(LuaThread)
,
+TTHREAD
+public java.lang.Object checkuserdata()+
LuaUserdata
, or throw LuaError
if it is not
++
this
if it is a LuaUserdata
+LuaError
- if this
is not a LuaUserdata
isuserdata()
,
+optuserdata(Object)
,
+checkuserdata(Class)
,
+TUSERDATA
+public java.lang.Object checkuserdata(java.lang.Class c)+
LuaUserdata
, or throw LuaError
if it is not
++
this
if it is a LuaUserdata
+LuaError
- if this
is not a LuaUserdata
isuserdata(Class)
,
+optuserdata(Class, Object)
,
+checkuserdata()
,
+TUSERDATA
+public LuaValue checknotnil()+
NIL
, or throw LuaError
if it is
++
this
if it is not NIL
+LuaError
- if this
is NIL
optvalue(LuaValue)
+public LuaValue checkvalidkey()+
LuaError
if not
++
this
if valid as a table key
+LuaError
- if not valid as a table keyisnil()
,
+isinttype()
+public static LuaValue error(java.lang.String message)+
LuaError
with a particular message
++
message
- String providing message details
+LuaError
- in all cases+public static void assert_(boolean b, + java.lang.String msg)+
LuaError
if not
++
b
- condition to test
+LuaError
- if b is not true+protected LuaValue argerror(java.lang.String expected)+
LuaError
indicating an invalid argument was supplied to a function
++
expected
- String naming the type that was expected
+LuaError
- in all cases+public static LuaValue argerror(int iarg, + java.lang.String msg)+
LuaError
indicating an invalid argument was supplied to a function
++
iarg
- index of the argument that was invalid, first index is 1msg
- String providing information about the invalid argument
+LuaError
- in all cases+protected LuaValue typerror(java.lang.String expected)+
LuaError
indicating an invalid type was supplied to a function
++
expected
- String naming the type that was expected
+LuaError
- in all cases+protected LuaValue unimplemented(java.lang.String fun)+
LuaError
indicating an operation is not implemented
++
LuaError
- in all cases+protected LuaValue illegal(java.lang.String op, + java.lang.String typename)+
LuaError
indicating an illegal operation occurred,
+ typically involved in managing weak references
++
LuaError
- in all cases+protected LuaValue lenerror()+
LuaError
based on the len operator,
+ typically due to an invalid operand type
++
LuaError
- in all cases+protected LuaValue aritherror()+
LuaError
based on an arithmetic error such as add, or pow,
+ typically due to an invalid operand type
++
LuaError
- in all cases+protected LuaValue aritherror(java.lang.String fun)+
LuaError
based on an arithmetic error such as add, or pow,
+ typically due to an invalid operand type
++
fun
- String description of the function that was attempted
+LuaError
- in all cases+protected LuaValue compareerror(java.lang.String rhs)+
LuaError
based on a comparison error such as greater-than or less-than,
+ typically due to an invalid operand type
++
rhs
- String description of what was on the right-hand-side of the comparison that resulted in the error.
+LuaError
- in all cases+protected LuaValue compareerror(LuaValue rhs)+
LuaError
based on a comparison error such as greater-than or less-than,
+ typically due to an invalid operand type
++
rhs
- Right-hand-side of the comparison that resulted in the error.
+LuaError
- in all cases+public LuaValue get(LuaValue key)+
INDEX
.
++
key
- the key to look up, must not be NIL
or null
+LuaValue
for that key, or NIL
if not found and no metatag
+LuaError
- if this
is not a table,
+ or there is no INDEX
metatag,
+ or key is NIL
get(int)
,
+get(String)
,
+rawget(LuaValue)
+public LuaValue get(int key)+
INDEX
.
++
key
- the key to look up
+LuaValue
for that key, or NIL
if not found
+LuaError
- if this
is not a table,
+ or there is no INDEX
metatagget(LuaValue)
,
+rawget(int)
+public LuaValue get(java.lang.String key)+
INDEX
.
++
key
- the key to look up, must not be null
+LuaValue
for that key, or NIL
if not found
+LuaError
- if this
is not a table,
+ or there is no INDEX
metatagget(LuaValue)
,
+rawget(String)
+public void set(LuaValue key, + LuaValue value)+
NEWINDEX
.
++
key
- the key to use, must not be NIL
or nullvalue
- the value to use, can be NIL
, must not be null
+LuaError
- if this
is not a table,
+ or key is NIL
,
+ or there is no NEWINDEX
metatag+public void set(int key, + LuaValue value)+
NEWINDEX
.
++
key
- the key to usevalue
- the value to use, can be NIL
, must not be null
+LuaError
- if this
is not a table,
+ or there is no NEWINDEX
metatag+public void set(int key, + java.lang.String value)+
NEWINDEX
.
++
key
- the key to usevalue
- the value to use, must not be null
+LuaError
- if this
is not a table,
+ or there is no NEWINDEX
metatag+public void set(java.lang.String key, + LuaValue value)+
NEWINDEX
.
++
key
- the key to use, must not be NIL
or nullvalue
- the value to use, can be NIL
, must not be null
+LuaError
- if this
is not a table,
+ or there is no NEWINDEX
metatag+public void set(java.lang.String key, + double value)+
NEWINDEX
.
++
key
- the key to use, must not be nullvalue
- the value to use
+LuaError
- if this
is not a table,
+ or there is no NEWINDEX
metatag+public void set(java.lang.String key, + int value)+
NEWINDEX
.
++
key
- the key to use, must not be nullvalue
- the value to use
+LuaError
- if this
is not a table,
+ or there is no NEWINDEX
metatag+public void set(java.lang.String key, + java.lang.String value)+
NEWINDEX
.
++
key
- the key to use, must not be nullvalue
- the value to use, must not be null
+LuaError
- if this
is not a table,
+ or there is no NEWINDEX
metatag+public LuaValue rawget(LuaValue key)+
+
key
- the key to look up, must not be NIL
or null
+LuaValue
for that key, or NIL
if not found
+LuaError
- if this
is not a table, or key is NIL
+public LuaValue rawget(int key)+
+
key
- the key to look up
+LuaValue
for that key, or NIL
if not found
+LuaError
- if this
is not a table+public LuaValue rawget(java.lang.String key)+
+
key
- the key to look up, must not be null
+LuaValue
for that key, or NIL
if not found
+LuaError
- if this
is not a table+public void rawset(LuaValue key, + LuaValue value)+
+
key
- the key to use, must not be NIL
or nullvalue
- the value to use, can be NIL
, must not be null
+LuaError
- if this
is not a table, or key is NIL
+public void rawset(int key, + LuaValue value)+
+
key
- the key to usevalue
- the value to use, can be NIL
, must not be null
+LuaError
- if this
is not a table+public void rawset(int key, + java.lang.String value)+
+
key
- the key to usevalue
- the value to use, can be NIL
, must not be null
+LuaError
- if this
is not a table+public void rawset(java.lang.String key, + LuaValue value)+
+
key
- the key to use, must not be nullvalue
- the value to use, can be NIL
, must not be null
+LuaError
- if this
is not a table+public void rawset(java.lang.String key, + double value)+
+
key
- the key to use, must not be nullvalue
- the value to use
+LuaError
- if this
is not a table+public void rawset(java.lang.String key, + int value)+
+
key
- the key to use, must not be nullvalue
- the value to use
+LuaError
- if this
is not a table+public void rawset(java.lang.String key, + java.lang.String value)+
+
key
- the key to use, must not be nullvalue
- the value to use, must not be null
+LuaError
- if this
is not a table+public void rawsetlist(int key0, + Varargs values)+
+ Primarily used internally in response to a SETLIST bytecode. +
+
key0
- the first key to set in the tablevalues
- the list of values to set
+LuaError
- if this is not a table.+public void presize(int i)+
+ Primarily used internally in response to a SETLIST bytecode. +
+
i
- the number of array slots to preallocate in the table.
+LuaError
- if this is not a table.+public Varargs next(LuaValue index)+
this
is a table,
+ return NIL
if there are no more, or throw a LuaError
if not a table.
+ + To iterate over all key-value pairs in a table you can use +
LuaValue k = LuaValue.NIL;
+ while ( true ) {
+ Varargs n = table.next(k);
+ if ( (k = n.arg1()).isnil() )
+ break;
+ LuaValue v = n.arg(2)
+ process( k, v )
+ }
++
index
- LuaInteger
value identifying a key to start from,
+ or NIL
to start at the beginning
+Varargs
containing {key,value} for the next entry,
+ or NIL
if there are no more.
+LuaError
- if this
is not a table, or the supplied key is invalid.LuaTable
,
+#inext()
,
+valueOf(int)
,
+Varargs.arg1()
,
+Varargs.arg(int)
,
+isnil()
+public Varargs inext(LuaValue index)+
this
is a table,
+ return NIL
if there are no more, or throw a LuaError
if not a table.
+ + To iterate over integer keys in a table you can use +
LuaValue k = LuaValue.NIL;
+ while ( true ) {
+ Varargs n = table.inext(k);
+ if ( (k = n.arg1()).isnil() )
+ break;
+ LuaValue v = n.arg(2)
+ process( k, v )
+ }
+
++
index
- LuaInteger
value identifying a key to start from,
+ or NIL
to start at the beginning
+Varargs
containing (key,value)
for the next entry,
+ or NONE
if there are no more.
+LuaError
- if this
is not a table, or the supplied key is invalid.LuaTable
,
+#next()
,
+valueOf(int)
,
+Varargs.arg1()
,
+Varargs.arg(int)
,
+isnil()
+public LuaValue load(LuaValue library)+
this
+ and calling it, which should iniitalize the library instance and
+ install itself into this instance.
++
library
- The callable LuaValue
to load into this
+LuaValue
containing the result of the initialization call.+public LuaValue arg(int index)+
Varargs
+
arg
in class Varargs
index
- the index of the argument to get, 1 is the first argument
+Varargs.arg1()
,
+NIL
+public int narg()+
Varargs
+
narg
in class Varargs
+public LuaValue arg1()+
Varargs
+
arg1
in class Varargs
Varargs.arg(int)
,
+NIL
+public LuaValue getmetatable()+
LuaValue
+
+ For LuaTable
and LuaUserdata
instances,
+ the metatable returned is this instance metatable.
+ For all other types, the class metatable value will be returned.
+
+
LuaBoolean.s_metatable
,
+LuaNumber.s_metatable
,
+LuaNil.s_metatable
,
+LuaFunction.s_metatable
,
+LuaThread.s_metatable
+public LuaValue setmetatable(LuaValue metatable)+
LuaValue
+
+ For LuaTable
and LuaUserdata
instances, the metatable is per instance.
+ For all other types, there is one metatable per type that can be set directly from java
+
+
metatable
- LuaValue
instance to serve as the metatable, or null to reset it.
+this
to allow chaining of Java function callsLuaBoolean.s_metatable
,
+LuaNumber.s_metatable
,
+LuaNil.s_metatable
,
+LuaFunction.s_metatable
,
+LuaThread.s_metatable
+public LuaValue getfenv()+
+
LuaValue
currently set as the instances environent.+public void setfenv(LuaValue env)+
+ Typically the environment is created once per application via a platform
+ helper method such as JsePlatform.standardGlobals()
+ However, any object can serve as an environment if it contains suitable metatag
+ values to implement get(LuaValue)
to provide the environment values.
+
+
env
- LuaValue
(typically a LuaTable
) containing the environment.JmePlatform
,
+JsePlatform
+public LuaValue call()+
this
with 0 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use invoke()
instead.
+
+ To call this
as a method call, use method(LuaValue)
instead.
+
+
(this())
, or NIL
if there were none.
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call(LuaValue)
,
+call(LuaValue,LuaValue)
,
+call(LuaValue, LuaValue, LuaValue)
,
+invoke()
,
+method(String)
,
+method(LuaValue)
+public LuaValue call(LuaValue arg)+
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use invoke()
instead.
+
+ To call this
as a method call, use method(LuaValue)
instead.
+
+
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call()
,
+call(LuaValue,LuaValue)
,
+call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+method(String,LuaValue)
,
+method(LuaValue,LuaValue)
+public LuaValue call(LuaValue arg1, + LuaValue arg2)+
this
with 2 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use invoke()
instead.
+
+ To call this
as a method call, use method(LuaValue)
instead.
+
+
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called function
+(this(arg1,arg2))
, or NIL
if there were none.
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call()
,
+call(LuaValue)
,
+call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue)
,
+method(String,LuaValue,LuaValue)
,
+method(LuaValue,LuaValue,LuaValue)
+public LuaValue call(LuaValue arg1, + LuaValue arg2, + LuaValue arg3)+
this
with 3 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use invoke()
instead.
+
+ To call this
as a method call, use method(LuaValue)
instead.
+
+
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called functionarg3
- Second argument to supply to the called function
+(this(arg1,arg2,arg3))
, or NIL
if there were none.
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call()
,
+call(LuaValue)
,
+call(LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue, LuaValue)
,
+invokemethod(String,Varargs)
,
+invokemethod(LuaValue,Varargs)
+public LuaValue method(java.lang.String name)+
this
with 0 arguments, including metatag processing,
+ and return only the first return value.
+
+ Look up this[name]
and if it is a LuaFunction
,
+ call it inserting this
as an additional first argument.
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use invoke()
instead.
+
+ To call this
as a plain call, use call()
instead.
+
+
name
- Name of the method to look up for invocation
+this:name()
as a Varargs
instance
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call()
,
+invoke()
,
+method(LuaValue)
,
+method(String,LuaValue)
,
+method(String,LuaValue,LuaValue)
+public LuaValue method(LuaValue name)+
this
with 0 arguments, including metatag processing,
+ and return only the first return value.
+
+ Look up this[name]
and if it is a LuaFunction
,
+ call it inserting this
as an additional first argument,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use invoke()
instead.
+
+ To call this
as a plain call, use call()
instead.
+
+
name
- Name of the method to look up for invocation
+this:name()
as a Varargs
instance
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call()
,
+invoke()
,
+method(String)
,
+method(LuaValue,LuaValue)
,
+method(LuaValue,LuaValue,LuaValue)
+public LuaValue method(java.lang.String name, + LuaValue arg)+
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ Look up this[name]
and if it is a LuaFunction
,
+ call it inserting this
as an additional first argument,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use invoke()
instead.
+
+ To call this
as a plain call, use call(LuaValue)
instead.
+
+
name
- Name of the method to look up for invocationarg
- Argument to supply to the method
+this:name(arg)
as a Varargs
instance
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call(LuaValue)
,
+#invoke(LuaValue)
,
+method(LuaValue,LuaValue)
,
+method(String)
,
+method(String,LuaValue,LuaValue)
+public LuaValue method(LuaValue name, + LuaValue arg)+
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ Look up this[name]
and if it is a LuaFunction
,
+ call it inserting this
as an additional first argument,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use invoke()
instead.
+
+ To call this
as a plain call, use call(LuaValue)
instead.
+
+
name
- Name of the method to look up for invocationarg
- Argument to supply to the method
+this:name(arg)
as a Varargs
instance
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call(LuaValue)
,
+#invoke(LuaValue)
,
+method(String,LuaValue)
,
+method(LuaValue)
,
+method(LuaValue,LuaValue,LuaValue)
+public LuaValue method(java.lang.String name, + LuaValue arg1, + LuaValue arg2)+
this
with 2 arguments, including metatag processing,
+ and return only the first return value.
+
+ Look up this[name]
and if it is a LuaFunction
,
+ call it inserting this
as an additional first argument,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use invoke()
instead.
+
+ To call this
as a plain call, use call(LuaValue,LuaValue)
instead.
+
+
name
- Name of the method to look up for invocationarg1
- First argument to supply to the methodarg2
- Second argument to supply to the method
+this:name(arg1,arg2)
as a Varargs
instance
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call(LuaValue,LuaValue)
,
+invoke(LuaValue,Varargs)
,
+method(String,LuaValue)
,
+method(LuaValue,LuaValue,LuaValue)
+public LuaValue method(LuaValue name, + LuaValue arg1, + LuaValue arg2)+
this
with 2 arguments, including metatag processing,
+ and return only the first return value.
+
+ Look up this[name]
and if it is a LuaFunction
,
+ call it inserting this
as an additional first argument,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use invoke()
instead.
+
+ To call this
as a plain call, use call(LuaValue,LuaValue)
instead.
+
+
name
- Name of the method to look up for invocationarg1
- First argument to supply to the methodarg2
- Second argument to supply to the method
+this:name(arg1,arg2)
as a Varargs
instance
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call(LuaValue,LuaValue)
,
+invoke(LuaValue,Varargs)
,
+method(LuaValue,LuaValue)
,
+method(String,LuaValue,LuaValue)
+public Varargs invoke()+
this
with 0 arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ If this
is a LuaFunction
, call it, and return all values.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a method call, use invokemethod(LuaValue)
instead.
+
+
Varargs
instance.
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call()
,
+invoke(Varargs)
,
+invokemethod(String)
,
+invokemethod(LuaValue)
+public Varargs invoke(Varargs args)+
this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ If this
is a LuaFunction
, call it, and return all values.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a method call, use invokemethod(LuaValue)
instead.
+
+
args
- Varargs containing the arguments to supply to the called function
+Varargs
instance.
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
varargsOf(LuaValue[])
,
+call(LuaValue)
,
+invoke()
,
+invoke(LuaValue,Varargs)
,
+invokemethod(String,Varargs)
,
+invokemethod(LuaValue,Varargs)
+public Varargs invoke(LuaValue arg, + Varargs varargs)+
this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ If this
is a LuaFunction
, call it, and return all values.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a method call, use invokemethod(LuaValue,Varargs)
instead.
+
+
arg
- The first argument to supply to the called functionvarargs
- Varargs containing the remaining arguments to supply to the called function
+Varargs
instance.
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
varargsOf(LuaValue[])
,
+call(LuaValue,LuaValue)
,
+invoke(LuaValue,Varargs)
,
+invokemethod(String,Varargs)
,
+invokemethod(LuaValue,Varargs)
+public Varargs invoke(LuaValue arg1, + LuaValue arg2, + Varargs varargs)+
this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ If this
is a LuaFunction
, call it, and return all values.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a method call, use invokemethod(LuaValue,Varargs)
instead.
+
+
arg1
- The first argument to supply to the called functionarg2
- The second argument to supply to the called functionvarargs
- Varargs containing the remaining arguments to supply to the called function
+Varargs
instance.
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
varargsOf(LuaValue[])
,
+call(LuaValue,LuaValue,LuaValue)
,
+invoke(LuaValue,LuaValue,Varargs)
,
+invokemethod(String,Varargs)
,
+invokemethod(LuaValue,Varargs)
+public Varargs invoke(LuaValue[] args)+
this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ If this
is a LuaFunction
, call it, and return all values.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a method call, use invokemethod(LuaValue,Varargs)
instead.
+
+
args
- Array of arguments to supply to the called function
+Varargs
instance.
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
varargsOf(LuaValue[])
,
+call(LuaValue,LuaValue,LuaValue)
,
+invoke(LuaValue,LuaValue,Varargs)
,
+invokemethod(String,LuaValue[])
,
+invokemethod(LuaValue,LuaValue[])
+public Varargs invoke(LuaValue[] args, + Varargs varargs)+
this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ If this
is a LuaFunction
, call it, and return all values.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a method call, use invokemethod(LuaValue,Varargs)
instead.
+
+
args
- Array of arguments to supply to the called functionvarargs
- Varargs containing additional arguments to supply to the called function
+Varargs
instance.
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
varargsOf(LuaValue[])
,
+call(LuaValue,LuaValue,LuaValue)
,
+invoke(LuaValue,LuaValue,Varargs)
,
+invokemethod(String,LuaValue[])
,
+invokemethod(LuaValue,LuaValue[])
,
+invokemethod(String,Varargs)
,
+invokemethod(LuaValue,Varargs)
+public Varargs invokemethod(java.lang.String name)+
this
with 0 arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ Look up this[name]
and if it is a LuaFunction
,
+ call it inserting this
as an additional first argument,
+ and return all return values as a Varargs
instance.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a plain call, use invoke()
instead.
+
+
name
- Name of the method to look up for invocation
+this:name()
as a Varargs
instance
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call()
,
+invoke()
,
+method(String)
,
+invokemethod(LuaValue)
,
+#invokemethod(String,LuaValue)
+public Varargs invokemethod(LuaValue name)+
this
with 0 arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ Look up this[name]
and if it is a LuaFunction
,
+ call it inserting this
as an additional first argument,
+ and return all return values as a Varargs
instance.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a plain call, use invoke()
instead.
+
+
name
- Name of the method to look up for invocation
+this:name()
as a Varargs
instance
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call()
,
+invoke()
,
+method(LuaValue)
,
+invokemethod(String)
,
+#invokemethod(LuaValue,LuaValue)
+public Varargs invokemethod(java.lang.String name, + Varargs args)+
this
with 1 argument, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ Look up this[name]
and if it is a LuaFunction
,
+ call it inserting this
as an additional first argument,
+ and return all return values as a Varargs
instance.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a plain call, use invoke(Varargs)
instead.
+
+
name
- Name of the method to look up for invocationargs
- Varargs
containing arguments to supply to the called function after this
+this:name(args)
as a Varargs
instance
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call()
,
+invoke(Varargs)
,
+method(String)
,
+invokemethod(LuaValue,Varargs)
,
+invokemethod(String,LuaValue[])
+public Varargs invokemethod(LuaValue name, + Varargs args)+
this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ Look up this[name]
and if it is a LuaFunction
,
+ call it inserting this
as an additional first argument,
+ and return all return values as a Varargs
instance.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a plain call, use invoke(Varargs)
instead.
+
+
name
- Name of the method to look up for invocationargs
- Varargs
containing arguments to supply to the called function after this
+this:name(args)
as a Varargs
instance
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call()
,
+invoke(Varargs)
,
+method(String)
,
+invokemethod(String,Varargs)
,
+invokemethod(LuaValue,LuaValue[])
+public Varargs invokemethod(java.lang.String name, + LuaValue[] args)+
this
with 1 argument, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ Look up this[name]
and if it is a LuaFunction
,
+ call it inserting this
as an additional first argument,
+ and return all return values as a Varargs
instance.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a plain call, use invoke(Varargs)
instead.
+
+
name
- Name of the method to look up for invocationargs
- Array of LuaValue
containing arguments to supply to the called function after this
+this:name(args)
as a Varargs
instance
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call()
,
+invoke(Varargs)
,
+method(String)
,
+invokemethod(LuaValue,LuaValue[])
,
+invokemethod(String,Varargs)
,
+varargsOf(LuaValue[])
+public Varargs invokemethod(LuaValue name, + LuaValue[] args)+
this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ Look up this[name]
and if it is a LuaFunction
,
+ call it inserting this
as an additional first argument,
+ and return all return values as a Varargs
instance.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a plain call, use invoke(Varargs)
instead.
+
+
name
- Name of the method to look up for invocationargs
- Array of LuaValue
containing arguments to supply to the called function after this
+this:name(args)
as a Varargs
instance
+LuaError
- if not a function and CALL
is not defined,
+ or the invoked function throws a LuaError
+ or the invoked closure throw a lua error
call()
,
+invoke(Varargs)
,
+method(String)
,
+invokemethod(String,LuaValue[])
,
+invokemethod(LuaValue,Varargs)
,
+varargsOf(LuaValue[])
+protected LuaValue callmt()+
CALL
metatag, if it exists.
++
LuaValue
value if metatag is defined
+LuaError
- if CALL
metatag is not defined.+public LuaValue not()+
(~this)
as defined by lua not operator
++
TRUE
if NIL
or FALSE
, otherwise FALSE
+public LuaValue neg()+
(-this)
as defined by lua unary minus operator
++
LuaBoolean
if boolean or nil,
+ numeric inverse as if numeric,
+ or metatag processing result if UNM
metatag is defined
+LuaError
- if this
is not a table or string, and has no UNM
metatag+public LuaValue len()+
(#this)
including metatag processing as java int
++
LuaError
- if this
is not a table or string, and has no LEN
metatag+public int length()+
(#this)
including metatag processing as java int
++
toint()
+LuaError
- if this
is not a table or string, and has no LEN
metatag+public LuaValue getn()+
+
this
is a LuaTable
+LuaError
- if this
is not a LuaTable
+public boolean equals(java.lang.Object obj)+
equals
in class java.lang.Object
+public LuaValue eq(LuaValue val)+
EQ
.
++
val
- The value to compare with.
+TRUE
if values are comparable and (this == rhs)
,
+ FALSE
if comparable but not equal,
+ LuaValue
if metatag processing occurs.eq_b(LuaValue)
,
+raweq(LuaValue)
,
+neq(LuaValue)
,
+eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
,
+EQ
+public boolean eq_b(LuaValue val)+
EQ
,
+ and return java boolean
++
val
- The value to compare with.
+(this == rhs)
,
+ false if comparable but not equal,
+ result converted to java boolean if metatag processing occurs.eq(LuaValue)
,
+raweq(LuaValue)
,
+neq_b(LuaValue)
,
+eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
,
+EQ
+public LuaValue neq(LuaValue val)+
EQ
.
++
val
- The value to compare with.
+TRUE
if values are comparable and (this != rhs)
,
+ FALSE
if comparable but equal,
+ inverse of LuaValue
converted to LuaBoolean
if metatag processing occurs.eq(LuaValue)
,
+raweq(LuaValue)
,
+eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
,
+EQ
+public boolean neq_b(LuaValue val)+
EQ
.
++
val
- The value to compare with.
+(this != rhs)
,
+ false if comparable but equal,
+ inverse of result converted to boolean if metatag processing occurs.eq_b(LuaValue)
,
+raweq(LuaValue)
,
+eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
,
+EQ
+public boolean raweq(LuaValue val)+
+
val
- The value to compare with.
+(this == rhs)
, false otherwiseeq(LuaValue)
,
+raweq(LuaUserdata)
,
+raweq(LuaString)
,
+raweq(double)
,
+raweq(int)
,
+EQ
+public boolean raweq(LuaUserdata val)+
LuaUserdata
value
+ without metatag processing.
++
val
- The LuaUserdata
to compare with.
+this
is userdata
+ and their metatables are the same using ==
+ and their instances are equal using equals(Object)
,
+ otherwise falseeq(LuaValue)
,
+raweq(LuaValue)
+public boolean raweq(LuaString val)+
LuaString
value
+ without metatag processing.
++
val
- The LuaString
to compare with.
+this
is a LuaString
+ and their byte sequences match,
+ otherwise false+public boolean raweq(double val)+
+
val
- The double value to compare with.
+this
is a LuaNumber
+ whose value equals val,
+ otherwise false+public boolean raweq(int val)+
+
val
- The double value to compare with.
+this
is a LuaNumber
+ whose value equals val,
+ otherwise false+public static final boolean eqmtcall(LuaValue lhs, + LuaValue lhsmt, + LuaValue rhs, + LuaValue rhsmt)+
+
lhs
- left-hand-side of equality expressionlhsmt
- metatag value for left-hand-siderhs
- right-hand-side of equality expressionrhsmt
- metatag value for right-hand-side
+NIL
or FALSE
+LuaError
- if metatag was not defined for either operandequals(Object)
,
+eq(LuaValue)
,
+raweq(LuaValue)
,
+EQ
+public LuaValue add(LuaValue rhs)+
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
rhs
- The right-hand-side value to perform the add with
+(this + rhs)
if both are numeric,
+ or LuaValue
if metatag processing occurs
+LuaError
- if either operand is not a number or string convertible to number,
+ and neither has the ADD
metatag definedarithmt(LuaValue, LuaValue)
+public LuaValue add(double rhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
rhs
- The right-hand-side value to perform the add with
+(this + rhs)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numberadd(LuaValue)
+public LuaValue add(int rhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
rhs
- The right-hand-side value to perform the add with
+(this + rhs)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numberadd(LuaValue)
+public LuaValue sub(LuaValue rhs)+
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
rhs
- The right-hand-side value to perform the subtract with
+(this - rhs)
if both are numeric,
+ or LuaValue
if metatag processing occurs
+LuaError
- if either operand is not a number or string convertible to number,
+ and neither has the SUB
metatag definedarithmt(LuaValue, LuaValue)
+public LuaValue sub(double rhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
rhs
- The right-hand-side value to perform the subtract with
+(this - rhs)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numbersub(LuaValue)
+public LuaValue sub(int rhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
rhs
- The right-hand-side value to perform the subtract with
+(this - rhs)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numbersub(LuaValue)
+public LuaValue subFrom(double lhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
lhs
- The left-hand-side value from which to perform the subtraction
+(lhs - this)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numbersub(LuaValue)
,
+sub(double)
,
+sub(int)
+public LuaValue subFrom(int lhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing sub(LuaValue)
must be used
+
+
lhs
- The left-hand-side value from which to perform the subtraction
+(lhs - this)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numbersub(LuaValue)
,
+sub(double)
,
+sub(int)
+public LuaValue mul(LuaValue rhs)+
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
rhs
- The right-hand-side value to perform the multiply with
+(this * rhs)
if both are numeric,
+ or LuaValue
if metatag processing occurs
+LuaError
- if either operand is not a number or string convertible to number,
+ and neither has the MUL
metatag definedarithmt(LuaValue, LuaValue)
+public LuaValue mul(double rhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
rhs
- The right-hand-side value to perform the multiply with
+(this * rhs)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numbermul(LuaValue)
+public LuaValue mul(int rhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
rhs
- The right-hand-side value to perform the multiply with
+(this * rhs)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numbermul(LuaValue)
+public LuaValue pow(LuaValue rhs)+
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
rhs
- The power to raise this value to
+(this ^ rhs)
if both are numeric,
+ or LuaValue
if metatag processing occurs
+LuaError
- if either operand is not a number or string convertible to number,
+ and neither has the POW
metatag definedarithmt(LuaValue, LuaValue)
+public LuaValue pow(double rhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
rhs
- The power to raise this value to
+(this ^ rhs)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numberpow(LuaValue)
+public LuaValue pow(int rhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
rhs
- The power to raise this value to
+(this ^ rhs)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numberpow(LuaValue)
+public LuaValue powWith(double lhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
lhs
- The left-hand-side value which will be raised to this power
+(lhs ^ this)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numberpow(LuaValue)
,
+pow(double)
,
+pow(int)
+public LuaValue powWith(int lhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
lhs
- The left-hand-side value which will be raised to this power
+(lhs ^ this)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numberpow(LuaValue)
,
+pow(double)
,
+pow(int)
+public LuaValue div(LuaValue rhs)+
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
rhs
- The right-hand-side value to perform the divulo with
+(this / rhs)
if both are numeric,
+ or LuaValue
if metatag processing occurs
+LuaError
- if either operand is not a number or string convertible to number,
+ and neither has the DIV
metatag definedarithmt(LuaValue, LuaValue)
+public LuaValue div(double rhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing div(LuaValue)
must be used
+
+
rhs
- The right-hand-side value to perform the divulo with
+(this / rhs)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numberdiv(LuaValue)
+public LuaValue div(int rhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing div(LuaValue)
must be used
+
+
rhs
- The right-hand-side value to perform the divulo with
+(this / rhs)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numberdiv(LuaValue)
+public LuaValue divInto(double lhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
lhs
- The left-hand-side value which will be divided by this
+(lhs / this)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numberdiv(LuaValue)
,
+div(double)
,
+div(int)
+public LuaValue mod(LuaValue rhs)+
+ Each operand must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
rhs
- The right-hand-side value to perform the modulo with
+(this % rhs)
if both are numeric,
+ or LuaValue
if metatag processing occurs
+LuaError
- if either operand is not a number or string convertible to number,
+ and neither has the MOD
metatag definedarithmt(LuaValue, LuaValue)
+public LuaValue mod(double rhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing mod(LuaValue)
must be used
+
+
rhs
- The right-hand-side value to perform the modulo with
+(this % rhs)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numbermod(LuaValue)
+public LuaValue mod(int rhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+ For metatag processing mod(LuaValue)
must be used
+
+
rhs
- The right-hand-side value to perform the modulo with
+(this % rhs)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numbermod(LuaValue)
+public LuaValue modFrom(double lhs)+
+ this
must derive from LuaNumber
+ or derive from LuaString
and be convertible to a number
+
+
lhs
- The left-hand-side value which will be modulo'ed by this
+(lhs % this)
if this is numeric
+LuaError
- if this
is not a number or string convertible to numbermod(LuaValue)
,
+mod(double)
,
+mod(int)
+protected LuaValue arithmt(LuaValue tag, + LuaValue op2)+
+ Finds the supplied metatag value for this
or op2
and invokes it,
+ or throws LuaError
if neither is defined.
+
+
tag
- The metatag to look upop2
- The other operand value to perform the operation with
+LuaValue
resulting from metatag processing
+LuaError
- if metatag was not defined for either operandadd(LuaValue)
,
+sub(LuaValue)
,
+mul(LuaValue)
,
+pow(LuaValue)
,
+div(LuaValue)
,
+mod(LuaValue)
,
+ADD
,
+SUB
,
+MUL
,
+POW
,
+DIV
,
+MOD
+protected LuaValue arithmtwith(LuaValue tag, + double op1)+
+ Finds the supplied metatag value for this
and invokes it,
+ or throws LuaError
if neither is defined.
+
+
tag
- The metatag to look upop1
- The value of the left-hand-side to perform the operation with
+LuaValue
resulting from metatag processing
+LuaError
- if metatag was not defined for either operandadd(LuaValue)
,
+sub(LuaValue)
,
+mul(LuaValue)
,
+pow(LuaValue)
,
+div(LuaValue)
,
+mod(LuaValue)
,
+ADD
,
+SUB
,
+MUL
,
+POW
,
+DIV
,
+MOD
+public LuaValue lt(LuaValue rhs)+
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this < rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occurs
+LuaError
- if either both operands are not a strings or both are not numbers
+ and no LT
metatag is defined.gteq_b(LuaValue)
,
+comparemt(LuaValue, LuaValue)
+public LuaValue lt(double rhs)+
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this < rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occurs
+LuaError
- if this is not a number
+ and no LT
metatag is defined.gteq_b(double)
,
+comparemt(LuaValue, LuaValue)
+public LuaValue lt(int rhs)+
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this < rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occurs
+LuaError
- if this is not a number
+ and no LT
metatag is defined.gteq_b(int)
,
+comparemt(LuaValue, LuaValue)
+public boolean lt_b(LuaValue rhs)+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+(this < rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.
+LuaError
- if either both operands are not a strings or both are not numbers
+ and no LT
metatag is defined.gteq(LuaValue)
,
+comparemt(LuaValue, LuaValue)
+public boolean lt_b(int rhs)+
+ To be comparable, this must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+(this < rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.
+LuaError
- if this is not a number
+ and no LT
metatag is defined.gteq(int)
,
+comparemt(LuaValue, LuaValue)
+public boolean lt_b(double rhs)+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+(this < rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.
+LuaError
- if either both operands are not a strings or both are not numbers
+ and no LT
metatag is defined.gteq(LuaValue)
,
+comparemt(LuaValue, LuaValue)
+public LuaValue lteq(LuaValue rhs)+
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this <= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occurs
+LuaError
- if either both operands are not a strings or both are not numbers
+ and no LE
metatag is defined.gteq_b(LuaValue)
,
+comparemt(LuaValue, LuaValue)
+public LuaValue lteq(double rhs)+
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this <= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occurs
+LuaError
- if this is not a number
+ and no LE
metatag is defined.gteq_b(double)
,
+comparemt(LuaValue, LuaValue)
+public LuaValue lteq(int rhs)+
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this <= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occurs
+LuaError
- if this is not a number
+ and no LE
metatag is defined.gteq_b(int)
,
+comparemt(LuaValue, LuaValue)
+public boolean lteq_b(LuaValue rhs)+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+(this <= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.
+LuaError
- if either both operands are not a strings or both are not numbers
+ and no LE
metatag is defined.gteq(LuaValue)
,
+comparemt(LuaValue, LuaValue)
+public boolean lteq_b(int rhs)+
+ To be comparable, this must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+(this <= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.
+LuaError
- if this is not a number
+ and no LE
metatag is defined.gteq(int)
,
+comparemt(LuaValue, LuaValue)
+public boolean lteq_b(double rhs)+
+ To be comparable, this must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+(this <= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.
+LuaError
- if this is not a number
+ and no LE
metatag is defined.gteq(double)
,
+comparemt(LuaValue, LuaValue)
+public LuaValue gt(LuaValue rhs)+
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this > rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occurs
+LuaError
- if either both operands are not a strings or both are not numbers
+ and no LE
metatag is defined.gteq_b(LuaValue)
,
+comparemt(LuaValue, LuaValue)
+public LuaValue gt(double rhs)+
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this > rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occurs
+LuaError
- if this is not a number
+ and no LE
metatag is defined.gteq_b(double)
,
+comparemt(LuaValue, LuaValue)
+public LuaValue gt(int rhs)+
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this > rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occurs
+LuaError
- if this is not a number
+ and no LE
metatag is defined.gteq_b(int)
,
+comparemt(LuaValue, LuaValue)
+public boolean gt_b(LuaValue rhs)+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+(this > rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.
+LuaError
- if either both operands are not a strings or both are not numbers
+ and no LE
metatag is defined.gteq(LuaValue)
,
+comparemt(LuaValue, LuaValue)
+public boolean gt_b(int rhs)+
+ To be comparable, this must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+(this > rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.
+LuaError
- if this is not a number
+ and no LE
metatag is defined.gteq(int)
,
+comparemt(LuaValue, LuaValue)
+public boolean gt_b(double rhs)+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+(this > rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.
+LuaError
- if either both operands are not a strings or both are not numbers
+ and no LE
metatag is defined.gteq(LuaValue)
,
+comparemt(LuaValue, LuaValue)
+public LuaValue gteq(LuaValue rhs)+
LuaValue
.
+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this >= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occurs
+LuaError
- if either both operands are not a strings or both are not numbers
+ and no LT
metatag is defined.gteq_b(LuaValue)
,
+comparemt(LuaValue, LuaValue)
+public LuaValue gteq(double rhs)+
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this >= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occurs
+LuaError
- if this is not a number
+ and no LT
metatag is defined.gteq_b(double)
,
+comparemt(LuaValue, LuaValue)
+public LuaValue gteq(int rhs)+
LuaValue
.
+
+ To be comparable, this must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+TRUE
if (this >= rhs)
, FALSE
if not,
+ or LuaValue
if metatag processing occurs
+LuaError
- if this is not a number
+ and no LT
metatag is defined.gteq_b(int)
,
+comparemt(LuaValue, LuaValue)
+public boolean gteq_b(LuaValue rhs)+
+ To be comparable, both operands must derive from LuaString
+ or both must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+(this >= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.
+LuaError
- if either both operands are not a strings or both are not numbers
+ and no LT
metatag is defined.gteq(LuaValue)
,
+comparemt(LuaValue, LuaValue)
+public boolean gteq_b(int rhs)+
+ To be comparable, this must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+(this >= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.
+LuaError
- if this is not a number
+ and no LT
metatag is defined.gteq(int)
,
+comparemt(LuaValue, LuaValue)
+public boolean gteq_b(double rhs)+
+ To be comparable, this must derive from LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+(this >= rhs)
, false if not,
+ and boolean interpreation of result if metatag processing occurs.
+LuaError
- if this is not a number
+ and no LT
metatag is defined.gteq(double)
,
+comparemt(LuaValue, LuaValue)
+public LuaValue comparemt(LuaValue tag, + LuaValue op1)+
+ Finds the supplied metatag value and invokes it,
+ or throws LuaError
if none applies.
+
+
tag
- The metatag to look uprhs
- The right-hand-side value to perform the operation with
+LuaValue
resulting from metatag processing
+LuaError
- if metatag was not defined for either operand,
+ or if the operands are not the same type,
+ or the metatag values for the two operands are different.gt(LuaValue)
,
+gteq(LuaValue)
,
+lt(LuaValue)
,
+lteq(LuaValue)
+public int strcmp(LuaValue rhs)+
+ Only strings can be compared, meaning
+ each operand must derive from LuaString
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+LuaError
- if either operand is not a string+public int strcmp(LuaString rhs)+
LuaString
+ using string comparison based on byte values.
+
+ Only strings can be compared, meaning
+ each operand must derive from LuaString
.
+
+
rhs
- The right-hand-side value to perform the comparison with
+LuaError
- if this is not a string+public LuaValue concat(LuaValue rhs)+
+ Only strings and numbers as represented can be concatenated, meaning
+ each operand must derive from LuaString
or LuaNumber
.
+
+
rhs
- The right-hand-side value to perform the operation with
+LuaError
- if either operand is not of an appropriate type,
+ such as nil or a table+public LuaValue concatTo(LuaValue lhs)+
+ Only strings and numbers as represented can be concatenated, meaning
+ each operand must derive from LuaString
or LuaNumber
.
+
+
lhs
- The left-hand-side value onto which this will be concatenated
+LuaError
- if either operand is not of an appropriate type,
+ such as nil or a tableconcat(LuaValue)
+public LuaValue concatTo(LuaNumber lhs)+
LuaNumber
+ and return the result using rules of lua string concatenation including
+ metatag processing.
+
+ Only strings and numbers as represented can be concatenated, meaning
+ each operand must derive from LuaString
or LuaNumber
.
+
+
lhs
- The left-hand-side value onto which this will be concatenated
+LuaError
- if either operand is not of an appropriate type,
+ such as nil or a tableconcat(LuaValue)
+public LuaValue concatTo(LuaString lhs)+
LuaString
+ and return the result using rules of lua string concatenation including
+ metatag processing.
+
+ Only strings and numbers as represented can be concatenated, meaning
+ each operand must derive from LuaString
or LuaNumber
.
+
+
lhs
- The left-hand-side value onto which this will be concatenated
+LuaError
- if either operand is not of an appropriate type,
+ such as nil or a tableconcat(LuaValue)
+public Buffer buffer()+
Buffer
for more efficient concatenation of
+ multiple strings.
++
+public Buffer concat(Buffer rhs)+
Buffer
onto this value and return the result
+ using rules of lua string concatenation including metatag processing.
+
+ Only strings and numbers as represented can be concatenated, meaning
+ each operand must derive from LuaString
or LuaNumber
.
+
+
rhs
- The right-hand-side Buffer
to perform the operation with
+(this .. rhs)
+LuaError
- if either operand is not of an appropriate type,
+ such as nil or a table+public LuaValue concatmt(LuaValue rhs)+
+ Finds the CONCAT
metatag value and invokes it,
+ or throws LuaError
if it doesn't exist.
+
+
rhs
- The right-hand-side value to perform the operation with
+LuaValue
resulting from metatag processing for CONCAT
metatag.
+LuaError
- if metatag was not defined for either operand+public LuaValue and(LuaValue rhs)+
and
with another operand, based on lua rules for boolean evaluation.
+ This returns either this
or rhs
depending on the boolean value for this
.
++
rhs
- The right-hand-side value to perform the operation with
+this
if this.toboolean()
is false, rhs
otherwise.+public LuaValue or(LuaValue rhs)+
or
with another operand, based on lua rules for boolean evaluation.
+ This returns either this
or rhs
depending on the boolean value for this
.
++
rhs
- The right-hand-side value to perform the operation with
+this
if this.toboolean()
is true, rhs
otherwise.+public boolean testfor_b(LuaValue limit, + LuaValue step)+
+ Used in lua-bytecode to Java-bytecode conversion. +
+
limit
- the numerical limit to complete the for loopstep
- the numberical step size to use.
++public LuaString strvalue()+
LuaString
or LuaNumber
,
+ or throw a LuaError
if it is not
++
LuaString
corresponding to the value if a string or number
+LuaError
- if not a string or number+public LuaValue strongkey()+
NIL
if it was weak and is no longer referenced.
++
LuaValue
key, or NIL
if it was weak and is no longer referenced.WeakTable
+public LuaValue strongvalue()+
NIL
if it was weak and is no longer referenced.
++
LuaValue
referred to, or NIL
if it was weak and is no longer referenced.WeakTable
+public boolean isweaknil()+
+
WeakTable
+public static LuaBoolean valueOf(boolean b)+
LuaValue
.
++
b
- boolean value to convert
+TRUE
if not or FALSE
if false+public static LuaInteger valueOf(int i)+
LuaValue
.
++
i
- int value to convert
+LuaInteger
instance, possibly pooled, whose value is i+public static LuaNumber valueOf(double d)+
LuaValue
.
+ This may return a LuaInteger
or LuaDouble
depending
+ on the value supplied.
++
d
- double value to convert
+LuaNumber
instance, possibly pooled, whose value is d+public static LuaString valueOf(java.lang.String s)+
LuaValue
.
++
s
- String value to convert
+LuaString
instance, possibly pooled, whose value is s+public static LuaString valueOf(byte[] bytes)+
LuaValue
.
++
bytes
- byte array to convert
+LuaString
instance, possibly pooled, whose bytes are those in the supplied array+public static LuaString valueOf(byte[] bytes, + int off, + int len)+
LuaValue
.
++
bytes
- byte array to convertoff
- offset into the byte array, starting at 0len
- number of bytes to include in the LuaString
+LuaString
instance, possibly pooled, whose bytes are those in the supplied array+public static LuaTable tableOf()+
LuaTable
.
++
LuaTable
instance with no values and no metatable.+public static LuaTable tableOf(Varargs varargs, + int firstarg)+
LuaTable
initialized with supplied array values.
++
varargs
- Varargs
containing the values to use in initializationfirstarg
- the index of the first argument to use from the varargs, 1 being the first.
+LuaTable
instance with sequential elements coming from the varargs.+public static LuaTable tableOf(int narray, + int nhash)+
LuaTable
preallocated to hold array and hashed elements
++
narray
- Number of array elements to preallocatenhash
- Number of hash elements to preallocate
+LuaTable
instance with no values and no metatable, but preallocated for array and hashed elements.+public static LuaTable listOf(LuaValue[] unnamedValues)+
LuaTable
initialized with supplied array values.
++
unnamedValues
- array of LuaValue
containing the values to use in initialization
+LuaTable
instance with sequential elements coming from the array.+public static LuaTable listOf(LuaValue[] unnamedValues, + Varargs lastarg)+
LuaTable
initialized with supplied array values.
++
unnamedValues
- array of LuaValue
containing the first values to use in initializationlastarg
- Varargs
containing additional values to use in initialization
+ to be put after the last unnamedValues element
+LuaTable
instance with sequential elements coming from the array and varargs.+public static LuaTable tableOf(LuaValue[] namedValues)+
LuaTable
initialized with supplied named values.
++
namedValues
- array of LuaValue
containing the keys and values to use in initialization
+ in order {key-a, value-a, key-b, value-b, ...}
+LuaTable
instance with non-sequential keys coming from the supplied array.+public static LuaTable tableOf(LuaValue[] namedValues, + LuaValue[] unnamedValues)+
LuaTable
initialized with supplied named values and sequential elements.
+ The named values will be assigned first, and the sequential elements will be assigned later,
+ possibly overwriting named values at the same slot if there are conflicts.
++
namedValues
- array of LuaValue
containing the keys and values to use in initialization
+ in order {key-a, value-a, key-b, value-b, ...}
unnamedValues
- array of LuaValue
containing the sequenctial elements to use in initialization
+ in order {value-1, value-2, ...}
, or null if there are none
+LuaTable
instance with named and sequential values supplied.+public static LuaTable tableOf(LuaValue[] namedValues, + LuaValue[] unnamedValues, + Varargs lastarg)+
LuaTable
initialized with supplied named values and sequential elements in an array part and as varargs.
+ The named values will be assigned first, and the sequential elements will be assigned later,
+ possibly overwriting named values at the same slot if there are conflicts.
++
namedValues
- array of LuaValue
containing the keys and values to use in initialization
+ in order {key-a, value-a, key-b, value-b, ...}
unnamedValues
- array of LuaValue
containing the first sequenctial elements to use in initialization
+ in order {value-1, value-2, ...}
, or null if there are nonelastarg
- Varargs
containing additional values to use in the sequential part of the initialization,
+ to be put after the last unnamedValues element
+LuaTable
instance with named and sequential values supplied.+public static LuaUserdata userdataOf(java.lang.Object o)+
+
o
- The java instance to be wrapped as userdata
+LuaUserdata
value wrapping the java instance.+public static LuaUserdata userdataOf(java.lang.Object o, + LuaValue metatable)+
+
o
- The java instance to be wrapped as userdatametatable
- The metatble to associate with the userdata instance.
+LuaUserdata
value wrapping the java instance.+protected static LuaValue gettable(LuaValue t, + LuaValue key)+
+
+protected static boolean settable(LuaValue t, + LuaValue key, + LuaValue value)+
+
t
- LuaValue
on which value is being set, typically a table or something with the metatag NEWINDEX
definedkey
- LuaValue
naming the field to assignvalue
- LuaValue
the new value to assign to key
+LuaError
- if there is a loop in metatag processing+public LuaValue metatag(LuaValue tag)+
NIL
if it doesn't exist
++
tag
- Metatag name to look up, typically a string such as
+ INDEX
or NEWINDEX
reason
- Description of error when tag lookup fails.
+LuaValue
for tag reason
, or NIL
+protected LuaValue checkmetatag(LuaValue tag, + java.lang.String reason)+
LuaError
if it doesn't exist
++
tag
- Metatag name to look up, typically a string such as
+ INDEX
or NEWINDEX
reason
- Description of error when tag lookup fails.
+LuaValue
that can be called
+LuaError
- when the lookup fails.+public static Varargs varargsOf(LuaValue[] v)+
Varargs
around an array of LuaValue
s.
++
v
- The array of LuaValue
smore
- Varargs
contain values to include at the end
+Varargs
wrapping the supplied values.varargsOf(LuaValue, Varargs)
,
+varargsOf(LuaValue[], int, int)
+public static Varargs varargsOf(LuaValue[] v, + Varargs r)+
Varargs
around an array of LuaValue
s.
++
v
- The array of LuaValue
smore
- Varargs
contain values to include at the end
+Varargs
wrapping the supplied values.varargsOf(LuaValue[])
,
+varargsOf(LuaValue[], int, int, Varargs)
+public static Varargs varargsOf(LuaValue[] v, + int offset, + int length)+
Varargs
around an array of LuaValue
s.
++
v
- The array of LuaValue
soffset
- number of initial values to skip in the arraylength
- number of values to include from the array
+Varargs
wrapping the supplied values.varargsOf(LuaValue[])
,
+varargsOf(LuaValue[], int, int, Varargs)
+public static Varargs varargsOf(LuaValue[] v, + int offset, + int length, + Varargs more)+
Varargs
around an array of LuaValue
s.
++
v
- The array of LuaValue
soffset
- number of initial values to skip in the arraylength
- number of values to include from the arraymore
- Varargs
contain values to include at the end
+Varargs
wrapping the supplied values.varargsOf(LuaValue[], Varargs)
,
+varargsOf(LuaValue[], int, int)
+public static Varargs varargsOf(LuaValue v, + Varargs r)+
Varargs
around a set of 2 or more LuaValue
s.
+ + This can be used to wrap exactly 2 values, or a list consisting of 1 initial value + followed by another variable list of remaining values. +
+
v1
- First LuaValue
in the Varargs
v2
- LuaValue
supplying the 2rd value,
+ or Varargs
s supplying all values beyond the first
+Varargs
wrapping the supplied values.+public static Varargs varargsOf(LuaValue v1, + LuaValue v2, + Varargs v3)+
Varargs
around a set of 3 or more LuaValue
s.
+ + This can be used to wrap exactly 3 values, or a list consisting of 2 initial values + followed by another variable list of remaining values. +
+
v1
- First LuaValue
in the Varargs
v2
- Second LuaValue
in the Varargs
v3
- LuaValue
supplying the 3rd value,
+ or Varargs
s supplying all values beyond the second
+Varargs
wrapping the supplied values.+public static Varargs tailcallOf(LuaValue func, + Varargs args)+
TailcallVarargs
around a function and arguments.
+
+ The tail call is not yet called or processing until the client invokes
+ TailcallVarargs.eval()
which performs the tail call processing.
+
+ This method is typically not used directly by client code. + Instead use one of the function invocation methods. +
+
func
- LuaValue
to be called as a tail callargs
- Varargs
containing the arguments to the call
+TailcallVarargs
to be used in tailcall oprocessing.call()
,
+invoke()
,
+method(LuaValue)
,
+invokemethod(LuaValue)
+public Varargs onInvoke(Varargs args)+
+ This may return a TailcallVarargs
to be evaluated by the client.
+
+ This should not be called directly, instead use on of the call invocation functions. +
+
args
- the arguments to the call invocation.
+call()
,
+invoke()
,
+method(LuaValue)
,
+invokemethod(LuaValue)
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + java.lang.Throwable + java.lang.Error + org.luaj.vm2.OrphanedThread ++
public class OrphanedThread
+Error
sublcass that indicates a lua thread that is no
+ longer referenced has been detected.
+
+ The java thread in which this is thrown should correspond to a
+ LuaThread
being used as a coroutine that could not possibly be
+ resumed again because there are no more references to the LuaThread with
+ which it is associated. Rather than locking up resources forever, this error
+ is thrown, and should fall through all the way to the thread's Thread.run
() method.
+
+ Java code mixed with the luaj vm should not catch this error because it may + occur when the coroutine is not running, so any processing done during error + handling could break the thread-safety of the application because other lua + processing could be going on in a different thread. +
+ +
+
+Constructor Summary | +|
---|---|
OrphanedThread()
+
++ |
+
+Method Summary | +
---|
Methods inherited from class java.lang.Throwable | +
---|
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public OrphanedThread()+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Lua + org.luaj.vm2.Print ++
public class Print
+Debug helper class to pretty-print lua bytecodes. +
+ +
+
Prototype
,
+LuaClosure
+Field Summary | +|
---|---|
+static java.lang.String[] |
+OPNAMES
+
++ |
+
+static java.io.PrintStream |
+ps
+
++ |
+
Fields inherited from class org.luaj.vm2.Lua | +
---|
_VERSION, BITRK, iABC, iABx, iAsBx, LFIELDS_PER_FLUSH, LUA_MULTRET, luaP_opmodes, MASK_A, MASK_B, MASK_Bx, MASK_C, MASK_NOT_A, MASK_NOT_B, MASK_NOT_Bx, MASK_NOT_C, MASK_NOT_OP, MASK_OP, MAX_OP, MAXARG_A, MAXARG_B, MAXARG_Bx, MAXARG_C, MAXARG_sBx, MAXINDEXRK, NO_REG, NUM_OPCODES, OP_ADD, OP_AND, OP_CALL, OP_CLOSE, OP_CLOSURE, OP_CONCAT, OP_DIV, OP_EQ, OP_FORLOOP, OP_FORPREP, OP_GE, OP_GETGLOBAL, OP_GETTABLE, OP_GETUPVAL, OP_GT, OP_JMP, OP_LE, OP_LEN, OP_LOADBOOL, OP_LOADK, OP_LOADNIL, OP_LT, OP_MOD, OP_MOVE, OP_MUL, OP_NEQ, OP_NEWTABLE, OP_NOT, OP_OR, OP_POW, OP_RETURN, OP_SELF, OP_SETGLOBAL, OP_SETLIST, OP_SETTABLE, OP_SETUPVAL, OP_SUB, OP_TAILCALL, OP_TEST, OP_TESTSET, OP_TFORLOOP, OP_UNM, OP_VARARG, OpArgK, OpArgN, OpArgR, OpArgU, POS_A, POS_B, POS_Bx, POS_C, POS_OP, SIZE_A, SIZE_B, SIZE_Bx, SIZE_C, SIZE_OP, VARARG_HASARG, VARARG_ISVARARG, VARARG_NEEDSARG |
+
+Constructor Summary | +|
---|---|
Print()
+
++ |
+
+Method Summary | +|
---|---|
+static void |
+print(Prototype p)
+
++ |
+
+static void |
+printCode(Prototype f)
+
++ Print the code in a prototype |
+
+static void |
+printFunction(Prototype f,
+ boolean full)
+
++ |
+
+static void |
+printOpCode(java.io.PrintStream ps,
+ Prototype f,
+ int pc)
+
++ Print an opcode in a prototype |
+
+static void |
+printOpCode(Prototype f,
+ int pc)
+
++ Print an opcode in a prototype |
+
+static void |
+printState(LuaClosure cl,
+ int pc,
+ LuaValue[] stack,
+ int top,
+ Varargs varargs)
+
++ Print the state of a LuaClosure that is being executed |
+
Methods inherited from class org.luaj.vm2.Lua | +
---|
GET_OPCODE, GETARG_A, GETARG_B, GETARG_Bx, GETARG_C, GETARG_sBx, getBMode, getCMode, getOpMode, INDEXK, ISK, RKASK, testAMode, testTMode |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Field Detail | +
---|
+public static java.io.PrintStream ps+
+public static final java.lang.String[] OPNAMES+
+Constructor Detail | +
---|
+public Print()+
+Method Detail | +
---|
+public static void printCode(Prototype f)+
+
f
- the Prototype
+public static void printOpCode(Prototype f, + int pc)+
+
f
- the Prototype
pc
- the program counter to look up and print+public static void printOpCode(java.io.PrintStream ps, + Prototype f, + int pc)+
+
ps
- the PrintStream
to print tof
- the Prototype
pc
- the program counter to look up and print+public static void print(Prototype p)+
+public static void printFunction(Prototype f, + boolean full)+
+public static void printState(LuaClosure cl, + int pc, + LuaValue[] stack, + int top, + Varargs varargs)+
LuaClosure
that is being executed
++
cl
- the LuaClosure
pc
- the program counterstack
- the stack of LuaValue
top
- the top of the stackvarargs
- any Varargs
value that may apply
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Prototype ++
public class Prototype
+Prototype representing compiled lua code. +
+ This is both a straight translation of the corresponding C type, + and the main data structure for execution of compiled lua bytecode. +
+ See documentatation on LuaClosure
for information on how to load
+ and execute a Prototype
.
+
+ +
+
LuaClosure
+Field Summary | +|
---|---|
+ int[] |
+code
+
++ |
+
+ int |
+is_vararg
+
++ |
+
+ LuaValue[] |
+k
+
++ |
+
+ int |
+lastlinedefined
+
++ |
+
+ int |
+linedefined
+
++ |
+
+ int[] |
+lineinfo
+
++ |
+
+ LocVars[] |
+locvars
+
++ |
+
+ int |
+maxstacksize
+
++ |
+
+ int |
+numparams
+
++ |
+
+ int |
+nups
+
++ |
+
+ Prototype[] |
+p
+
++ |
+
+ LuaString |
+source
+
++ |
+
+ LuaString[] |
+upvalues
+
++ |
+
+Constructor Summary | +|
---|---|
Prototype()
+
++ |
+
+Method Summary | +|
---|---|
+ LuaString |
+getlocalname(int number,
+ int pc)
+
++ Get the name of a local variable. |
+
+ java.lang.String |
+toString()
+
++ |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public LuaValue[] k+
+public int[] code+
+public Prototype[] p+
+public int[] lineinfo+
+public LocVars[] locvars+
+public LuaString[] upvalues+
+public LuaString source+
+public int nups+
+public int linedefined+
+public int lastlinedefined+
+public int numparams+
+public int is_vararg+
+public int maxstacksize+
+Constructor Detail | +
---|
+public Prototype()+
+Method Detail | +
---|
+public java.lang.String toString()+
toString
in class java.lang.Object
+public LuaString getlocalname(int number, + int pc)+
+
number
- the local variable number to look uppc
- the program counter
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.TailcallVarargs ++
public class TailcallVarargs
+Subclass of Varargs
that represents a lua tail call
+ in a Java library function execution environment.
+
+ Since Java doesn't have direct support for tail calls,
+ any lua function whose Prototype
contains the
+ Lua.OP_TAILCALL
bytecode needs a mechanism
+ for tail calls when converting lua-bytecode to java-bytecode.
+
+ The tail call holds the next function and arguments,
+ and the client a call to eval()
executes the function
+ repeatedly until the tail calls are completed.
+
+ Normally, users of luaj need not concern themselves with the + details of this mechanism, as it is built into the core + execution framework. +
+ +
+
Prototype
,
+LuaJC
+Constructor Summary | +|
---|---|
TailcallVarargs(LuaValue object,
+ LuaValue methodname,
+ Varargs args)
+
++ |
+|
TailcallVarargs(LuaValue f,
+ Varargs args)
+
++ |
+
+Method Summary | +|
---|---|
+ LuaValue |
+arg(int i)
+
++ Get the n-th argument value (1-based). |
+
+ LuaValue |
+arg1()
+
++ Get the first argument in the list. |
+
+ Varargs |
+eval()
+
++ Evaluate any pending tail call and return result. |
+
+ boolean |
+isTailcall()
+
++ Return true if this is a TailcallVarargs |
+
+ int |
+narg()
+
++ Get the number of arguments, or 0 if there are none. |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tojstring, tolong, toshort, toString, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public TailcallVarargs(LuaValue f, + Varargs args)+
+public TailcallVarargs(LuaValue object, + LuaValue methodname, + Varargs args)+
+Method Detail | +
---|
+public boolean isTailcall()+
Varargs
+
isTailcall
in class Varargs
+public Varargs eval()+
Varargs
+
eval
in class Varargs
+public LuaValue arg(int i)+
Varargs
+
arg
in class Varargs
i
- the index of the argument to get, 1 is the first argument
+Varargs.arg1()
,
+LuaValue.NIL
+public LuaValue arg1()+
Varargs
+
arg1
in class Varargs
Varargs.arg(int)
,
+LuaValue.NIL
+public int narg()+
Varargs
+
narg
in class Varargs
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.UpValue ++
public final class UpValue
+Upvalue used with Closure formulation +
+
+ +
+
LuaClosure
,
+Prototype
+Constructor Summary | +|
---|---|
UpValue(LuaValue[] stack,
+ int index)
+
++ Create an upvalue relative to a stack |
+
+Method Summary | +|
---|---|
+ void |
+close()
+
++ Close this upvalue so it is no longer on the stack |
+
+ LuaValue |
+getValue()
+
++ Get the value of the upvalue |
+
+ void |
+setValue(LuaValue value)
+
++ Set the value of the upvalue |
+
+ java.lang.String |
+tojstring()
+
++ Convert this upvalue to a Java String |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Constructor Detail | +
---|
+public UpValue(LuaValue[] stack, + int index)+
+
stack
- the stackindex
- the index on the stack for the upvalue+Method Detail | +
---|
+public java.lang.String tojstring()+
+
LuaValue.tojstring()
+public final LuaValue getValue()+
+
LuaValue
for this upvalue+public final void setValue(LuaValue value)+
+
the
- LuaValue
to set it to+public final void close()+
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs ++
public abstract class Varargs
+Class to encapsulate varargs values, either as part of a variable argument list, or multiple return values. +
+ To construct varargs, use one of the static methods such as
+ LuaValue.varargsOf(LuaValue,LuaValue)
+
+
+ Any LuaValue can be used as a stand-in for Varargs, for both calls and return values. + When doing so, nargs() will return 1 and arg1() or arg(1) will return this. + This simplifies the case when calling or implementing varargs functions with only + 1 argument or 1 return value. +
+ Varargs can also be derived from other varargs by appending to the front with a call
+ such as LuaValue.varargsOf(LuaValue,Varargs)
+ or by taking a portion of the args using Varargs.subargs(int start)
+
+
+ +
+
LuaValue.varargsOf(LuaValue[])
,
+LuaValue.varargsOf(LuaValue, Varargs)
,
+LuaValue.varargsOf(LuaValue[], Varargs)
,
+LuaValue.varargsOf(LuaValue, LuaValue, Varargs)
,
+LuaValue.varargsOf(LuaValue[], int, int)
,
+LuaValue.varargsOf(LuaValue[], int, int, Varargs)
,
+subargs(int)
+Constructor Summary | +|
---|---|
Varargs()
+
++ |
+
+Method Summary | +|
---|---|
+abstract LuaValue |
+arg(int i)
+
++ Get the n-th argument value (1-based). |
+
+abstract LuaValue |
+arg1()
+
++ Get the first argument in the list. |
+
+ void |
+argcheck(boolean test,
+ int i,
+ java.lang.String msg)
+
++ Return argument i as a LuaValue when a user-supplied assertion passes, or throw an error. |
+
+ boolean |
+checkboolean(int i)
+
++ Return argument i as a boolean value, or throw an error if any other type. |
+
+ LuaClosure |
+checkclosure(int i)
+
++ Return argument i as a closure, or throw an error if any other type. |
+
+ double |
+checkdouble(int i)
+
++ Return argument i as a double, or throw an error if it cannot be converted to one. |
+
+ LuaValue |
+checkfunction(int i)
+
++ Return argument i as a function, or throw an error if an incompatible type. |
+
+ int |
+checkint(int i)
+
++ Return argument i as a java int value, discarding any fractional part, or throw an error if not a number. |
+
+ LuaInteger |
+checkinteger(int i)
+
++ Return argument i as a java int value, or throw an error if not a number or is not representable by a java int. |
+
+ java.lang.String |
+checkjstring(int i)
+
++ Return argument i as a java String if a string or number, or throw an error if any other type |
+
+ long |
+checklong(int i)
+
++ Return argument i as a java long value, discarding any fractional part, or throw an error if not a number. |
+
+ LuaValue |
+checknotnil(int i)
+
++ Return argument i as a LuaValue if it is not nil, or throw an error if it is nil. |
+
+ LuaNumber |
+checknumber(int i)
+
++ Return argument i as a LuaNumber, or throw an error if not a number or string that can be converted to a number. |
+
+ LuaString |
+checkstring(int i)
+
++ Return argument i as a LuaString if a string or number, or throw an error if any other type |
+
+ LuaTable |
+checktable(int i)
+
++ Return argument i as a LuaTable if a lua table, or throw an error if any other type. |
+
+ LuaThread |
+checkthread(int i)
+
++ Return argument i as a LuaThread if a lua thread, or throw an error if any other type. |
+
+ java.lang.Object |
+checkuserdata(int i)
+
++ Return argument i as a java Object if a userdata, or throw an error if any other type. |
+
+ java.lang.Object |
+checkuserdata(int i,
+ java.lang.Class c)
+
++ Return argument i as a java Object if it is a userdata whose instance Class c or a subclass, + or throw an error if any other type. |
+
+ LuaValue |
+checkvalue(int i)
+
++ Return argument i as a LuaValue if it exists, or throw an error. |
+
+ Varargs |
+eval()
+
++ Evaluate any pending tail call and return result. |
+
+ boolean |
+isfunction(int i)
+
++ Tests if argument i is a function. |
+
+ boolean |
+isnil(int i)
+
++ Tests if argument i is nil. |
+
+ boolean |
+isnoneornil(int i)
+
++ Return true if there is no argument or nil at argument i. |
+
+ boolean |
+isnumber(int i)
+
++ Tests if argument i is a number. |
+
+ boolean |
+isstring(int i)
+
++ Tests if argument i is a string. |
+
+ boolean |
+istable(int i)
+
++ Tests if argument i is a table. |
+
+ boolean |
+isTailcall()
+
++ Return true if this is a TailcallVarargs |
+
+ boolean |
+isthread(int i)
+
++ Tests if argument i is a thread. |
+
+ boolean |
+isuserdata(int i)
+
++ Tests if argument i is a userdata. |
+
+ boolean |
+isvalue(int i)
+
++ Tests if a value exists at argument i. |
+
+abstract int |
+narg()
+
++ Get the number of arguments, or 0 if there are none. |
+
+ boolean |
+optboolean(int i,
+ boolean defval)
+
++ Return argument i as a boolean value, defval if nil, or throw a LuaError if any other type. |
+
+ LuaClosure |
+optclosure(int i,
+ LuaClosure defval)
+
++ Return argument i as a closure, defval if nil, or throw a LuaError if any other type. |
+
+ double |
+optdouble(int i,
+ double defval)
+
++ Return argument i as a double, defval if nil, or throw a LuaError if it cannot be converted to one. |
+
+ LuaFunction |
+optfunction(int i,
+ LuaFunction defval)
+
++ Return argument i as a function, defval if nil, or throw a LuaError if an incompatible type. |
+
+ int |
+optint(int i,
+ int defval)
+
++ Return argument i as a java int value, discarding any fractional part, defval if nil, or throw a LuaError if not a number. |
+
+ LuaInteger |
+optinteger(int i,
+ LuaInteger defval)
+
++ Return argument i as a java int value, defval if nil, or throw a LuaError if not a number or is not representable by a java int. |
+
+ java.lang.String |
+optjstring(int i,
+ java.lang.String defval)
+
++ Return argument i as a java String if a string or number, defval if nil, or throw a LuaError if any other type |
+
+ long |
+optlong(int i,
+ long defval)
+
++ Return argument i as a java long value, discarding any fractional part, defval if nil, or throw a LuaError if not a number. |
+
+ LuaNumber |
+optnumber(int i,
+ LuaNumber defval)
+
++ Return argument i as a LuaNumber, defval if nil, or throw a LuaError if not a number or string that can be converted to a number. |
+
+ LuaString |
+optstring(int i,
+ LuaString defval)
+
++ Return argument i as a LuaString if a string or number, defval if nil, or throw a LuaError if any other type |
+
+ LuaTable |
+opttable(int i,
+ LuaTable defval)
+
++ Return argument i as a LuaTable if a lua table, defval if nil, or throw a LuaError if any other type. |
+
+ LuaThread |
+optthread(int i,
+ LuaThread defval)
+
++ Return argument i as a LuaThread if a lua thread, defval if nil, or throw a LuaError if any other type. |
+
+ java.lang.Object |
+optuserdata(int i,
+ java.lang.Class c,
+ java.lang.Object defval)
+
++ Return argument i as a java Object if it is a userdata whose instance Class c or a subclass, + defval if nil, or throw a LuaError if any other type. |
+
+ java.lang.Object |
+optuserdata(int i,
+ java.lang.Object defval)
+
++ Return argument i as a java Object if a userdata, defval if nil, or throw a LuaError if any other type. |
+
+ LuaValue |
+optvalue(int i,
+ LuaValue defval)
+
++ Return argument i as a LuaValue if it exists, or defval . |
+
+ Varargs |
+subargs(int start)
+
++ Create a Varargs instance containing arguments starting at index start |
+
+ boolean |
+toboolean(int i)
+
++ Convert argument i to java boolean based on lua rules for boolean evaluation. |
+
+ byte |
+tobyte(int i)
+
++ Return argument i as a java byte value, discarding any fractional part and truncating, + or 0 if not a number. |
+
+ char |
+tochar(int i)
+
++ Return argument i as a java char value, discarding any fractional part and truncating, + or 0 if not a number. |
+
+ double |
+todouble(int i)
+
++ Return argument i as a java double value or 0 if not a number. |
+
+ float |
+tofloat(int i)
+
++ Return argument i as a java float value, discarding excess fractional part and truncating, + or 0 if not a number. |
+
+ int |
+toint(int i)
+
++ Return argument i as a java int value, discarding any fractional part and truncating, + or 0 if not a number. |
+
+ java.lang.String |
+tojstring()
+
++ Convert the list of varargs values to a human readable java String. |
+
+ java.lang.String |
+tojstring(int i)
+
++ Return argument i as a java String based on the type of the argument. |
+
+ long |
+tolong(int i)
+
++ Return argument i as a java long value, discarding any fractional part and truncating, + or 0 if not a number. |
+
+ short |
+toshort(int i)
+
++ Return argument i as a java short value, discarding any fractional part and truncating, + or 0 if not a number. |
+
+ java.lang.String |
+toString()
+
++ Convert the value or values to a java String using Varargs.tojstring() |
+
+ java.lang.Object |
+touserdata(int i)
+
++ Return argument i as a java Object if a userdata, or null. |
+
+ java.lang.Object |
+touserdata(int i,
+ java.lang.Class c)
+
++ Return argument i as a java Object if it is a userdata whose instance Class c or a subclass, or null. |
+
+ int |
+type(int i)
+
++ Gets the type of argument i |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public Varargs()+
+Method Detail | +
---|
+public abstract LuaValue arg(int i)+
+
i
- the index of the argument to get, 1 is the first argument
+arg1()
,
+LuaValue.NIL
+public abstract int narg()+
+
+public abstract LuaValue arg1()+
+
arg(int)
,
+LuaValue.NIL
+public Varargs eval()+
+
+public boolean isTailcall()+
+
+public int type(int i)+
i
++
i
- the index of the argument to convert, 1 is the first argument
+LuaValue.TNIL
,
+LuaValue.TBOOLEAN
,
+LuaValue.TNUMBER
,
+LuaValue.TSTRING
,
+LuaValue.TTABLE
,
+LuaValue.TFUNCTION
,
+LuaValue.TUSERDATA
,
+LuaValue.TTHREAD
+public boolean isnil(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaValue.TNIL
+public boolean isfunction(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaValue.TFUNCTION
+public boolean isnumber(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaValue.TNUMBER
,
+LuaValue.TSTRING
+public boolean isstring(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaValue.TNUMBER
,
+LuaValue.TSTRING
+public boolean istable(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaValue.TTABLE
+public boolean isthread(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaValue.TTHREAD
+public boolean isuserdata(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaValue.TUSERDATA
+public boolean isvalue(int i)+
+
i
- the index of the argument to test, 1 is the first argument
++public boolean optboolean(int i, + boolean defval)+
defval
if nil, or throw a LuaError if any other type.
++
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a lua boolean+public LuaClosure optclosure(int i, + LuaClosure defval)+
defval
if nil, or throw a LuaError if any other type.
++
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a lua closure+public double optdouble(int i, + double defval)+
defval
if nil, or throw a LuaError if it cannot be converted to one.
++
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a number+public LuaFunction optfunction(int i, + LuaFunction defval)+
defval
if nil, or throw a LuaError if an incompatible type.
++
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a lua function or closure+public int optint(int i, + int defval)+
defval
if nil, or throw a LuaError if not a number.
++
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a number+public LuaInteger optinteger(int i, + LuaInteger defval)+
defval
if nil, or throw a LuaError if not a number or is not representable by a java int.
++
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument cannot be represented by a java int value+public long optlong(int i, + long defval)+
defval
if nil, or throw a LuaError if not a number.
++
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a number+public LuaNumber optnumber(int i, + LuaNumber defval)+
defval
if nil, or throw a LuaError if not a number or string that can be converted to a number.
++
i
- the index of the argument to test, 1 is the first argument, or defval if not supplied or nil
+LuaError
- if the argument is not a number+public java.lang.String optjstring(int i, + java.lang.String defval)+
defval
if nil, or throw a LuaError if any other type
++
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a string or number+public LuaString optstring(int i, + LuaString defval)+
defval
if nil, or throw a LuaError if any other type
++
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a string or number+public LuaTable opttable(int i, + LuaTable defval)+
defval
if nil, or throw a LuaError if any other type.
++
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a lua table+public LuaThread optthread(int i, + LuaThread defval)+
defval
if nil, or throw a LuaError if any other type.
++
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a lua thread+public java.lang.Object optuserdata(int i, + java.lang.Object defval)+
defval
if nil, or throw a LuaError if any other type.
++
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a userdata+public java.lang.Object optuserdata(int i, + java.lang.Class c, + java.lang.Object defval)+
defval
if nil, or throw a LuaError if any other type.
++
i
- the index of the argument to test, 1 is the first argumentc
- the class to which the userdata instance must be assignable
+LuaError
- if the argument is not a userdata or from whose instance c is not assignable+public LuaValue optvalue(int i, + LuaValue defval)+
defval
.
++
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument does not exist.+public boolean checkboolean(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a lua boolean+public LuaClosure checkclosure(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a lua closure+public double checkdouble(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a number+public LuaValue checkfunction(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a lua function or closure+public int checkint(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a number+public LuaInteger checkinteger(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument cannot be represented by a java int value+public long checklong(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a number+public LuaNumber checknumber(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a number+public java.lang.String checkjstring(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a string or number+public LuaString checkstring(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a string or number+public LuaTable checktable(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a lua table+public LuaThread checkthread(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a lua thread+public java.lang.Object checkuserdata(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument is not a userdata+public java.lang.Object checkuserdata(int i, + java.lang.Class c)+
+
i
- the index of the argument to test, 1 is the first argumentc
- the class to which the userdata instance must be assignable
+LuaError
- if the argument is not a userdata or from whose instance c is not assignable+public LuaValue checkvalue(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument does not exist.+public LuaValue checknotnil(int i)+
+
i
- the index of the argument to test, 1 is the first argument
+LuaError
- if the argument doesn't exist or evaluates to nil.+public void argcheck(boolean test, + int i, + java.lang.String msg)+
+
test
- user supplied assertion to test againsti
- the index to report in any error messagemsg
- the error message to use when the test fails
+LuaError
- if the the value of test
is false
+public boolean isnoneornil(int i)+
+
i
- the index of the argument to test, 1 is the first argument
++public boolean toboolean(int i)+
i
to java boolean based on lua rules for boolean evaluation.
++
i
- the index of the argument to convert, 1 is the first argument
+false
if argument i is nil or false, otherwise true
+public byte tobyte(int i)+
+
i
- the index of the argument to convert, 1 is the first argument
++public char tochar(int i)+
+
i
- the index of the argument to convert, 1 is the first argument
++public double todouble(int i)+
+
i
- the index of the argument to convert, 1 is the first argument
++public float tofloat(int i)+
+
i
- the index of the argument to convert, 1 is the first argument
++public int toint(int i)+
+
i
- the index of the argument to convert, 1 is the first argument
++public long tolong(int i)+
+
i
- the index of the argument to convert, 1 is the first argument
++public java.lang.String tojstring(int i)+
+
i
- the index of the argument to convert, 1 is the first argument
++public short toshort(int i)+
+
i
- the index of the argument to convert, 1 is the first argument
++public java.lang.Object touserdata(int i)+
+
i
- the index of the argument to convert, 1 is the first argument
++public java.lang.Object touserdata(int i, + java.lang.Class c)+
+
i
- the index of the argument to convert, 1 is the first argumentc
- the class to which the userdata instance must be assignable
++public java.lang.String tojstring()+
+
+public java.lang.String toString()+
+
toString
in class java.lang.Object
tojstring()
+public Varargs subargs(int start)+
Varargs
instance containing arguments starting at index start
++
start
- the index from which to include arguments, where 1 is the first argument.
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaTable + org.luaj.vm2.WeakTable ++
public class WeakTable
+Subclass of LuaTable
that provides weak key and weak value semantics.
+
+ Normally these are not created directly, but indirectly when changing the mode
+ of a LuaTable
as lua script executes.
+
+ However, calling the constructors directly when weak tables are required from + Java will reduce overhead. +
+ +
+
+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.LuaTable | +
---|
array, hashEntries, hashKeys, hashValues, m_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
+ |
+WeakTable(boolean weakkeys,
+ boolean weakvalues)
+
++ Construct a table with weak keys, weak values, or both |
+
+protected |
+WeakTable(boolean weakkeys,
+ boolean weakvalues,
+ int narray,
+ int nhash)
+
++ Construct a table with weak keys, weak values, or both, and an initial capacity |
+
+protected |
+WeakTable(boolean weakkeys,
+ boolean weakvalues,
+ LuaTable source)
+
++ Construct a table with weak keys, weak values, or both, and a source of initial data |
+
+Method Summary | +|
---|---|
+protected LuaTable |
+changemode(boolean weakkeys,
+ boolean weakvalues)
+
++ Change the mode of a table |
+
+protected int |
+getArrayLength()
+
++ Get the length of the array part of the table. |
+
+protected int |
+getHashLength()
+
++ Get the length of the hash part of the table. |
+
+ int |
+hashFindSlot(LuaValue key)
+
++ Find the hashtable slot to use |
+
+protected LuaValue |
+hashget(LuaValue key)
+
++ Get the hash value for a key + key the key to look up |
+
+ int |
+maxn()
+
++ Return table.maxn() as defined by lua 5.0. |
+
+ Varargs |
+next(LuaValue key)
+
++ Get the next element after a particular key in the table |
+
+ void |
+presize(int narray)
+
++ Preallocate the array part of a table to be a certain size, |
+
+ void |
+presize(int narray,
+ int nhash)
+
++ Presize capacity of both array and hash parts. |
+
+ LuaValue |
+rawget(int key)
+
++ Get a value in a table without metatag processing. |
+
+ LuaValue |
+rawget(LuaValue key)
+
++ Get a value in a table without metatag processing. |
+
+ void |
+rawset(int key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing. |
+
+ void |
+rawset(LuaValue key,
+ LuaValue value)
+
++ caller must ensure key is not nil |
+
+ void |
+sort(LuaValue comparator)
+
++ Sort the table using a comparator. |
+
Methods inherited from class org.luaj.vm2.LuaTable | +
---|
checktable, concat, eq_b, eq, foreach, foreachi, get, get, getmetatable, getn, hashClearSlot, hashset, inext, insert, istable, keyCount, keys, len, length, opttable, remove, set, set, setmetatable, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public WeakTable(boolean weakkeys, + boolean weakvalues)+
+
weakkeys
- true to let the table have weak keysweakvalues
- true to let the table have weak values+protected WeakTable(boolean weakkeys, + boolean weakvalues, + int narray, + int nhash)+
+
weakkeys
- true to let the table have weak keysweakvalues
- true to let the table have weak valuesnarray
- capacity of array partnhash
- capacity of hash part+protected WeakTable(boolean weakkeys, + boolean weakvalues, + LuaTable source)+
+
weakkeys
- true to let the table have weak keysweakvalues
- true to let the table have weak valuessource
- LuaTable
containing the initial elements+Method Detail | +
---|
+public void presize(int narray)+
LuaValue
+ Primarily used internally in response to a SETLIST bytecode. +
+
presize
in class LuaTable
narray
- the number of array slots to preallocate in the table.+public void presize(int narray, + int nhash)+
+
presize
in class LuaTable
narray
- capacity of array partnhash
- capacity of hash part+protected int getArrayLength()+
LuaTable
+
getArrayLength
in class LuaTable
+protected int getHashLength()+
LuaTable
+
getHashLength
in class LuaTable
+protected LuaTable changemode(boolean weakkeys, + boolean weakvalues)+
LuaTable
+
changemode
in class LuaTable
weakkeys
- true to make the table have weak keys going forwardweakvalues
- true to make the table have weak values going forward
+this
or a new WeakTable
if the mode change requires copying.+public void rawset(int key, + LuaValue value)+
LuaValue
+
rawset
in class LuaTable
key
- the key to usevalue
- the value to use, can be NIL
, must not be null+public void rawset(LuaValue key, + LuaValue value)+
LuaTable
+
rawset
in class LuaTable
key
- the key to use, must not be NIL
or nullvalue
- the value to use, can be NIL
, must not be null+public LuaValue rawget(int key)+
LuaValue
+
rawget
in class LuaTable
key
- the key to look up
+LuaValue
for that key, or NIL
if not found+public LuaValue rawget(LuaValue key)+
LuaValue
+
rawget
in class LuaTable
key
- the key to look up, must not be NIL
or null
+LuaValue
for that key, or NIL
if not found+protected LuaValue hashget(LuaValue key)+
+
hashget
in class LuaTable
+public int hashFindSlot(LuaValue key)+
LuaTable
+
hashFindSlot
in class LuaTable
key
- key to look for
++public int maxn()+
LuaTable
+ Provided for compatibility, not a scalable operation. +
+
maxn
in class LuaTable
+public Varargs next(LuaValue key)+
+
next
in class LuaTable
key
- LuaInteger
value identifying a key to start from,
+ or NIL
to start at the beginning
+LuaTable
,
+#inext()
,
+LuaValue.valueOf(int)
,
+Varargs.arg1()
,
+Varargs.arg(int)
,
+LuaValue.isnil()
+public void sort(LuaValue comparator)+
LuaTable
+
sort
in class LuaTable
comparator
- LuaValue
to be called to compare elements.
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use Buffer | +|
---|---|
org.luaj.vm2 | ++ |
+Uses of Buffer in org.luaj.vm2 | +
---|
+ +
Methods in org.luaj.vm2 that return Buffer | +|
---|---|
+ Buffer |
+Buffer.append(byte b)
+
++ Append a single byte to the buffer. |
+
+ Buffer |
+Buffer.append(LuaString str)
+
++ Append a LuaString to the buffer. |
+
+ Buffer |
+Buffer.append(LuaValue val)
+
++ Append a LuaValue to the buffer. |
+
+ Buffer |
+Buffer.append(java.lang.String str)
+
++ Append a Java String to the buffer. |
+
+ Buffer |
+LuaValue.buffer()
+
++ Convert the value to a Buffer for more efficient concatenation of
+ multiple strings. |
+
+ Buffer |
+LuaNumber.concat(Buffer rhs)
+
++ |
+
+ Buffer |
+LuaString.concat(Buffer rhs)
+
++ |
+
+ Buffer |
+LuaValue.concat(Buffer rhs)
+
++ Concatenate a Buffer onto this value and return the result
+ using rules of lua string concatenation including metatag processing. |
+
+ Buffer |
+Buffer.concatTo(LuaNumber lhs)
+
++ Concatenate this buffer onto a LuaNumber |
+
+ Buffer |
+Buffer.concatTo(LuaString lhs)
+
++ Concatenate this buffer onto a LuaString |
+
+ Buffer |
+Buffer.concatTo(LuaValue lhs)
+
++ Concatenate this buffer onto a LuaValue |
+
+ Buffer |
+Buffer.prepend(LuaString s)
+
++ Concatenate bytes from a LuaString onto the front of this buffer |
+
+ Buffer |
+Buffer.setvalue(LuaValue value)
+
++ Set buffer contents as a LuaValue |
+
+ +
Methods in org.luaj.vm2 with parameters of type Buffer | +|
---|---|
+ Buffer |
+LuaNumber.concat(Buffer rhs)
+
++ |
+
+ Buffer |
+LuaString.concat(Buffer rhs)
+
++ |
+
+ Buffer |
+LuaValue.concat(Buffer rhs)
+
++ Concatenate a Buffer onto this value and return the result
+ using rules of lua string concatenation including metatag processing. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LoadState.LuaCompiler | +|
---|---|
org.luaj.vm2 | ++ |
org.luaj.vm2.compiler | ++ |
org.luaj.vm2.luajc | ++ |
+Uses of LoadState.LuaCompiler in org.luaj.vm2 | +
---|
+ +
Fields in org.luaj.vm2 declared as LoadState.LuaCompiler | +|
---|---|
+static LoadState.LuaCompiler |
+LoadState.compiler
+
++ Compiler instance, if installed |
+
+Uses of LoadState.LuaCompiler in org.luaj.vm2.compiler | +
---|
+ +
Classes in org.luaj.vm2.compiler that implement LoadState.LuaCompiler | +|
---|---|
+ class |
+LuaC
+
++ Compiler for Lua. |
+
+Uses of LoadState.LuaCompiler in org.luaj.vm2.luajc | +
---|
+ +
Classes in org.luaj.vm2.luajc that implement LoadState.LuaCompiler | +|
---|---|
+ class |
+LuaJC
+
++ Implementation of LoadState.LuaCompiler which does direct
+ lua-to-java-bytecode compiling. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LocVars | +|
---|---|
org.luaj.vm2 | ++ |
+Uses of LocVars in org.luaj.vm2 | +
---|
+ +
Fields in org.luaj.vm2 declared as LocVars | +|
---|---|
+ LocVars[] |
+Prototype.locvars
+
++ |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use Lua | +|
---|---|
org.luaj.vm2 | ++ |
org.luaj.vm2.compiler | ++ |
+Uses of Lua in org.luaj.vm2 | +
---|
+ +
Subclasses of Lua in org.luaj.vm2 | +|
---|---|
+ class |
+Print
+
++ Debug helper class to pretty-print lua bytecodes. |
+
+Uses of Lua in org.luaj.vm2.compiler | +
---|
+ +
Subclasses of Lua in org.luaj.vm2.compiler | +|
---|---|
+ class |
+LuaC
+
++ Compiler for Lua. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LuaBoolean | +|
---|---|
org.luaj.vm2 | ++ |
+Uses of LuaBoolean in org.luaj.vm2 | +
---|
+ +
Fields in org.luaj.vm2 declared as LuaBoolean | +|
---|---|
+static LuaBoolean |
+LuaValue.FALSE
+
++ LuaBoolean constant corresponding to lua false |
+
+static LuaBoolean |
+LuaValue.TRUE
+
++ LuaBoolean constant corresponding to lua true |
+
+ +
Methods in org.luaj.vm2 that return LuaBoolean | +|
---|---|
+static LuaBoolean |
+LuaValue.valueOf(boolean b)
+
++ Convert java boolean to a LuaValue . |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LuaClosure | +|
---|---|
org.luaj.vm2 | ++ |
+Uses of LuaClosure in org.luaj.vm2 | +
---|
+ +
Methods in org.luaj.vm2 that return LuaClosure | +|
---|---|
+ LuaClosure |
+LuaClosure.checkclosure()
+
++ |
+
+ LuaClosure |
+LuaValue.checkclosure()
+
++ Check that the value is a LuaClosure ,
+ or throw LuaError if not |
+
+ LuaClosure |
+Varargs.checkclosure(int i)
+
++ Return argument i as a closure, or throw an error if any other type. |
+
+ LuaClosure |
+Varargs.optclosure(int i,
+ LuaClosure defval)
+
++ Return argument i as a closure, defval if nil, or throw a LuaError if any other type. |
+
+ LuaClosure |
+LuaClosure.optclosure(LuaClosure defval)
+
++ |
+
+ LuaClosure |
+LuaNil.optclosure(LuaClosure defval)
+
++ |
+
+ LuaClosure |
+LuaValue.optclosure(LuaClosure defval)
+
++ Check that optional argument is a closure and return as LuaClosure |
+
+ +
Methods in org.luaj.vm2 with parameters of type LuaClosure | +|
---|---|
+ LuaClosure |
+Varargs.optclosure(int i,
+ LuaClosure defval)
+
++ Return argument i as a closure, defval if nil, or throw a LuaError if any other type. |
+
+ LuaClosure |
+LuaClosure.optclosure(LuaClosure defval)
+
++ |
+
+ LuaClosure |
+LuaNil.optclosure(LuaClosure defval)
+
++ |
+
+ LuaClosure |
+LuaValue.optclosure(LuaClosure defval)
+
++ Check that optional argument is a closure and return as LuaClosure |
+
+static void |
+Print.printState(LuaClosure cl,
+ int pc,
+ LuaValue[] stack,
+ int top,
+ Varargs varargs)
+
++ Print the state of a LuaClosure that is being executed |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LuaDouble | +|
---|---|
org.luaj.vm2 | ++ |
+Uses of LuaDouble in org.luaj.vm2 | +
---|
+ +
Fields in org.luaj.vm2 declared as LuaDouble | +|
---|---|
+static LuaDouble |
+LuaDouble.NAN
+
++ Constant LuaDouble representing NaN (not a number) |
+
+static LuaDouble |
+LuaDouble.NEGINF
+
++ Constant LuaDouble representing negative infinity |
+
+static LuaDouble |
+LuaDouble.POSINF
+
++ Constant LuaDouble representing positive infinity |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LuaFunction | +|
---|---|
org.luaj.vm2 | ++ |
org.luaj.vm2.compiler | ++ |
org.luaj.vm2.lib | ++ |
org.luaj.vm2.lib.jme | ++ |
org.luaj.vm2.lib.jse | ++ |
org.luaj.vm2.luajc | ++ |
+Uses of LuaFunction in org.luaj.vm2 | +
---|
+ +
Subclasses of LuaFunction in org.luaj.vm2 | +|
---|---|
+ class |
+LuaClosure
+
++ Extension of LuaFunction which executes lua bytecode. |
+
+ +
Methods in org.luaj.vm2 that return LuaFunction | +|
---|---|
+static LuaFunction |
+LuaThread.getCallstackFunction(int level)
+
++ Get the function called as a specific location on the stack. |
+
+static LuaFunction |
+LoadState.load(java.io.InputStream stream,
+ java.lang.String name,
+ LuaValue env)
+
++ Load lua in either binary or text form from an input stream. |
+
+ LuaFunction |
+LoadState.LuaCompiler.load(java.io.InputStream stream,
+ java.lang.String filename,
+ LuaValue env)
+
++ Load into a Closure or LuaFunction from a Stream and initializes the environment |
+
+ LuaFunction |
+Varargs.optfunction(int i,
+ LuaFunction defval)
+
++ Return argument i as a function, defval if nil, or throw a LuaError if an incompatible type. |
+
+ LuaFunction |
+LuaFunction.optfunction(LuaFunction defval)
+
++ |
+
+ LuaFunction |
+LuaNil.optfunction(LuaFunction defval)
+
++ |
+
+ LuaFunction |
+LuaValue.optfunction(LuaFunction defval)
+
++ Check that optional argument is a function and return as LuaFunction |
+
+ +
Methods in org.luaj.vm2 with parameters of type LuaFunction | +|
---|---|
+static LuaThread.CallStack |
+LuaThread.onCall(LuaFunction function)
+
++ Callback used at the beginning of a call to prepare for possible getfenv/setfenv calls |
+
+ LuaFunction |
+Varargs.optfunction(int i,
+ LuaFunction defval)
+
++ Return argument i as a function, defval if nil, or throw a LuaError if an incompatible type. |
+
+ LuaFunction |
+LuaFunction.optfunction(LuaFunction defval)
+
++ |
+
+ LuaFunction |
+LuaNil.optfunction(LuaFunction defval)
+
++ |
+
+ LuaFunction |
+LuaValue.optfunction(LuaFunction defval)
+
++ Check that optional argument is a function and return as LuaFunction |
+
+Uses of LuaFunction in org.luaj.vm2.compiler | +
---|
+ +
Methods in org.luaj.vm2.compiler that return LuaFunction | +|
---|---|
+ LuaFunction |
+LuaC.load(java.io.InputStream stream,
+ java.lang.String name,
+ LuaValue env)
+
++ Load into a Closure or LuaFunction, with the supplied initial environment |
+
+ LuaFunction |
+LuaC.load(Prototype p,
+ java.lang.String filename,
+ LuaValue env)
+
++ |
+
+Uses of LuaFunction in org.luaj.vm2.lib | +
---|
+ +
Subclasses of LuaFunction in org.luaj.vm2.lib | +|
---|---|
+ class |
+BaseLib
+
++ Subclass of LibFunction which implements the lua basic library functions. |
+
+ class |
+CoroutineLib
+
++ Subclass of LibFunction which implements the lua standard coroutine
+ library. |
+
+ class |
+DebugLib
+
++ Subclass of LibFunction which implements the lua standard debug
+ library. |
+
+ class |
+IoLib
+
++ Abstract base class extending LibFunction which implements the
+ core of the lua standard io library. |
+
+ class |
+LibFunction
+
++ Subclass of LuaFunction common to Java functions exposed to lua. |
+
+ class |
+MathLib
+
++ Subclass of LibFunction which implements the lua standard math
+ library. |
+
+ class |
+OneArgFunction
+
++ Abstract base class for Java function implementations that take one argument and + return one value. |
+
+ class |
+OsLib
+
++ Subclass of LibFunction which implements the standard lua os library. |
+
+ class |
+PackageLib
+
++ Subclass of LibFunction which implements the lua standard package and module
+ library functions. |
+
+ class |
+StringLib
+
++ Subclass of LibFunction which implements the lua standard string
+ library. |
+
+ class |
+TableLib
+
++ Subclass of LibFunction which implements the lua standard table
+ library. |
+
+ class |
+ThreeArgFunction
+
++ Abstract base class for Java function implementations that take two arguments and + return one value. |
+
+ class |
+TwoArgFunction
+
++ Abstract base class for Java function implementations that take two arguments and + return one value. |
+
+ class |
+VarArgFunction
+
++ Abstract base class for Java function implementations that takes varaiable arguments and + returns multiple return values. |
+
+ class |
+ZeroArgFunction
+
++ Abstract base class for Java function implementations that take no arguments and + return one value. |
+
+ +
Methods in org.luaj.vm2.lib with parameters of type LuaFunction | +|
---|---|
+static void |
+DebugLib.debugOnCall(LuaThread thread,
+ int calls,
+ LuaFunction func)
+
++ Called by Closures and recursing java functions on entry |
+
+Uses of LuaFunction in org.luaj.vm2.lib.jme | +
---|
+ +
Subclasses of LuaFunction in org.luaj.vm2.lib.jme | +|
---|---|
+ class |
+JmeIoLib
+
++ Subclass of IoLib and therefore LibFunction which implements the lua standard io
+ library for the JSE platform. |
+
+Uses of LuaFunction in org.luaj.vm2.lib.jse | +
---|
+ +
Subclasses of LuaFunction in org.luaj.vm2.lib.jse | +|
---|---|
+ class |
+JseBaseLib
+
++ Subclass of BaseLib and LibFunction which implements the lua basic library functions
+ and provides a directory based ResourceFinder as the BaseLib.FINDER . |
+
+ class |
+JseIoLib
+
++ Subclass of IoLib and therefore LibFunction which implements the lua standard io
+ library for the JSE platform. |
+
+ class |
+JseMathLib
+
++ Subclass of LibFunction which implements the lua standard math
+ library. |
+
+static class |
+JseMathLib.JseMathLib1
+
++ |
+
+static class |
+JseMathLib.JseMathLib2
+
++ |
+
+ class |
+JseOsLib
+
++ Subclass of LibFunction which implements the standard lua os library. |
+
+ class |
+LuajavaLib
+
++ Subclass of LibFunction which implements the features of the luajava package. |
+
+Uses of LuaFunction in org.luaj.vm2.luajc | +
---|
+ +
Methods in org.luaj.vm2.luajc that return LuaFunction | +|
---|---|
+ LuaFunction |
+LuaJC.load(java.io.InputStream stream,
+ java.lang.String name,
+ LuaValue env)
+
++ |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LuaInteger | +|
---|---|
org.luaj.vm2 | ++ |
+Uses of LuaInteger in org.luaj.vm2 | +
---|
+ +
Methods in org.luaj.vm2 that return LuaInteger | +|
---|---|
+ LuaInteger |
+LuaDouble.checkinteger()
+
++ |
+
+ LuaInteger |
+LuaInteger.checkinteger()
+
++ |
+
+ LuaInteger |
+LuaString.checkinteger()
+
++ |
+
+ LuaInteger |
+LuaValue.checkinteger()
+
++ Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric |
+
+ LuaInteger |
+Varargs.checkinteger(int i)
+
++ Return argument i as a java int value, or throw an error if not a number or is not representable by a java int. |
+
+ LuaInteger |
+Varargs.optinteger(int i,
+ LuaInteger defval)
+
++ Return argument i as a java int value, defval if nil, or throw a LuaError if not a number or is not representable by a java int. |
+
+ LuaInteger |
+LuaDouble.optinteger(LuaInteger defval)
+
++ |
+
+ LuaInteger |
+LuaInteger.optinteger(LuaInteger defval)
+
++ |
+
+ LuaInteger |
+LuaNil.optinteger(LuaInteger defval)
+
++ |
+
+ LuaInteger |
+LuaString.optinteger(LuaInteger defval)
+
++ |
+
+ LuaInteger |
+LuaValue.optinteger(LuaInteger defval)
+
++ Check that optional argument is a number or string convertible to number and return as LuaInteger |
+
+static LuaInteger |
+LuaInteger.valueOf(int i)
+
++ |
+
+static LuaInteger |
+LuaValue.valueOf(int i)
+
++ Convert java int to a LuaValue . |
+
+ +
Methods in org.luaj.vm2 with parameters of type LuaInteger | +|
---|---|
+ LuaInteger |
+Varargs.optinteger(int i,
+ LuaInteger defval)
+
++ Return argument i as a java int value, defval if nil, or throw a LuaError if not a number or is not representable by a java int. |
+
+ LuaInteger |
+LuaDouble.optinteger(LuaInteger defval)
+
++ |
+
+ LuaInteger |
+LuaInteger.optinteger(LuaInteger defval)
+
++ |
+
+ LuaInteger |
+LuaNil.optinteger(LuaInteger defval)
+
++ |
+
+ LuaInteger |
+LuaString.optinteger(LuaInteger defval)
+
++ |
+
+ LuaInteger |
+LuaValue.optinteger(LuaInteger defval)
+
++ Check that optional argument is a number or string convertible to number and return as LuaInteger |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LuaNumber | +|
---|---|
org.luaj.vm2 | ++ |
+Uses of LuaNumber in org.luaj.vm2 | +
---|
+ +
Subclasses of LuaNumber in org.luaj.vm2 | +|
---|---|
+ class |
+LuaDouble
+
++ Extension of LuaNumber which can hold a Java double as its value. |
+
+ class |
+LuaInteger
+
++ Extension of LuaNumber which can hold a Java int as its value. |
+
+ +
Fields in org.luaj.vm2 declared as LuaNumber | +|
---|---|
+static LuaNumber |
+LuaValue.MINUSONE
+
++ LuaValue number constant equal to -1 |
+
+static LuaNumber |
+LuaValue.ONE
+
++ LuaValue number constant equal to 1 |
+
+static LuaNumber |
+LuaValue.ZERO
+
++ LuaValue number constant equal to 0 |
+
+ +
Methods in org.luaj.vm2 that return LuaNumber | +|
---|---|
+ LuaNumber |
+LuaDouble.checknumber()
+
++ |
+
+ LuaNumber |
+LuaNumber.checknumber()
+
++ |
+
+ LuaNumber |
+LuaString.checknumber()
+
++ |
+
+ LuaNumber |
+LuaValue.checknumber()
+
++ Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError |
+
+ LuaNumber |
+Varargs.checknumber(int i)
+
++ Return argument i as a LuaNumber, or throw an error if not a number or string that can be converted to a number. |
+
+ LuaNumber |
+LuaNumber.checknumber(java.lang.String errmsg)
+
++ |
+
+ LuaNumber |
+LuaString.checknumber(java.lang.String msg)
+
++ |
+
+ LuaNumber |
+LuaValue.checknumber(java.lang.String msg)
+
++ Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError |
+
+ LuaNumber |
+Varargs.optnumber(int i,
+ LuaNumber defval)
+
++ Return argument i as a LuaNumber, defval if nil, or throw a LuaError if not a number or string that can be converted to a number. |
+
+ LuaNumber |
+LuaDouble.optnumber(LuaNumber defval)
+
++ |
+
+ LuaNumber |
+LuaNil.optnumber(LuaNumber defval)
+
++ |
+
+ LuaNumber |
+LuaNumber.optnumber(LuaNumber defval)
+
++ |
+
+ LuaNumber |
+LuaString.optnumber(LuaNumber defval)
+
++ |
+
+ LuaNumber |
+LuaValue.optnumber(LuaNumber defval)
+
++ Check that optional argument is a number or string convertible to number and return as LuaNumber |
+
+static LuaNumber |
+LuaDouble.valueOf(double d)
+
++ |
+
+static LuaNumber |
+LuaValue.valueOf(double d)
+
++ Convert java double to a LuaValue . |
+
+static LuaNumber |
+LuaInteger.valueOf(long l)
+
++ Return a LuaNumber that represents the value provided |
+
+ +
Methods in org.luaj.vm2 with parameters of type LuaNumber | +|
---|---|
+ Buffer |
+Buffer.concatTo(LuaNumber lhs)
+
++ Concatenate this buffer onto a LuaNumber |
+
+ LuaValue |
+LuaNumber.concatTo(LuaNumber lhs)
+
++ |
+
+ LuaValue |
+LuaString.concatTo(LuaNumber lhs)
+
++ |
+
+ LuaValue |
+LuaValue.concatTo(LuaNumber lhs)
+
++ Reverse-concatenation: concatenate this value onto another value + known to be a LuaNumber
+ and return the result using rules of lua string concatenation including
+ metatag processing. |
+
+ LuaNumber |
+Varargs.optnumber(int i,
+ LuaNumber defval)
+
++ Return argument i as a LuaNumber, defval if nil, or throw a LuaError if not a number or string that can be converted to a number. |
+
+ LuaNumber |
+LuaDouble.optnumber(LuaNumber defval)
+
++ |
+
+ LuaNumber |
+LuaNil.optnumber(LuaNumber defval)
+
++ |
+
+ LuaNumber |
+LuaNumber.optnumber(LuaNumber defval)
+
++ |
+
+ LuaNumber |
+LuaString.optnumber(LuaNumber defval)
+
++ |
+
+ LuaNumber |
+LuaValue.optnumber(LuaNumber defval)
+
++ Check that optional argument is a number or string convertible to number and return as LuaNumber |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LuaString | +|
---|---|
org.luaj.vm2 | ++ |
org.luaj.vm2.compiler | ++ |
org.luaj.vm2.lib | ++ |
+Uses of LuaString in org.luaj.vm2 | +
---|
+ +
Fields in org.luaj.vm2 declared as LuaString | +|
---|---|
+static LuaString |
+LuaValue.ADD
+
++ LuaString constant with value "__add" for use as metatag |
+
+static LuaString |
+LuaValue.CALL
+
++ LuaString constant with value "__call" for use as metatag |
+
+static LuaString |
+LuaValue.CONCAT
+
++ LuaString constant with value "__concat" for use as metatag |
+
+static LuaString |
+LuaValue.DIV
+
++ LuaString constant with value "__div" for use as metatag |
+
+static LuaString |
+LuaValue.EMPTYSTRING
+
++ LuaString constant with value "" |
+
+static LuaString |
+LuaValue.EQ
+
++ LuaString constant with value "__eq" for use as metatag |
+
+static LuaString |
+LuaValue.INDEX
+
++ LuaString constant with value "__index" for use as metatag |
+
+static LuaString |
+LuaValue.LE
+
++ LuaString constant with value "__le" for use as metatag |
+
+static LuaString |
+LuaValue.LEN
+
++ LuaString constant with value "__len" for use as metatag |
+
+static LuaString |
+LuaValue.LT
+
++ LuaString constant with value "__lt" for use as metatag |
+
+static LuaString |
+LuaValue.METATABLE
+
++ LuaString constant with value "__metatable" for use as metatag |
+
+static LuaString |
+LuaValue.MOD
+
++ LuaString constant with value "__mod" for use as metatag |
+
+static LuaString |
+LuaValue.MODE
+
++ LuaString constant with value "__mode" for use as metatag |
+
+static LuaString |
+LuaValue.MUL
+
++ LuaString constant with value "__mul" for use as metatag |
+
+static LuaString |
+LuaValue.NEWINDEX
+
++ LuaString constant with value "__newindex" for use as metatag |
+
+static LuaString |
+LuaValue.POW
+
++ LuaString constant with value "__pow" for use as metatag |
+
+ LuaString |
+Prototype.source
+
++ |
+
+static LuaString |
+LuaValue.SUB
+
++ LuaString constant with value "__sub" for use as metatag |
+
+static LuaString |
+LuaValue.TOSTRING
+
++ LuaString constant with value "__tostring" for use as metatag |
+
+static LuaString |
+LuaValue.UNM
+
++ LuaString constant with value "__unm" for use as metatag |
+
+ LuaString[] |
+Prototype.upvalues
+
++ |
+
+ LuaString |
+LocVars.varname
+
++ The local variable name |
+
+ +
Methods in org.luaj.vm2 that return LuaString | +|
---|---|
+ LuaString |
+LuaDouble.checkstring()
+
++ |
+
+ LuaString |
+LuaInteger.checkstring()
+
++ |
+
+ LuaString |
+LuaString.checkstring()
+
++ |
+
+ LuaString |
+LuaValue.checkstring()
+
++ Check that this is a lua string, or throw LuaError if it is not. |
+
+ LuaString |
+Varargs.checkstring(int i)
+
++ Return argument i as a LuaString if a string or number, or throw an error if any other type |
+
+ LuaString |
+Prototype.getlocalname(int number,
+ int pc)
+
++ Get the name of a local variable. |
+
+ LuaString |
+Varargs.optstring(int i,
+ LuaString defval)
+
++ Return argument i as a LuaString if a string or number, defval if nil, or throw a LuaError if any other type |
+
+ LuaString |
+LuaDouble.optstring(LuaString defval)
+
++ |
+
+ LuaString |
+LuaInteger.optstring(LuaString defval)
+
++ |
+
+ LuaString |
+LuaNil.optstring(LuaString defval)
+
++ |
+
+ LuaString |
+LuaString.optstring(LuaString defval)
+
++ |
+
+ LuaString |
+LuaValue.optstring(LuaString defval)
+
++ Check that optional argument is a string or number and return as LuaString |
+
+ LuaString |
+LuaDouble.strvalue()
+
++ |
+
+ LuaString |
+LuaInteger.strvalue()
+
++ |
+
+ LuaString |
+LuaString.strvalue()
+
++ |
+
+ LuaString |
+LuaValue.strvalue()
+
++ Convert this value to a string if it is a LuaString or LuaNumber ,
+ or throw a LuaError if it is not |
+
+ LuaString |
+LuaString.substring(int beginIndex,
+ int endIndex)
+
++ |
+
+ LuaString |
+Buffer.tostring()
+
++ Convert the buffer to a LuaString |
+
+static LuaString |
+LuaString.valueOf(byte[] bytes)
+
++ Construct a LuaString around a byte array without copying the contents. |
+
+static LuaString |
+LuaValue.valueOf(byte[] bytes)
+
++ Convert bytes in an array to a LuaValue . |
+
+static LuaString |
+LuaString.valueOf(byte[] bytes,
+ int off,
+ int len)
+
++ Construct a LuaString around a byte array without copying the contents. |
+
+static LuaString |
+LuaValue.valueOf(byte[] bytes,
+ int off,
+ int len)
+
++ Convert bytes in an array to a LuaValue . |
+
+static LuaString |
+LuaString.valueOf(char[] bytes)
+
++ Construct a LuaString using the supplied characters as byte values. |
+
+static LuaString |
+LuaString.valueOf(java.lang.String string)
+
++ Get a LuaString instance whose bytes match
+ the supplied Java String using the UTF8 encoding. |
+
+static LuaString |
+LuaValue.valueOf(java.lang.String s)
+
++ Convert java string to a LuaValue . |
+
+ +
Methods in org.luaj.vm2 with parameters of type LuaString | +|
---|---|
+ Buffer |
+Buffer.append(LuaString str)
+
++ Append a LuaString to the buffer. |
+
+ LuaValue |
+LuaTable.concat(LuaString sep,
+ int i,
+ int j)
+
++ Concatenate the contents of a table efficiently, using Buffer |
+
+ Buffer |
+Buffer.concatTo(LuaString lhs)
+
++ Concatenate this buffer onto a LuaString |
+
+ LuaValue |
+LuaNumber.concatTo(LuaString lhs)
+
++ |
+
+ LuaValue |
+LuaString.concatTo(LuaString lhs)
+
++ |
+
+ LuaValue |
+LuaValue.concatTo(LuaString lhs)
+
++ Reverse-concatenation: concatenate this value onto another value + known to be a LuaString
+ and return the result using rules of lua string concatenation including
+ metatag processing. |
+
+static boolean |
+LuaString.equals(LuaString a,
+ int i,
+ LuaString b,
+ int j,
+ int n)
+
++ |
+
+ int |
+LuaString.indexOf(LuaString s,
+ int start)
+
++ Find the index of a string starting at a point in this string |
+
+ int |
+LuaString.indexOfAny(LuaString accept)
+
++ Java version of strpbrk - find index of any byte that in an accept string. |
+
+ int |
+LuaString.lastIndexOf(LuaString s)
+
++ Find the last index of a string in this string |
+
+ Prototype |
+LoadState.loadFunction(LuaString p)
+
++ Load a function prototype from the input stream |
+
+ LuaString |
+Varargs.optstring(int i,
+ LuaString defval)
+
++ Return argument i as a LuaString if a string or number, defval if nil, or throw a LuaError if any other type |
+
+ LuaString |
+LuaDouble.optstring(LuaString defval)
+
++ |
+
+ LuaString |
+LuaInteger.optstring(LuaString defval)
+
++ |
+
+ LuaString |
+LuaNil.optstring(LuaString defval)
+
++ |
+
+ LuaString |
+LuaString.optstring(LuaString defval)
+
++ |
+
+ LuaString |
+LuaValue.optstring(LuaString defval)
+
++ Check that optional argument is a string or number and return as LuaString |
+
+ Buffer |
+Buffer.prepend(LuaString s)
+
++ Concatenate bytes from a LuaString onto the front of this buffer |
+
+ boolean |
+LuaString.raweq(LuaString s)
+
++ |
+
+ boolean |
+LuaValue.raweq(LuaString val)
+
++ Equals: Perform direct equality comparison with a LuaString value
+ without metatag processing. |
+
+ int |
+LuaDouble.strcmp(LuaString rhs)
+
++ |
+
+ int |
+LuaInteger.strcmp(LuaString rhs)
+
++ |
+
+ int |
+LuaString.strcmp(LuaString rhs)
+
++ |
+
+ int |
+LuaValue.strcmp(LuaString rhs)
+
++ Perform string comparison with another value + known to be a LuaString
+ using string comparison based on byte values. |
+
+ +
Constructors in org.luaj.vm2 with parameters of type LuaString | +|
---|---|
LocVars(LuaString varname,
+ int startpc,
+ int endpc)
+
++ Construct a LocVars instance. |
+
+Uses of LuaString in org.luaj.vm2.compiler | +
---|
+ +
Methods in org.luaj.vm2.compiler that return LuaString | +|
---|---|
+ LuaString |
+LuaC.newTString(byte[] bytes,
+ int offset,
+ int len)
+
++ |
+
+Uses of LuaString in org.luaj.vm2.lib | +
---|
+ +
Methods in org.luaj.vm2.lib with parameters of type LuaString | +|
---|---|
+abstract void |
+IoLib.File.write(LuaString string)
+
++ |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LuaTable | +|
---|---|
org.luaj.vm2 | ++ |
org.luaj.vm2.lib | ++ |
org.luaj.vm2.lib.jme | ++ |
org.luaj.vm2.lib.jse | ++ |
+Uses of LuaTable in org.luaj.vm2 | +
---|
+ +
Subclasses of LuaTable in org.luaj.vm2 | +|
---|---|
+ class |
+WeakTable
+
++ Subclass of LuaTable that provides weak key and weak value semantics. |
+
+ +
Methods in org.luaj.vm2 that return LuaTable | +|
---|---|
+protected LuaTable |
+LuaTable.changemode(boolean weakkeys,
+ boolean weakvalues)
+
++ Change the mode of a table |
+
+protected LuaTable |
+WeakTable.changemode(boolean weakkeys,
+ boolean weakvalues)
+
++ |
+
+ LuaTable |
+LuaTable.checktable()
+
++ |
+
+ LuaTable |
+LuaValue.checktable()
+
++ Check that this is a LuaTable , or throw LuaError if it is not |
+
+ LuaTable |
+Varargs.checktable(int i)
+
++ Return argument i as a LuaTable if a lua table, or throw an error if any other type. |
+
+static LuaTable |
+LuaValue.listOf(LuaValue[] unnamedValues)
+
++ Construct a LuaTable initialized with supplied array values. |
+
+static LuaTable |
+LuaValue.listOf(LuaValue[] unnamedValues,
+ Varargs lastarg)
+
++ Construct a LuaTable initialized with supplied array values. |
+
+ LuaTable |
+Varargs.opttable(int i,
+ LuaTable defval)
+
++ Return argument i as a LuaTable if a lua table, defval if nil, or throw a LuaError if any other type. |
+
+ LuaTable |
+LuaNil.opttable(LuaTable defval)
+
++ |
+
+ LuaTable |
+LuaTable.opttable(LuaTable defval)
+
++ |
+
+ LuaTable |
+LuaValue.opttable(LuaTable defval)
+
++ Check that optional argument is a table and return as LuaTable |
+
+static LuaTable |
+LuaValue.tableOf()
+
++ Construct an empty LuaTable . |
+
+static LuaTable |
+LuaValue.tableOf(int narray,
+ int nhash)
+
++ Construct an empty LuaTable preallocated to hold array and hashed elements |
+
+static LuaTable |
+LuaValue.tableOf(LuaValue[] namedValues)
+
++ Construct a LuaTable initialized with supplied named values. |
+
+static LuaTable |
+LuaValue.tableOf(LuaValue[] namedValues,
+ LuaValue[] unnamedValues)
+
++ Construct a LuaTable initialized with supplied named values and sequential elements. |
+
+static LuaTable |
+LuaValue.tableOf(LuaValue[] namedValues,
+ LuaValue[] unnamedValues,
+ Varargs lastarg)
+
++ Construct a LuaTable initialized with supplied named values and sequential elements in an array part and as varargs. |
+
+static LuaTable |
+LuaValue.tableOf(Varargs varargs,
+ int firstarg)
+
++ Construct a LuaTable initialized with supplied array values. |
+
+ +
Methods in org.luaj.vm2 with parameters of type LuaTable | +|
---|---|
+ LuaTable |
+Varargs.opttable(int i,
+ LuaTable defval)
+
++ Return argument i as a LuaTable if a lua table, defval if nil, or throw a LuaError if any other type. |
+
+ LuaTable |
+LuaNil.opttable(LuaTable defval)
+
++ |
+
+ LuaTable |
+LuaTable.opttable(LuaTable defval)
+
++ |
+
+ LuaTable |
+LuaValue.opttable(LuaTable defval)
+
++ Check that optional argument is a table and return as LuaTable |
+
+ +
Constructors in org.luaj.vm2 with parameters of type LuaTable | +|
---|---|
WeakTable(boolean weakkeys,
+ boolean weakvalues,
+ LuaTable source)
+
++ Construct a table with weak keys, weak values, or both, and a source of initial data |
+
+Uses of LuaTable in org.luaj.vm2.lib | +
---|
+ +
Fields in org.luaj.vm2.lib declared as LuaTable | +|
---|---|
+static LuaTable |
+StringLib.instance
+
++ |
+
+ LuaTable |
+PackageLib.LOADED
+
++ |
+
+ LuaTable |
+PackageLib.PACKAGE
+
++ |
+
+ +
Methods in org.luaj.vm2.lib with parameters of type LuaTable | +|
---|---|
+ void |
+PackageLib.setIsLoaded(java.lang.String name,
+ LuaTable value)
+
++ Allow packages to mark themselves as loaded |
+
+protected long |
+OsLib.time(LuaTable table)
+
++ Returns the current time when called without arguments, + or a time representing the date and time specified by the given table. |
+
+Uses of LuaTable in org.luaj.vm2.lib.jme | +
---|
+ +
Methods in org.luaj.vm2.lib.jme that return LuaTable | +|
---|---|
+static LuaTable |
+JmePlatform.debugGlobals()
+
++ Create standard globals including the debug library. |
+
+static LuaTable |
+JmePlatform.standardGlobals()
+
++ Create a standard set of globals for JME including all the libraries. |
+
+Uses of LuaTable in org.luaj.vm2.lib.jse | +
---|
+ +
Methods in org.luaj.vm2.lib.jse that return LuaTable | +|
---|---|
+static LuaTable |
+JsePlatform.debugGlobals()
+
++ Create standard globals including the debug library. |
+
+static LuaTable |
+JsePlatform.standardGlobals()
+
++ Create a standard set of globals for JSE including all the libraries. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LuaThread.CallStack | +|
---|---|
org.luaj.vm2 | ++ |
+Uses of LuaThread.CallStack in org.luaj.vm2 | +
---|
+ +
Methods in org.luaj.vm2 that return LuaThread.CallStack | +|
---|---|
+static LuaThread.CallStack |
+LuaThread.onCall(LuaFunction function)
+
++ Callback used at the beginning of a call to prepare for possible getfenv/setfenv calls |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LuaThread | +|
---|---|
org.luaj.vm2 | ++ |
org.luaj.vm2.lib | ++ |
+Uses of LuaThread in org.luaj.vm2 | +
---|
+ +
Methods in org.luaj.vm2 that return LuaThread | +|
---|---|
+ LuaThread |
+LuaThread.checkthread()
+
++ |
+
+ LuaThread |
+LuaValue.checkthread()
+
++ Check that this is a LuaThread , or throw LuaError if it is not |
+
+ LuaThread |
+Varargs.checkthread(int i)
+
++ Return argument i as a LuaThread if a lua thread, or throw an error if any other type. |
+
+static LuaThread |
+LuaThread.getRunning()
+
++ Get the currently running thread. |
+
+ LuaThread |
+Varargs.optthread(int i,
+ LuaThread defval)
+
++ Return argument i as a LuaThread if a lua thread, defval if nil, or throw a LuaError if any other type. |
+
+ LuaThread |
+LuaNil.optthread(LuaThread defval)
+
++ |
+
+ LuaThread |
+LuaThread.optthread(LuaThread defval)
+
++ |
+
+ LuaThread |
+LuaValue.optthread(LuaThread defval)
+
++ Check that optional argument is a thread and return as LuaThread |
+
+ +
Methods in org.luaj.vm2 with parameters of type LuaThread | +|
---|---|
+static boolean |
+LuaThread.isMainThread(LuaThread r)
+
++ Test if this is the main thread |
+
+ LuaThread |
+Varargs.optthread(int i,
+ LuaThread defval)
+
++ Return argument i as a LuaThread if a lua thread, defval if nil, or throw a LuaError if any other type. |
+
+ LuaThread |
+LuaNil.optthread(LuaThread defval)
+
++ |
+
+ LuaThread |
+LuaThread.optthread(LuaThread defval)
+
++ |
+
+ LuaThread |
+LuaValue.optthread(LuaThread defval)
+
++ Check that optional argument is a thread and return as LuaThread |
+
+Uses of LuaThread in org.luaj.vm2.lib | +
---|
+ +
Methods in org.luaj.vm2.lib with parameters of type LuaThread | +|
---|---|
+static void |
+DebugLib.debugOnCall(LuaThread thread,
+ int calls,
+ LuaFunction func)
+
++ Called by Closures and recursing java functions on entry |
+
+static void |
+DebugLib.debugOnReturn(LuaThread thread,
+ int calls)
+
++ Called by Closures and recursing java functions on return |
+
+static java.lang.String |
+DebugLib.traceback(LuaThread thread,
+ int level)
+
++ Get a traceback for a particular thread. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LuaUserdata | +|
---|---|
org.luaj.vm2 | ++ |
+Uses of LuaUserdata in org.luaj.vm2 | +
---|
+ +
Methods in org.luaj.vm2 that return LuaUserdata | +|
---|---|
+static LuaUserdata |
+LuaValue.userdataOf(java.lang.Object o)
+
++ Construct a LuaUserdata for an object. |
+
+static LuaUserdata |
+LuaValue.userdataOf(java.lang.Object o,
+ LuaValue metatable)
+
++ Construct a LuaUserdata for an object with a user supplied metatable. |
+
+ +
Methods in org.luaj.vm2 with parameters of type LuaUserdata | +|
---|---|
+ boolean |
+LuaUserdata.raweq(LuaUserdata val)
+
++ |
+
+ boolean |
+LuaValue.raweq(LuaUserdata val)
+
++ Equals: Perform direct equality comparison with a LuaUserdata value
+ without metatag processing. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LuaValue | +|
---|---|
org.luaj.vm2 | ++ |
org.luaj.vm2.compiler | ++ |
org.luaj.vm2.lib | ++ |
org.luaj.vm2.lib.jme | ++ |
org.luaj.vm2.lib.jse | ++ |
org.luaj.vm2.luajc | ++ |
+Uses of LuaValue in org.luaj.vm2 | +
---|
+ +
Subclasses of LuaValue in org.luaj.vm2 | +|
---|---|
+ class |
+LuaBoolean
+
++ Extension of LuaValue which can hold a Java boolean as its value. |
+
+ class |
+LuaClosure
+
++ Extension of LuaFunction which executes lua bytecode. |
+
+ class |
+LuaDouble
+
++ Extension of LuaNumber which can hold a Java double as its value. |
+
+ class |
+LuaFunction
+
++ Base class for functions implemented in Java. |
+
+ class |
+LuaInteger
+
++ Extension of LuaNumber which can hold a Java int as its value. |
+
+ class |
+LuaNil
+
++ Class to encapsulate behavior of the singleton instance nil |
+
+ class |
+LuaNumber
+
++ Base class for representing numbers as lua values directly. |
+
+ class |
+LuaString
+
++ Subclass of LuaValue for representing lua strings. |
+
+ class |
+LuaTable
+
++ Subclass of LuaValue for representing lua tables. |
+
+ class |
+LuaThread
+
++ Subclass of LuaValue that implements
+ a lua coroutine thread using Java Threads. |
+
+ class |
+LuaUserdata
+
++ |
+
+ class |
+WeakTable
+
++ Subclass of LuaTable that provides weak key and weak value semantics. |
+
+ +
Fields in org.luaj.vm2 declared as LuaValue | +|
---|---|
+protected LuaValue[] |
+LuaTable.array
+
++ the array values |
+
+protected LuaValue |
+LuaFunction.env
+
++ |
+
+ LuaValue |
+LuaThread.err
+
++ Field to hold state of error condition during debug hook function calls. |
+
+protected LuaValue[] |
+LuaTable.hashKeys
+
++ the hash keys |
+
+protected LuaValue[] |
+LuaTable.hashValues
+
++ the hash values |
+
+ LuaValue[] |
+Prototype.k
+
++ |
+
+protected LuaValue |
+LuaTable.m_metatable
+
++ metatable for this table, or null |
+
+ LuaValue |
+LuaUserdata.m_metatable
+
++ |
+
+static LuaValue |
+LuaValue.NIL
+
++ LuaValue constant corresponding to lua nil |
+
+static LuaValue[] |
+LuaValue.NILS
+
++ Array of NIL values to optimize filling stacks using System.arraycopy(). |
+
+static LuaValue |
+LuaValue.NONE
+
++ LuaValue constant corresponding to a Varargs list of no values |
+
+static LuaValue[] |
+LuaValue.NOVALS
+
++ LuaValue array constant with no values |
+
+static LuaValue |
+LuaBoolean.s_metatable
+
++ Shared static metatable for boolean values represented in lua. |
+
+static LuaValue |
+LuaFunction.s_metatable
+
++ Shared static metatable for all functions and closures. |
+
+static LuaValue |
+LuaNil.s_metatable
+
++ |
+
+static LuaValue |
+LuaNumber.s_metatable
+
++ Shared static metatable for all number values represented in lua. |
+
+static LuaValue |
+LuaString.s_metatable
+
++ The singleton instance representing lua true |
+
+static LuaValue |
+LuaThread.s_metatable
+
++ |
+
+ +
Methods in org.luaj.vm2 that return LuaValue | +|
---|---|
+ LuaValue |
+LuaDouble.add(double lhs)
+
++ |
+
+ LuaValue |
+LuaInteger.add(double lhs)
+
++ |
+
+ LuaValue |
+LuaString.add(double rhs)
+
++ |
+
+ LuaValue |
+LuaValue.add(double rhs)
+
++ Add: Perform numeric add operation with another value + of double type with metatag processing |
+
+ LuaValue |
+LuaInteger.add(int lhs)
+
++ |
+
+ LuaValue |
+LuaString.add(int rhs)
+
++ |
+
+ LuaValue |
+LuaValue.add(int rhs)
+
++ Add: Perform numeric add operation with another value + of int type with metatag processing |
+
+ LuaValue |
+LuaDouble.add(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.add(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.add(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.add(LuaValue rhs)
+
++ Add: Perform numeric add operation with another value + including metatag processing. |
+
+ LuaValue |
+LuaValue.and(LuaValue rhs)
+
++ Perform boolean and with another operand, based on lua rules for boolean evaluation. |
+
+ LuaValue |
+LuaValue.arg(int index)
+
++ |
+
+ LuaValue |
+TailcallVarargs.arg(int i)
+
++ |
+
+abstract LuaValue |
+Varargs.arg(int i)
+
++ Get the n-th argument value (1-based). |
+
+ LuaValue |
+LuaValue.arg1()
+
++ |
+
+ LuaValue |
+TailcallVarargs.arg1()
+
++ |
+
+abstract LuaValue |
+Varargs.arg1()
+
++ Get the first argument in the list. |
+
+static LuaValue |
+LuaValue.argerror(int iarg,
+ java.lang.String msg)
+
++ Throw a LuaError indicating an invalid argument was supplied to a function |
+
+protected LuaValue |
+LuaValue.argerror(java.lang.String expected)
+
++ Throw a LuaError indicating an invalid argument was supplied to a function |
+
+protected LuaValue |
+LuaValue.aritherror()
+
++ Throw a LuaError based on an arithmetic error such as add, or pow,
+ typically due to an invalid operand type |
+
+protected LuaValue |
+LuaValue.aritherror(java.lang.String fun)
+
++ Throw a LuaError based on an arithmetic error such as add, or pow,
+ typically due to an invalid operand type |
+
+protected LuaValue |
+LuaValue.arithmt(LuaValue tag,
+ LuaValue op2)
+
++ Perform metatag processing for arithmetic operations. |
+
+protected LuaValue |
+LuaValue.arithmtwith(LuaValue tag,
+ double op1)
+
++ Perform metatag processing for arithmetic operations when the left-hand-side is a number. |
+
+ LuaValue |
+LuaClosure.call()
+
++ |
+
+ LuaValue |
+LuaValue.call()
+
++ Call this with 0 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaClosure.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+LuaValue.call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaClosure.call(LuaValue arg1,
+ LuaValue arg2)
+
++ |
+
+ LuaValue |
+LuaValue.call(LuaValue arg1,
+ LuaValue arg2)
+
++ Call this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaClosure.call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ |
+
+ LuaValue |
+LuaValue.call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ Call this with 3 arguments, including metatag processing,
+ and return only the first return value. |
+
+protected LuaValue |
+LuaValue.callmt()
+
++ Get the metatag value for the CALL metatag, if it exists. |
+
+ LuaValue |
+LuaFunction.checkfunction()
+
++ |
+
+ LuaValue |
+LuaValue.checkfunction()
+
++ Check that the value is a function , or throw LuaError if not |
+
+ LuaValue |
+Varargs.checkfunction(int i)
+
++ Return argument i as a function, or throw an error if an incompatible type. |
+
+protected LuaValue |
+LuaValue.checkmetatag(LuaValue tag,
+ java.lang.String reason)
+
++ Get particular metatag, or throw LuaError if it doesn't exist |
+
+ LuaValue |
+LuaNil.checknotnil()
+
++ |
+
+ LuaValue |
+LuaValue.checknotnil()
+
++ Check that this is not the value NIL , or throw LuaError if it is |
+
+ LuaValue |
+Varargs.checknotnil(int i)
+
++ Return argument i as a LuaValue if it is not nil, or throw an error if it is nil. |
+
+ LuaValue |
+LuaDouble.checkvalidkey()
+
++ |
+
+ LuaValue |
+LuaNil.checkvalidkey()
+
++ |
+
+ LuaValue |
+LuaValue.checkvalidkey()
+
++ Check that this is a valid key in a table index operation, or throw LuaError if not |
+
+ LuaValue |
+Varargs.checkvalue(int i)
+
++ Return argument i as a LuaValue if it exists, or throw an error. |
+
+protected LuaValue |
+LuaValue.compareerror(LuaValue rhs)
+
++ Throw a LuaError based on a comparison error such as greater-than or less-than,
+ typically due to an invalid operand type |
+
+protected LuaValue |
+LuaValue.compareerror(java.lang.String rhs)
+
++ Throw a LuaError based on a comparison error such as greater-than or less-than,
+ typically due to an invalid operand type |
+
+ LuaValue |
+LuaValue.comparemt(LuaValue tag,
+ LuaValue op1)
+
++ Perform metatag processing for comparison operations. |
+
+ LuaValue |
+LuaTable.concat(LuaString sep,
+ int i,
+ int j)
+
++ Concatenate the contents of a table efficiently, using Buffer |
+
+ LuaValue |
+LuaNumber.concat(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.concat(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.concat(LuaValue rhs)
+
++ Concatenate another value onto this value and return the result + using rules of lua string concatenation including metatag processing. |
+
+ LuaValue |
+LuaValue.concatmt(LuaValue rhs)
+
++ Perform metatag processing for concatenation operations. |
+
+ LuaValue |
+LuaNumber.concatTo(LuaNumber lhs)
+
++ |
+
+ LuaValue |
+LuaString.concatTo(LuaNumber lhs)
+
++ |
+
+ LuaValue |
+LuaValue.concatTo(LuaNumber lhs)
+
++ Reverse-concatenation: concatenate this value onto another value + known to be a LuaNumber
+ and return the result using rules of lua string concatenation including
+ metatag processing. |
+
+ LuaValue |
+LuaNumber.concatTo(LuaString lhs)
+
++ |
+
+ LuaValue |
+LuaString.concatTo(LuaString lhs)
+
++ |
+
+ LuaValue |
+LuaValue.concatTo(LuaString lhs)
+
++ Reverse-concatenation: concatenate this value onto another value + known to be a LuaString
+ and return the result using rules of lua string concatenation including
+ metatag processing. |
+
+ LuaValue |
+LuaValue.concatTo(LuaValue lhs)
+
++ Reverse-concatenation: concatenate this value onto another value + whose type is unknwon + and return the result using rules of lua string concatenation including + metatag processing. |
+
+static LuaValue |
+LuaDouble.ddiv(double lhs,
+ double rhs)
+
++ Divide two double numbers according to lua math, and return a LuaValue result. |
+
+ LuaValue |
+LuaDouble.div(double rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.div(double rhs)
+
++ |
+
+ LuaValue |
+LuaString.div(double rhs)
+
++ |
+
+ LuaValue |
+LuaValue.div(double rhs)
+
++ Divide: Perform numeric divide operation by another value + of double type without metatag processing |
+
+ LuaValue |
+LuaDouble.div(int rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.div(int rhs)
+
++ |
+
+ LuaValue |
+LuaString.div(int rhs)
+
++ |
+
+ LuaValue |
+LuaValue.div(int rhs)
+
++ Divide: Perform numeric divide operation by another value + of int type without metatag processing |
+
+ LuaValue |
+LuaDouble.div(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.div(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.div(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.div(LuaValue rhs)
+
++ Divide: Perform numeric divide operation by another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+LuaDouble.divInto(double lhs)
+
++ |
+
+ LuaValue |
+LuaInteger.divInto(double lhs)
+
++ |
+
+ LuaValue |
+LuaString.divInto(double lhs)
+
++ |
+
+ LuaValue |
+LuaValue.divInto(double lhs)
+
++ Reverse-divide: Perform numeric divide operation into another value + with metatag processing |
+
+static LuaValue |
+LuaDouble.dmod(double lhs,
+ double rhs)
+
++ Take modulo double numbers according to lua math, and return a LuaValue result. |
+
+ LuaValue |
+LuaDouble.eq(LuaValue val)
+
++ |
+
+ LuaValue |
+LuaInteger.eq(LuaValue val)
+
++ |
+
+ LuaValue |
+LuaString.eq(LuaValue val)
+
++ |
+
+ LuaValue |
+LuaTable.eq(LuaValue val)
+
++ |
+
+ LuaValue |
+LuaUserdata.eq(LuaValue val)
+
++ |
+
+ LuaValue |
+LuaValue.eq(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ . |
+
+static LuaValue |
+LuaValue.error(java.lang.String message)
+
++ Throw a LuaError with a particular message |
+
+ LuaValue |
+LuaTable.foreach(LuaValue func)
+
++ Call the supplied function once for each key-value pair |
+
+ LuaValue |
+LuaTable.foreachi(LuaValue func)
+
++ Call the supplied function once for each key-value pair + in the contiguous array part |
+
+ LuaValue |
+LuaTable.get(int key)
+
++ |
+
+ LuaValue |
+LuaValue.get(int key)
+
++ Get a value in a table including metatag processing using INDEX . |
+
+ LuaValue |
+LuaString.get(LuaValue key)
+
++ |
+
+ LuaValue |
+LuaTable.get(LuaValue key)
+
++ |
+
+ LuaValue |
+LuaUserdata.get(LuaValue key)
+
++ |
+
+ LuaValue |
+LuaValue.get(LuaValue key)
+
++ Get a value in a table including metatag processing using INDEX . |
+
+ LuaValue |
+LuaValue.get(java.lang.String key)
+
++ Get a value in a table including metatag processing using INDEX . |
+
+ LuaValue |
+LuaFunction.getfenv()
+
++ |
+
+ LuaValue |
+LuaThread.getfenv()
+
++ |
+
+ LuaValue |
+LuaValue.getfenv()
+
++ Get the environemnt for an instance. |
+
+static LuaValue |
+LuaThread.getGlobals()
+
++ Get the current thread's environment |
+
+ LuaValue |
+LuaBoolean.getmetatable()
+
++ |
+
+ LuaValue |
+LuaClosure.getmetatable()
+
++ |
+
+ LuaValue |
+LuaFunction.getmetatable()
+
++ |
+
+ LuaValue |
+LuaNil.getmetatable()
+
++ |
+
+ LuaValue |
+LuaNumber.getmetatable()
+
++ |
+
+ LuaValue |
+LuaString.getmetatable()
+
++ |
+
+ LuaValue |
+LuaTable.getmetatable()
+
++ |
+
+ LuaValue |
+LuaThread.getmetatable()
+
++ |
+
+ LuaValue |
+LuaUserdata.getmetatable()
+
++ |
+
+ LuaValue |
+LuaValue.getmetatable()
+
++ Get the metatable for this LuaValue |
+
+ LuaValue |
+LuaTable.getn()
+
++ |
+
+ LuaValue |
+LuaValue.getn()
+
++ Implementation of lua 5.0 getn() function. |
+
+protected static LuaValue |
+LuaValue.gettable(LuaValue t,
+ LuaValue key)
+
++ get value from metatable operations, or NIL if not defined by metatables |
+
+protected LuaValue |
+LuaClosure.getUpvalue(int i)
+
++ |
+
+ LuaValue |
+UpValue.getValue()
+
++ Get the value of the upvalue |
+
+ LuaValue |
+LuaDouble.gt(double rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.gt(double rhs)
+
++ |
+
+ LuaValue |
+LuaValue.gt(double rhs)
+
++ Greater than: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+LuaDouble.gt(int rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.gt(int rhs)
+
++ |
+
+ LuaValue |
+LuaValue.gt(int rhs)
+
++ Greater than: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+LuaDouble.gt(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.gt(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.gt(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.gt(LuaValue rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+LuaDouble.gteq(double rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.gteq(double rhs)
+
++ |
+
+ LuaValue |
+LuaValue.gteq(double rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+LuaDouble.gteq(int rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.gteq(int rhs)
+
++ |
+
+ LuaValue |
+LuaValue.gteq(int rhs)
+
++ Greater than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+LuaDouble.gteq(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.gteq(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.gteq(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.gteq(LuaValue rhs)
+
++ Greater than or equals: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+protected LuaValue |
+LuaTable.hashget(LuaValue key)
+
++ |
+
+protected LuaValue |
+WeakTable.hashget(LuaValue key)
+
++ Get the hash value for a key + key the key to look up |
+
+protected LuaValue |
+LuaValue.illegal(java.lang.String op,
+ java.lang.String typename)
+
++ Throw a LuaError indicating an illegal operation occurred,
+ typically involved in managing weak references |
+
+ LuaValue[] |
+LuaTable.keys()
+
++ This may be deprecated in a future release. |
+
+ LuaValue |
+LuaString.len()
+
++ |
+
+ LuaValue |
+LuaTable.len()
+
++ |
+
+ LuaValue |
+LuaValue.len()
+
++ Length operator: return lua length of object (#this) including metatag processing as java int |
+
+protected LuaValue |
+LuaValue.lenerror()
+
++ Throw a LuaError based on the len operator,
+ typically due to an invalid operand type |
+
+ LuaValue |
+LuaValue.load(LuaValue library)
+
++ Load a library instance by setting its environment to this
+ and calling it, which should iniitalize the library instance and
+ install itself into this instance. |
+
+static LuaValue |
+LoadState.longBitsToLuaNumber(long bits)
+
++ Convert bits in a long value to a LuaValue . |
+
+ LuaValue |
+LuaDouble.lt(double rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.lt(double rhs)
+
++ |
+
+ LuaValue |
+LuaValue.lt(double rhs)
+
++ Less than: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+LuaDouble.lt(int rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.lt(int rhs)
+
++ |
+
+ LuaValue |
+LuaValue.lt(int rhs)
+
++ Less than: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+LuaDouble.lt(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.lt(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.lt(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.lt(LuaValue rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+LuaDouble.lteq(double rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.lteq(double rhs)
+
++ |
+
+ LuaValue |
+LuaValue.lteq(double rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of double type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+LuaDouble.lteq(int rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.lteq(int rhs)
+
++ |
+
+ LuaValue |
+LuaValue.lteq(int rhs)
+
++ Less than or equals: Perform numeric comparison with another value + of int type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+LuaDouble.lteq(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.lteq(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.lteq(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.lteq(LuaValue rhs)
+
++ Less than or equals: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+LuaValue.metatag(LuaValue tag)
+
++ Get particular metatag, or return NIL if it doesn't exist |
+
+ LuaValue |
+LuaValue.method(LuaValue name)
+
++ Call named method on this with 0 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaValue.method(LuaValue name,
+ LuaValue arg)
+
++ Call named method on this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaValue.method(LuaValue name,
+ LuaValue arg1,
+ LuaValue arg2)
+
++ Call named method on this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaValue.method(java.lang.String name)
+
++ Call named method on this with 0 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaValue.method(java.lang.String name,
+ LuaValue arg)
+
++ Call named method on this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaValue.method(java.lang.String name,
+ LuaValue arg1,
+ LuaValue arg2)
+
++ Call named method on this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaDouble.mod(double rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.mod(double rhs)
+
++ |
+
+ LuaValue |
+LuaString.mod(double rhs)
+
++ |
+
+ LuaValue |
+LuaValue.mod(double rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of double type without metatag processing |
+
+ LuaValue |
+LuaDouble.mod(int rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.mod(int rhs)
+
++ |
+
+ LuaValue |
+LuaString.mod(int rhs)
+
++ |
+
+ LuaValue |
+LuaValue.mod(int rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of int type without metatag processing |
+
+ LuaValue |
+LuaDouble.mod(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.mod(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.mod(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.mod(LuaValue rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+LuaDouble.modFrom(double lhs)
+
++ |
+
+ LuaValue |
+LuaInteger.modFrom(double lhs)
+
++ |
+
+ LuaValue |
+LuaString.modFrom(double lhs)
+
++ |
+
+ LuaValue |
+LuaValue.modFrom(double lhs)
+
++ Reverse-modulo: Perform numeric modulo operation from another value + with metatag processing |
+
+ LuaValue |
+LuaDouble.mul(double lhs)
+
++ |
+
+ LuaValue |
+LuaInteger.mul(double lhs)
+
++ |
+
+ LuaValue |
+LuaString.mul(double rhs)
+
++ |
+
+ LuaValue |
+LuaValue.mul(double rhs)
+
++ Multiply: Perform numeric multiply operation with another value + of double type with metatag processing |
+
+ LuaValue |
+LuaDouble.mul(int lhs)
+
++ |
+
+ LuaValue |
+LuaInteger.mul(int lhs)
+
++ |
+
+ LuaValue |
+LuaString.mul(int rhs)
+
++ |
+
+ LuaValue |
+LuaValue.mul(int rhs)
+
++ Multiply: Perform numeric multiply operation with another value + of int type with metatag processing |
+
+ LuaValue |
+LuaDouble.mul(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.mul(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.mul(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.mul(LuaValue rhs)
+
++ Multiply: Perform numeric multiply operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+LuaDouble.neg()
+
++ |
+
+ LuaValue |
+LuaInteger.neg()
+
++ |
+
+ LuaValue |
+LuaString.neg()
+
++ |
+
+ LuaValue |
+LuaValue.neg()
+
++ Unary minus: return negative value (-this) as defined by lua unary minus operator |
+
+ LuaValue |
+LuaValue.neq(LuaValue val)
+
++ Notquals: Perform inequality comparison with another value + including metatag processing using EQ . |
+
+ LuaValue |
+LuaBoolean.not()
+
++ |
+
+ LuaValue |
+LuaNil.not()
+
++ |
+
+ LuaValue |
+LuaValue.not()
+
++ Unary not: return inverse boolean value (~this) as defined by lua not operator |
+
+ LuaValue |
+Varargs.optvalue(int i,
+ LuaValue defval)
+
++ Return argument i as a LuaValue if it exists, or defval . |
+
+ LuaValue |
+LuaNil.optvalue(LuaValue defval)
+
++ |
+
+ LuaValue |
+LuaValue.optvalue(LuaValue defval)
+
++ Perform argument check that this is not nil or none. |
+
+ LuaValue |
+LuaValue.or(LuaValue rhs)
+
++ Perform boolean or with another operand, based on lua rules for boolean evaluation. |
+
+ LuaValue |
+LuaDouble.pow(double rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.pow(double rhs)
+
++ |
+
+ LuaValue |
+LuaString.pow(double rhs)
+
++ |
+
+ LuaValue |
+LuaValue.pow(double rhs)
+
++ Raise to power: Raise this value to a power + of double type with metatag processing |
+
+ LuaValue |
+LuaDouble.pow(int rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.pow(int rhs)
+
++ |
+
+ LuaValue |
+LuaString.pow(int rhs)
+
++ |
+
+ LuaValue |
+LuaValue.pow(int rhs)
+
++ Raise to power: Raise this value to a power + of int type with metatag processing |
+
+ LuaValue |
+LuaDouble.pow(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.pow(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.pow(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.pow(LuaValue rhs)
+
++ Raise to power: Raise this value to a power + including metatag processing. |
+
+ LuaValue |
+LuaDouble.powWith(double lhs)
+
++ |
+
+ LuaValue |
+LuaInteger.powWith(double lhs)
+
++ |
+
+ LuaValue |
+LuaString.powWith(double lhs)
+
++ |
+
+ LuaValue |
+LuaValue.powWith(double lhs)
+
++ Reverse-raise to power: Raise another value of double type to this power + with metatag processing |
+
+ LuaValue |
+LuaDouble.powWith(int lhs)
+
++ |
+
+ LuaValue |
+LuaInteger.powWith(int lhs)
+
++ |
+
+ LuaValue |
+LuaString.powWith(int lhs)
+
++ |
+
+ LuaValue |
+LuaValue.powWith(int lhs)
+
++ Reverse-raise to power: Raise another value of double type to this power + with metatag processing |
+
+ LuaValue |
+LuaTable.rawget(int key)
+
++ |
+
+ LuaValue |
+LuaValue.rawget(int key)
+
++ Get a value in a table without metatag processing. |
+
+ LuaValue |
+WeakTable.rawget(int key)
+
++ |
+
+ LuaValue |
+LuaTable.rawget(LuaValue key)
+
++ |
+
+ LuaValue |
+LuaValue.rawget(LuaValue key)
+
++ Get a value in a table without metatag processing. |
+
+ LuaValue |
+WeakTable.rawget(LuaValue key)
+
++ |
+
+ LuaValue |
+LuaValue.rawget(java.lang.String key)
+
++ Get a value in a table without metatag processing. |
+
+ LuaValue |
+LuaTable.remove(int pos)
+
++ Remove the element at a position in a list-table |
+
+static LuaValue |
+LuaThread.setErrorFunc(LuaValue errfunc)
+
++ Replace the error function of the currently running thread. |
+
+ LuaValue |
+LuaTable.setmetatable(LuaValue metatable)
+
++ |
+
+ LuaValue |
+LuaUserdata.setmetatable(LuaValue metatable)
+
++ |
+
+ LuaValue |
+LuaValue.setmetatable(LuaValue metatable)
+
++ Set the metatable for this LuaValue |
+
+ LuaValue |
+LuaValue.strongkey()
+
++ Return the key part of this value if it is a weak table entry, or NIL if it was weak and is no longer referenced. |
+
+ LuaValue |
+LuaValue.strongvalue()
+
++ Return this value as a strong reference, or NIL if it was weak and is no longer referenced. |
+
+ LuaValue |
+LuaDouble.sub(double rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.sub(double rhs)
+
++ |
+
+ LuaValue |
+LuaString.sub(double rhs)
+
++ |
+
+ LuaValue |
+LuaValue.sub(double rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of double type with metatag processing |
+
+ LuaValue |
+LuaDouble.sub(int rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.sub(int rhs)
+
++ |
+
+ LuaValue |
+LuaString.sub(int rhs)
+
++ |
+
+ LuaValue |
+LuaValue.sub(int rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of int type with metatag processing |
+
+ LuaValue |
+LuaDouble.sub(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.sub(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.sub(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.sub(LuaValue rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+LuaDouble.subFrom(double lhs)
+
++ |
+
+ LuaValue |
+LuaInteger.subFrom(double lhs)
+
++ |
+
+ LuaValue |
+LuaString.subFrom(double lhs)
+
++ |
+
+ LuaValue |
+LuaValue.subFrom(double lhs)
+
++ Reverse-subtract: Perform numeric subtract operation from an int value + with metatag processing |
+
+ LuaValue |
+LuaInteger.subFrom(int lhs)
+
++ |
+
+ LuaValue |
+LuaValue.subFrom(int lhs)
+
++ Reverse-subtract: Perform numeric subtract operation from a double value + without metatag processing |
+
+ LuaValue |
+LuaDouble.tonumber()
+
++ |
+
+ LuaValue |
+LuaNumber.tonumber()
+
++ |
+
+ LuaValue |
+LuaString.tonumber()
+
++ |
+
+ LuaValue |
+LuaValue.tonumber()
+
++ Conditionally convert to lua number without throwing errors. |
+
+ LuaValue |
+LuaString.tonumber(int base)
+
++ convert to a number using a supplied base, or NIL if it can't be converted |
+
+ LuaValue |
+LuaDouble.tostring()
+
++ |
+
+ LuaValue |
+LuaInteger.tostring()
+
++ |
+
+ LuaValue |
+LuaString.tostring()
+
++ |
+
+ LuaValue |
+LuaValue.tostring()
+
++ Conditionally convert to lua string without throwing errors. |
+
+protected LuaValue |
+LuaValue.typerror(java.lang.String expected)
+
++ Throw a LuaError indicating an invalid type was supplied to a function |
+
+protected LuaValue |
+LuaValue.unimplemented(java.lang.String fun)
+
++ Throw a LuaError indicating an operation is not implemented |
+
+ LuaValue |
+Buffer.value()
+
++ Get buffer contents as a LuaValue |
+
+ +
Methods in org.luaj.vm2 with parameters of type LuaValue | +|
---|---|
+ LuaValue |
+LuaDouble.add(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.add(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.add(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.add(LuaValue rhs)
+
++ Add: Perform numeric add operation with another value + including metatag processing. |
+
+ LuaValue |
+LuaValue.and(LuaValue rhs)
+
++ Perform boolean and with another operand, based on lua rules for boolean evaluation. |
+
+ Buffer |
+Buffer.append(LuaValue val)
+
++ Append a LuaValue to the buffer. |
+
+protected LuaValue |
+LuaValue.arithmt(LuaValue tag,
+ LuaValue op2)
+
++ Perform metatag processing for arithmetic operations. |
+
+protected LuaValue |
+LuaValue.arithmtwith(LuaValue tag,
+ double op1)
+
++ Perform metatag processing for arithmetic operations when the left-hand-side is a number. |
+
+ LuaValue |
+LuaClosure.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+LuaValue.call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaClosure.call(LuaValue arg1,
+ LuaValue arg2)
+
++ |
+
+ LuaValue |
+LuaValue.call(LuaValue arg1,
+ LuaValue arg2)
+
++ Call this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaClosure.call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ |
+
+ LuaValue |
+LuaValue.call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ Call this with 3 arguments, including metatag processing,
+ and return only the first return value. |
+
+protected LuaValue |
+LuaValue.checkmetatag(LuaValue tag,
+ java.lang.String reason)
+
++ Get particular metatag, or throw LuaError if it doesn't exist |
+
+protected LuaValue |
+LuaValue.compareerror(LuaValue rhs)
+
++ Throw a LuaError based on a comparison error such as greater-than or less-than,
+ typically due to an invalid operand type |
+
+ LuaValue |
+LuaValue.comparemt(LuaValue tag,
+ LuaValue op1)
+
++ Perform metatag processing for comparison operations. |
+
+ LuaValue |
+LuaNumber.concat(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.concat(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.concat(LuaValue rhs)
+
++ Concatenate another value onto this value and return the result + using rules of lua string concatenation including metatag processing. |
+
+ LuaValue |
+LuaValue.concatmt(LuaValue rhs)
+
++ Perform metatag processing for concatenation operations. |
+
+ Buffer |
+Buffer.concatTo(LuaValue lhs)
+
++ Concatenate this buffer onto a LuaValue |
+
+ LuaValue |
+LuaValue.concatTo(LuaValue lhs)
+
++ Reverse-concatenation: concatenate this value onto another value + whose type is unknwon + and return the result using rules of lua string concatenation including + metatag processing. |
+
+ LuaValue |
+LuaDouble.div(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.div(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.div(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.div(LuaValue rhs)
+
++ Divide: Perform numeric divide operation by another value + of unknown type, + including metatag processing. |
+
+ boolean |
+LuaDouble.eq_b(LuaValue val)
+
++ |
+
+ boolean |
+LuaInteger.eq_b(LuaValue val)
+
++ |
+
+ boolean |
+LuaString.eq_b(LuaValue val)
+
++ |
+
+ boolean |
+LuaTable.eq_b(LuaValue val)
+
++ |
+
+ boolean |
+LuaUserdata.eq_b(LuaValue val)
+
++ |
+
+ boolean |
+LuaValue.eq_b(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ ,
+ and return java boolean |
+
+ LuaValue |
+LuaDouble.eq(LuaValue val)
+
++ |
+
+ LuaValue |
+LuaInteger.eq(LuaValue val)
+
++ |
+
+ LuaValue |
+LuaString.eq(LuaValue val)
+
++ |
+
+ LuaValue |
+LuaTable.eq(LuaValue val)
+
++ |
+
+ LuaValue |
+LuaUserdata.eq(LuaValue val)
+
++ |
+
+ LuaValue |
+LuaValue.eq(LuaValue val)
+
++ Equals: Perform equality comparison with another value + including metatag processing using EQ . |
+
+ boolean |
+LuaUserdata.eqmt(LuaValue val)
+
++ |
+
+static boolean |
+LuaValue.eqmtcall(LuaValue lhs,
+ LuaValue lhsmt,
+ LuaValue rhs,
+ LuaValue rhsmt)
+
++ Perform equality testing metatag processing |
+
+protected Varargs |
+LuaClosure.execute(LuaValue[] stack,
+ Varargs varargs)
+
++ |
+
+ LuaValue |
+LuaTable.foreach(LuaValue func)
+
++ Call the supplied function once for each key-value pair |
+
+ LuaValue |
+LuaTable.foreachi(LuaValue func)
+
++ Call the supplied function once for each key-value pair + in the contiguous array part |
+
+ LuaValue |
+LuaString.get(LuaValue key)
+
++ |
+
+ LuaValue |
+LuaTable.get(LuaValue key)
+
++ |
+
+ LuaValue |
+LuaUserdata.get(LuaValue key)
+
++ |
+
+ LuaValue |
+LuaValue.get(LuaValue key)
+
++ Get a value in a table including metatag processing using INDEX . |
+
+protected static LuaValue |
+LuaValue.gettable(LuaValue t,
+ LuaValue key)
+
++ get value from metatable operations, or NIL if not defined by metatables |
+
+ boolean |
+LuaDouble.gt_b(LuaValue rhs)
+
++ |
+
+ boolean |
+LuaInteger.gt_b(LuaValue rhs)
+
++ |
+
+ boolean |
+LuaString.gt_b(LuaValue rhs)
+
++ |
+
+ boolean |
+LuaValue.gt_b(LuaValue rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+LuaDouble.gt(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.gt(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.gt(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.gt(LuaValue rhs)
+
++ Greater than: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ boolean |
+LuaDouble.gteq_b(LuaValue rhs)
+
++ |
+
+ boolean |
+LuaInteger.gteq_b(LuaValue rhs)
+
++ |
+
+ boolean |
+LuaString.gteq_b(LuaValue rhs)
+
++ |
+
+ boolean |
+LuaValue.gteq_b(LuaValue rhs)
+
++ Greater than or equals: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+LuaDouble.gteq(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.gteq(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.gteq(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.gteq(LuaValue rhs)
+
++ Greater than or equals: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ int |
+LuaTable.hashFindSlot(LuaValue key)
+
++ Find the hashtable slot to use |
+
+ int |
+WeakTable.hashFindSlot(LuaValue key)
+
++ |
+
+protected LuaValue |
+LuaTable.hashget(LuaValue key)
+
++ |
+
+protected LuaValue |
+WeakTable.hashget(LuaValue key)
+
++ Get the hash value for a key + key the key to look up |
+
+ void |
+LuaTable.hashset(LuaValue key,
+ LuaValue value)
+
++ Set a hashtable value |
+
+ Varargs |
+LuaTable.inext(LuaValue key)
+
++ Get the next element after a particular key in the + contiguous array part of a table |
+
+ Varargs |
+LuaValue.inext(LuaValue index)
+
++ Find the next integer-key,value pair if this is a table,
+ return NIL if there are no more, or throw a LuaError if not a table. |
+
+ void |
+LuaTable.insert(int pos,
+ LuaValue value)
+
++ Insert an element at a position in a list-table |
+
+ Varargs |
+LuaValue.invoke(LuaValue[] args)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invoke(LuaValue[] args,
+ Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invoke(LuaValue arg1,
+ LuaValue arg2,
+ Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invoke(LuaValue arg,
+ Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invokemethod(LuaValue name)
+
++ Call named method on this with 0 arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invokemethod(LuaValue name,
+ LuaValue[] args)
+
++ Call named method on this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invokemethod(LuaValue name,
+ LuaValue[] args)
+
++ Call named method on this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invokemethod(LuaValue name,
+ Varargs args)
+
++ Call named method on this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invokemethod(java.lang.String name,
+ LuaValue[] args)
+
++ Call named method on this with 1 argument, including metatag processing,
+ and retain all return values in a Varargs . |
+
+static LuaTable |
+LuaValue.listOf(LuaValue[] unnamedValues)
+
++ Construct a LuaTable initialized with supplied array values. |
+
+static LuaTable |
+LuaValue.listOf(LuaValue[] unnamedValues,
+ Varargs lastarg)
+
++ Construct a LuaTable initialized with supplied array values. |
+
+static LuaFunction |
+LoadState.load(java.io.InputStream stream,
+ java.lang.String name,
+ LuaValue env)
+
++ Load lua in either binary or text form from an input stream. |
+
+ LuaFunction |
+LoadState.LuaCompiler.load(java.io.InputStream stream,
+ java.lang.String filename,
+ LuaValue env)
+
++ Load into a Closure or LuaFunction from a Stream and initializes the environment |
+
+ LuaValue |
+LuaValue.load(LuaValue library)
+
++ Load a library instance by setting its environment to this
+ and calling it, which should iniitalize the library instance and
+ install itself into this instance. |
+
+ boolean |
+LuaDouble.lt_b(LuaValue rhs)
+
++ |
+
+ boolean |
+LuaInteger.lt_b(LuaValue rhs)
+
++ |
+
+ boolean |
+LuaString.lt_b(LuaValue rhs)
+
++ |
+
+ boolean |
+LuaValue.lt_b(LuaValue rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+LuaDouble.lt(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.lt(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.lt(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.lt(LuaValue rhs)
+
++ Less than: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ boolean |
+LuaDouble.lteq_b(LuaValue rhs)
+
++ |
+
+ boolean |
+LuaInteger.lteq_b(LuaValue rhs)
+
++ |
+
+ boolean |
+LuaString.lteq_b(LuaValue rhs)
+
++ |
+
+ boolean |
+LuaValue.lteq_b(LuaValue rhs)
+
++ Less than or equals: Perform numeric or string comparison with another value + of unknown type, including metatag processing, + and returning java boolean. |
+
+ LuaValue |
+LuaDouble.lteq(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.lteq(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.lteq(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.lteq(LuaValue rhs)
+
++ Less than or equals: Perform numeric or string comparison with another value + of unknown type, + including metatag processing, and returning LuaValue . |
+
+ LuaValue |
+LuaValue.metatag(LuaValue tag)
+
++ Get particular metatag, or return NIL if it doesn't exist |
+
+ LuaValue |
+LuaValue.method(LuaValue name)
+
++ Call named method on this with 0 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaValue.method(LuaValue name,
+ LuaValue arg)
+
++ Call named method on this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaValue.method(LuaValue name,
+ LuaValue arg1,
+ LuaValue arg2)
+
++ Call named method on this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaValue.method(java.lang.String name,
+ LuaValue arg)
+
++ Call named method on this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaValue.method(java.lang.String name,
+ LuaValue arg1,
+ LuaValue arg2)
+
++ Call named method on this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+LuaDouble.mod(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.mod(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.mod(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.mod(LuaValue rhs)
+
++ Modulo: Perform numeric modulo operation with another value + of unknown type, + including metatag processing. |
+
+ LuaValue |
+LuaDouble.mul(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.mul(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.mul(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.mul(LuaValue rhs)
+
++ Multiply: Perform numeric multiply operation with another value + of unknown type, + including metatag processing. |
+
+ boolean |
+LuaValue.neq_b(LuaValue val)
+
++ Notquals: Perform inequality comparison with another value + including metatag processing using EQ . |
+
+ LuaValue |
+LuaValue.neq(LuaValue val)
+
++ Notquals: Perform inequality comparison with another value + including metatag processing using EQ . |
+
+ Varargs |
+LuaTable.next(LuaValue key)
+
++ Get the next element after a particular key in the table |
+
+ Varargs |
+LuaValue.next(LuaValue index)
+
++ Find the next key,value pair if this is a table,
+ return NIL if there are no more, or throw a LuaError if not a table. |
+
+ Varargs |
+WeakTable.next(LuaValue key)
+
++ Get the next element after a particular key in the table |
+
+ LuaValue |
+Varargs.optvalue(int i,
+ LuaValue defval)
+
++ Return argument i as a LuaValue if it exists, or defval . |
+
+ LuaValue |
+LuaNil.optvalue(LuaValue defval)
+
++ |
+
+ LuaValue |
+LuaValue.optvalue(LuaValue defval)
+
++ Perform argument check that this is not nil or none. |
+
+ LuaValue |
+LuaValue.or(LuaValue rhs)
+
++ Perform boolean or with another operand, based on lua rules for boolean evaluation. |
+
+ LuaValue |
+LuaDouble.pow(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.pow(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.pow(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.pow(LuaValue rhs)
+
++ Raise to power: Raise this value to a power + including metatag processing. |
+
+static void |
+Print.printState(LuaClosure cl,
+ int pc,
+ LuaValue[] stack,
+ int top,
+ Varargs varargs)
+
++ Print the state of a LuaClosure that is being executed |
+
+ boolean |
+LuaDouble.raweq(LuaValue val)
+
++ |
+
+ boolean |
+LuaInteger.raweq(LuaValue val)
+
++ |
+
+ boolean |
+LuaString.raweq(LuaValue val)
+
++ |
+
+ boolean |
+LuaUserdata.raweq(LuaValue val)
+
++ |
+
+ boolean |
+LuaValue.raweq(LuaValue val)
+
++ Equals: Perform direct equality comparison with another value + without metatag processing. |
+
+ LuaValue |
+LuaTable.rawget(LuaValue key)
+
++ |
+
+ LuaValue |
+LuaValue.rawget(LuaValue key)
+
++ Get a value in a table without metatag processing. |
+
+ LuaValue |
+WeakTable.rawget(LuaValue key)
+
++ |
+
+ void |
+LuaTable.rawset(int key,
+ LuaValue value)
+
++ |
+
+ void |
+LuaValue.rawset(int key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing. |
+
+ void |
+WeakTable.rawset(int key,
+ LuaValue value)
+
++ |
+
+ void |
+LuaTable.rawset(LuaValue key,
+ LuaValue value)
+
++ caller must ensure key is not nil |
+
+ void |
+LuaValue.rawset(LuaValue key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing. |
+
+ void |
+WeakTable.rawset(LuaValue key,
+ LuaValue value)
+
++ |
+
+ void |
+LuaValue.rawset(java.lang.String key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing. |
+
+ void |
+LuaTable.set(int key,
+ LuaValue value)
+
++ |
+
+ void |
+LuaValue.set(int key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing using NEWINDEX . |
+
+ void |
+LuaTable.set(LuaValue key,
+ LuaValue value)
+
++ caller must ensure key is not nil |
+
+ void |
+LuaUserdata.set(LuaValue key,
+ LuaValue value)
+
++ |
+
+ void |
+LuaValue.set(LuaValue key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing using NEWINDEX . |
+
+ void |
+LuaValue.set(java.lang.String key,
+ LuaValue value)
+
++ Set a value in a table without metatag processing using NEWINDEX . |
+
+static LuaValue |
+LuaThread.setErrorFunc(LuaValue errfunc)
+
++ Replace the error function of the currently running thread. |
+
+ void |
+LuaFunction.setfenv(LuaValue env)
+
++ |
+
+ void |
+LuaThread.setfenv(LuaValue env)
+
++ |
+
+ void |
+LuaValue.setfenv(LuaValue env)
+
++ Set the environment on an object. |
+
+static void |
+LuaThread.setGlobals(LuaValue globals)
+
++ Set the globals of the current thread. |
+
+ LuaValue |
+LuaTable.setmetatable(LuaValue metatable)
+
++ |
+
+ LuaValue |
+LuaUserdata.setmetatable(LuaValue metatable)
+
++ |
+
+ LuaValue |
+LuaValue.setmetatable(LuaValue metatable)
+
++ Set the metatable for this LuaValue |
+
+protected static boolean |
+LuaValue.settable(LuaValue t,
+ LuaValue key,
+ LuaValue value)
+
++ Perform field assignment including metatag processing. |
+
+protected void |
+LuaClosure.setUpvalue(int i,
+ LuaValue v)
+
++ |
+
+ Buffer |
+Buffer.setvalue(LuaValue value)
+
++ Set buffer contents as a LuaValue |
+
+ void |
+UpValue.setValue(LuaValue value)
+
++ Set the value of the upvalue |
+
+ void |
+LuaTable.sort(LuaValue comparator)
+
++ Sort the table using a comparator. |
+
+ void |
+WeakTable.sort(LuaValue comparator)
+
++ |
+
+ int |
+LuaString.strcmp(LuaValue lhs)
+
++ |
+
+ int |
+LuaValue.strcmp(LuaValue rhs)
+
++ Perform string comparison with another value + of any type + using string comparison based on byte values. |
+
+ LuaValue |
+LuaDouble.sub(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaInteger.sub(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaString.sub(LuaValue rhs)
+
++ |
+
+ LuaValue |
+LuaValue.sub(LuaValue rhs)
+
++ Subtract: Perform numeric subtract operation with another value + of unknown type, + including metatag processing. |
+
+static LuaTable |
+LuaValue.tableOf(LuaValue[] namedValues)
+
++ Construct a LuaTable initialized with supplied named values. |
+
+static LuaTable |
+LuaValue.tableOf(LuaValue[] namedValues,
+ LuaValue[] unnamedValues)
+
++ Construct a LuaTable initialized with supplied named values and sequential elements. |
+
+static LuaTable |
+LuaValue.tableOf(LuaValue[] namedValues,
+ LuaValue[] unnamedValues)
+
++ Construct a LuaTable initialized with supplied named values and sequential elements. |
+
+static LuaTable |
+LuaValue.tableOf(LuaValue[] namedValues,
+ LuaValue[] unnamedValues,
+ Varargs lastarg)
+
++ Construct a LuaTable initialized with supplied named values and sequential elements in an array part and as varargs. |
+
+static LuaTable |
+LuaValue.tableOf(LuaValue[] namedValues,
+ LuaValue[] unnamedValues,
+ Varargs lastarg)
+
++ Construct a LuaTable initialized with supplied named values and sequential elements in an array part and as varargs. |
+
+static Varargs |
+LuaValue.tailcallOf(LuaValue func,
+ Varargs args)
+
++ Construct a TailcallVarargs around a function and arguments. |
+
+ boolean |
+LuaValue.testfor_b(LuaValue limit,
+ LuaValue step)
+
++ Perform end-condition test in for-loop processing. |
+
+static LuaUserdata |
+LuaValue.userdataOf(java.lang.Object o,
+ LuaValue metatable)
+
++ Construct a LuaUserdata for an object with a user supplied metatable. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue[] v)
+
++ Construct a Varargs around an array of LuaValue s. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue[] v,
+ int offset,
+ int length)
+
++ Construct a Varargs around an array of LuaValue s. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue[] v,
+ int offset,
+ int length,
+ Varargs more)
+
++ Construct a Varargs around an array of LuaValue s. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue[] v,
+ Varargs r)
+
++ Construct a Varargs around an array of LuaValue s. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue v1,
+ LuaValue v2,
+ Varargs v3)
+
++ Construct a Varargs around a set of 3 or more LuaValue s. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue v,
+ Varargs r)
+
++ Construct a Varargs around a set of 2 or more LuaValue s. |
+
+ +
Constructors in org.luaj.vm2 with parameters of type LuaValue | +|
---|---|
Buffer(LuaValue value)
+
++ Create buffer with specified initial value |
+|
LuaClosure(int nupvalues,
+ LuaValue env)
+
++ |
+|
LuaClosure(Prototype p,
+ LuaValue env)
+
++ Supply the initial environment |
+|
LuaFunction(LuaValue env)
+
++ |
+|
LuaTable(LuaValue[] named,
+ LuaValue[] unnamed,
+ Varargs lastarg)
+
++ Construct table with named and unnamed parts. |
+|
LuaTable(LuaValue[] named,
+ LuaValue[] unnamed,
+ Varargs lastarg)
+
++ Construct table with named and unnamed parts. |
+|
LuaThread(LuaValue func,
+ LuaValue env)
+
++ Create a LuaThread around a function and environment |
+|
LuaUserdata(java.lang.Object obj,
+ LuaValue metatable)
+
++ |
+|
TailcallVarargs(LuaValue object,
+ LuaValue methodname,
+ Varargs args)
+
++ |
+|
TailcallVarargs(LuaValue f,
+ Varargs args)
+
++ |
+|
UpValue(LuaValue[] stack,
+ int index)
+
++ Create an upvalue relative to a stack |
+
+Uses of LuaValue in org.luaj.vm2.compiler | +
---|
+ +
Methods in org.luaj.vm2.compiler with parameters of type LuaValue | +|
---|---|
+ LuaFunction |
+LuaC.load(java.io.InputStream stream,
+ java.lang.String name,
+ LuaValue env)
+
++ Load into a Closure or LuaFunction, with the supplied initial environment |
+
+ LuaFunction |
+LuaC.load(Prototype p,
+ java.lang.String filename,
+ LuaValue env)
+
++ |
+
+Uses of LuaValue in org.luaj.vm2.lib | +
---|
+ +
Subclasses of LuaValue in org.luaj.vm2.lib | +|
---|---|
+ class |
+BaseLib
+
++ Subclass of LibFunction which implements the lua basic library functions. |
+
+ class |
+CoroutineLib
+
++ Subclass of LibFunction which implements the lua standard coroutine
+ library. |
+
+ class |
+DebugLib
+
++ Subclass of LibFunction which implements the lua standard debug
+ library. |
+
+ class |
+IoLib
+
++ Abstract base class extending LibFunction which implements the
+ core of the lua standard io library. |
+
+protected class |
+IoLib.File
+
++ |
+
+ class |
+LibFunction
+
++ Subclass of LuaFunction common to Java functions exposed to lua. |
+
+ class |
+MathLib
+
++ Subclass of LibFunction which implements the lua standard math
+ library. |
+
+ class |
+OneArgFunction
+
++ Abstract base class for Java function implementations that take one argument and + return one value. |
+
+ class |
+OsLib
+
++ Subclass of LibFunction which implements the standard lua os library. |
+
+ class |
+PackageLib
+
++ Subclass of LibFunction which implements the lua standard package and module
+ library functions. |
+
+ class |
+StringLib
+
++ Subclass of LibFunction which implements the lua standard string
+ library. |
+
+ class |
+TableLib
+
++ Subclass of LibFunction which implements the lua standard table
+ library. |
+
+ class |
+ThreeArgFunction
+
++ Abstract base class for Java function implementations that take two arguments and + return one value. |
+
+ class |
+TwoArgFunction
+
++ Abstract base class for Java function implementations that take two arguments and + return one value. |
+
+ class |
+VarArgFunction
+
++ Abstract base class for Java function implementations that takes varaiable arguments and + returns multiple return values. |
+
+ class |
+ZeroArgFunction
+
++ Abstract base class for Java function implementations that take no arguments and + return one value. |
+
+ +
Fields in org.luaj.vm2.lib declared as LuaValue | +|
---|---|
+ LuaValue |
+PackageLib.java_loader
+
++ Loader that loads as a Java class. |
+
+ LuaValue |
+PackageLib.lua_loader
+
++ Loader that loads as a lua script using the LUA_PATH |
+
+ LuaValue |
+PackageLib.preload_loader
+
++ Loader that loads from preload table if found there |
+
+ +
Methods in org.luaj.vm2.lib that return LuaValue | +|
---|---|
+ LuaValue |
+OneArgFunction.call()
+
++ |
+
+ LuaValue |
+ThreeArgFunction.call()
+
++ |
+
+ LuaValue |
+TwoArgFunction.call()
+
++ |
+
+ LuaValue |
+VarArgFunction.call()
+
++ |
+
+abstract LuaValue |
+ZeroArgFunction.call()
+
++ |
+
+ LuaValue |
+BaseLib.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+IoLib.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+MathLib.call(LuaValue arg)
+
++ |
+
+abstract LuaValue |
+OneArgFunction.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+PackageLib.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+StringLib.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+TableLib.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+ThreeArgFunction.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+TwoArgFunction.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+VarArgFunction.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+ZeroArgFunction.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+OneArgFunction.call(LuaValue arg1,
+ LuaValue arg2)
+
++ |
+
+ LuaValue |
+ThreeArgFunction.call(LuaValue arg1,
+ LuaValue arg2)
+
++ |
+
+abstract LuaValue |
+TwoArgFunction.call(LuaValue arg1,
+ LuaValue arg2)
+
++ |
+
+ LuaValue |
+VarArgFunction.call(LuaValue arg1,
+ LuaValue arg2)
+
++ |
+
+ LuaValue |
+ZeroArgFunction.call(LuaValue arg1,
+ LuaValue arg2)
+
++ |
+
+ LuaValue |
+OneArgFunction.call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ |
+
+abstract LuaValue |
+ThreeArgFunction.call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ |
+
+ LuaValue |
+TwoArgFunction.call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ |
+
+ LuaValue |
+VarArgFunction.call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ |
+
+ LuaValue |
+ZeroArgFunction.call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ |
+
+static LuaValue |
+MathLib.dpow(double a,
+ double b)
+
++ compute power using installed math library, or default if there is no math library installed |
+
+static LuaValue |
+IoLib.freadall(IoLib.File f)
+
++ |
+
+static LuaValue |
+IoLib.freadbytes(IoLib.File f,
+ int count)
+
++ |
+
+static LuaValue |
+IoLib.freadline(IoLib.File f)
+
++ |
+
+static LuaValue |
+IoLib.freadnumber(IoLib.File f)
+
++ |
+
+static LuaValue |
+IoLib.freaduntil(IoLib.File f,
+ boolean lineonly)
+
++ |
+
+ LuaValue |
+IoLib.File.get(LuaValue key)
+
++ |
+
+ LuaValue |
+OsLib.init()
+
++ |
+
+protected static LuaValue[] |
+LibFunction.newupe()
+
++ Java code generation utility to allocate storage for upvalue, leave it empty |
+
+protected static LuaValue[] |
+LibFunction.newupl(LuaValue v)
+
++ Java code generation utility to allocate storage for upvalue, initialize with value |
+
+protected static LuaValue[] |
+LibFunction.newupn()
+
++ Java code generation utility to allocate storage for upvalue, initialize with nil |
+
+ LuaValue |
+PackageLib.require(LuaValue arg)
+
++ require (modname) + + Loads the given module. |
+
+ +
Methods in org.luaj.vm2.lib with parameters of type LuaValue | +|
---|---|
+ Varargs |
+IoLib._file_close(LuaValue file)
+
++ |
+
+ Varargs |
+IoLib._file_flush(LuaValue file)
+
++ |
+
+ Varargs |
+IoLib._file_lines(LuaValue file)
+
++ |
+
+ Varargs |
+IoLib._file_read(LuaValue file,
+ Varargs subargs)
+
++ |
+
+ Varargs |
+IoLib._file_seek(LuaValue file,
+ java.lang.String whence,
+ int offset)
+
++ |
+
+ Varargs |
+IoLib._file_setvbuf(LuaValue file,
+ java.lang.String mode,
+ int size)
+
++ |
+
+ Varargs |
+IoLib._file_write(LuaValue file,
+ Varargs subargs)
+
++ |
+
+protected static Varargs |
+DebugLib._getinfo(Varargs args,
+ LuaValue level0func)
+
++ |
+
+ Varargs |
+IoLib._io_close(LuaValue file)
+
++ |
+
+ Varargs |
+IoLib._io_index(LuaValue v)
+
++ |
+
+ Varargs |
+IoLib._io_input(LuaValue file)
+
++ |
+
+ Varargs |
+IoLib._io_output(LuaValue filename)
+
++ |
+
+ Varargs |
+IoLib._io_type(LuaValue obj)
+
++ |
+
+ Varargs |
+IoLib._lines_iter(LuaValue file)
+
++ |
+
+protected void |
+LibFunction.bind(LuaValue env,
+ java.lang.Class factory,
+ java.lang.String[] names)
+
++ Bind a set of library functions. |
+
+protected void |
+LibFunction.bind(LuaValue env,
+ java.lang.Class factory,
+ java.lang.String[] names,
+ int firstopcode)
+
++ Bind a set of library functions, with an offset |
+
+ LuaValue |
+BaseLib.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+IoLib.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+MathLib.call(LuaValue arg)
+
++ |
+
+abstract LuaValue |
+OneArgFunction.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+PackageLib.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+StringLib.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+TableLib.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+ThreeArgFunction.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+TwoArgFunction.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+VarArgFunction.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+ZeroArgFunction.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+OneArgFunction.call(LuaValue arg1,
+ LuaValue arg2)
+
++ |
+
+ LuaValue |
+ThreeArgFunction.call(LuaValue arg1,
+ LuaValue arg2)
+
++ |
+
+abstract LuaValue |
+TwoArgFunction.call(LuaValue arg1,
+ LuaValue arg2)
+
++ |
+
+ LuaValue |
+VarArgFunction.call(LuaValue arg1,
+ LuaValue arg2)
+
++ |
+
+ LuaValue |
+ZeroArgFunction.call(LuaValue arg1,
+ LuaValue arg2)
+
++ |
+
+ LuaValue |
+OneArgFunction.call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ |
+
+abstract LuaValue |
+ThreeArgFunction.call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ |
+
+ LuaValue |
+TwoArgFunction.call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ |
+
+ LuaValue |
+VarArgFunction.call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ |
+
+ LuaValue |
+ZeroArgFunction.call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ |
+
+static void |
+DebugLib.debugSetupCall(Varargs args,
+ LuaValue[] stack)
+
++ Called by Closures to set up stack and arguments to next call |
+
+ LuaValue |
+IoLib.File.get(LuaValue key)
+
++ |
+
+protected static LuaValue[] |
+LibFunction.newupl(LuaValue v)
+
++ Java code generation utility to allocate storage for upvalue, initialize with value |
+
+static Varargs |
+BaseLib.pcall(LuaValue func,
+ Varargs args,
+ LuaValue errfunc)
+
++ |
+
+ LuaValue |
+PackageLib.require(LuaValue arg)
+
++ require (modname) + + Loads the given module. |
+
+ +
Constructors in org.luaj.vm2.lib with parameters of type LuaValue | +|
---|---|
OneArgFunction(LuaValue env)
+
++ Constructor with specific environment |
+|
ThreeArgFunction(LuaValue env)
+
++ Constructor with specific environment |
+|
TwoArgFunction(LuaValue env)
+
++ Constructor with specific environment |
+|
VarArgFunction(LuaValue env)
+
++ |
+|
ZeroArgFunction(LuaValue env)
+
++ Constructor with specific environment |
+
+Uses of LuaValue in org.luaj.vm2.lib.jme | +
---|
+ +
Subclasses of LuaValue in org.luaj.vm2.lib.jme | +|
---|---|
+ class |
+JmeIoLib
+
++ Subclass of IoLib and therefore LibFunction which implements the lua standard io
+ library for the JSE platform. |
+
+Uses of LuaValue in org.luaj.vm2.lib.jse | +
---|
+ +
Subclasses of LuaValue in org.luaj.vm2.lib.jse | +|
---|---|
+ class |
+JseBaseLib
+
++ Subclass of BaseLib and LibFunction which implements the lua basic library functions
+ and provides a directory based ResourceFinder as the BaseLib.FINDER . |
+
+ class |
+JseIoLib
+
++ Subclass of IoLib and therefore LibFunction which implements the lua standard io
+ library for the JSE platform. |
+
+ class |
+JseMathLib
+
++ Subclass of LibFunction which implements the lua standard math
+ library. |
+
+static class |
+JseMathLib.JseMathLib1
+
++ |
+
+static class |
+JseMathLib.JseMathLib2
+
++ |
+
+ class |
+JseOsLib
+
++ Subclass of LibFunction which implements the standard lua os library. |
+
+ class |
+LuajavaLib
+
++ Subclass of LibFunction which implements the features of the luajava package. |
+
+ +
Methods in org.luaj.vm2.lib.jse that return LuaValue | +|
---|---|
+ LuaValue |
+JseMathLib.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+JseMathLib.JseMathLib1.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+JseMathLib.JseMathLib2.call(LuaValue arg1,
+ LuaValue arg2)
+
++ |
+
+static LuaValue |
+CoerceJavaToLua.coerce(java.lang.Object o)
+
++ Coerse a Java object to a corresponding lua value. |
+
+ +
Methods in org.luaj.vm2.lib.jse with parameters of type LuaValue | +|
---|---|
+ LuaValue |
+JseMathLib.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+JseMathLib.JseMathLib1.call(LuaValue arg)
+
++ |
+
+ LuaValue |
+JseMathLib.JseMathLib2.call(LuaValue arg1,
+ LuaValue arg2)
+
++ |
+
+static java.lang.Object |
+CoerceLuaToJava.coerce(LuaValue value,
+ java.lang.Class clazz)
+
++ Coerce a LuaValue value to a specified java class |
+
+Uses of LuaValue in org.luaj.vm2.luajc | +
---|
+ +
Methods in org.luaj.vm2.luajc with parameters of type LuaValue | +|
---|---|
+ LuaFunction |
+LuaJC.load(java.io.InputStream stream,
+ java.lang.String name,
+ LuaValue env)
+
++ |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use Prototype | +|
---|---|
org.luaj.vm2 | ++ |
org.luaj.vm2.compiler | ++ |
org.luaj.vm2.lib | ++ |
+Uses of Prototype in org.luaj.vm2 | +
---|
+ +
Fields in org.luaj.vm2 declared as Prototype | +|
---|---|
+ Prototype |
+LuaClosure.p
+
++ |
+
+ Prototype[] |
+Prototype.p
+
++ |
+
+ +
Methods in org.luaj.vm2 that return Prototype | +|
---|---|
+static Prototype |
+LoadState.loadBinaryChunk(int firstByte,
+ java.io.InputStream stream,
+ java.lang.String name)
+
++ Load lua thought to be a binary chunk from its first byte from an input stream. |
+
+ Prototype |
+LoadState.loadFunction(LuaString p)
+
++ Load a function prototype from the input stream |
+
+ +
Methods in org.luaj.vm2 with parameters of type Prototype | +|
---|---|
+static void |
+Print.print(Prototype p)
+
++ |
+
+static void |
+Print.printCode(Prototype f)
+
++ Print the code in a prototype |
+
+static void |
+Print.printFunction(Prototype f,
+ boolean full)
+
++ |
+
+static void |
+Print.printOpCode(java.io.PrintStream ps,
+ Prototype f,
+ int pc)
+
++ Print an opcode in a prototype |
+
+static void |
+Print.printOpCode(Prototype f,
+ int pc)
+
++ Print an opcode in a prototype |
+
+ +
Constructors in org.luaj.vm2 with parameters of type Prototype | +|
---|---|
LuaClosure(Prototype p,
+ LuaValue env)
+
++ Supply the initial environment |
+
+Uses of Prototype in org.luaj.vm2.compiler | +
---|
+ +
Methods in org.luaj.vm2.compiler that return Prototype | +|
---|---|
+static Prototype |
+LuaC.compile(java.io.InputStream stream,
+ java.lang.String name)
+
++ Compile a prototype or load as a binary chunk |
+
+ +
Methods in org.luaj.vm2.compiler with parameters of type Prototype | +|
---|---|
+ LuaFunction |
+LuaC.load(Prototype p,
+ java.lang.String filename,
+ LuaValue env)
+
++ |
+
+Uses of Prototype in org.luaj.vm2.lib | +
---|
+ +
Methods in org.luaj.vm2.lib with parameters of type Prototype | +|
---|---|
+static java.lang.String |
+DebugLib.sourceshort(Prototype p)
+
++ |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use UpValue | +|
---|---|
org.luaj.vm2 | ++ |
+Uses of UpValue in org.luaj.vm2 | +
---|
+ +
Fields in org.luaj.vm2 declared as UpValue | +|
---|---|
+ UpValue[] |
+LuaClosure.upValues
+
++ |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use Varargs | +|
---|---|
org.luaj.vm2 | ++ |
org.luaj.vm2.lib | ++ |
org.luaj.vm2.lib.jme | ++ |
org.luaj.vm2.lib.jse | ++ |
+Uses of Varargs in org.luaj.vm2 | +
---|
+ +
Subclasses of Varargs in org.luaj.vm2 | +|
---|---|
+ class |
+LuaBoolean
+
++ Extension of LuaValue which can hold a Java boolean as its value. |
+
+ class |
+LuaClosure
+
++ Extension of LuaFunction which executes lua bytecode. |
+
+ class |
+LuaDouble
+
++ Extension of LuaNumber which can hold a Java double as its value. |
+
+ class |
+LuaFunction
+
++ Base class for functions implemented in Java. |
+
+ class |
+LuaInteger
+
++ Extension of LuaNumber which can hold a Java int as its value. |
+
+ class |
+LuaNil
+
++ Class to encapsulate behavior of the singleton instance nil |
+
+ class |
+LuaNumber
+
++ Base class for representing numbers as lua values directly. |
+
+ class |
+LuaString
+
++ Subclass of LuaValue for representing lua strings. |
+
+ class |
+LuaTable
+
++ Subclass of LuaValue for representing lua tables. |
+
+ class |
+LuaThread
+
++ Subclass of LuaValue that implements
+ a lua coroutine thread using Java Threads. |
+
+ class |
+LuaUserdata
+
++ |
+
+ class |
+LuaValue
+
++ Base class for all concrete lua type values. |
+
+ class |
+TailcallVarargs
+
++ Subclass of Varargs that represents a lua tail call
+ in a Java library function execution environment. |
+
+ class |
+WeakTable
+
++ Subclass of LuaTable that provides weak key and weak value semantics. |
+
+ +
Methods in org.luaj.vm2 that return Varargs | +|
---|---|
+ Varargs |
+TailcallVarargs.eval()
+
++ |
+
+ Varargs |
+Varargs.eval()
+
++ Evaluate any pending tail call and return result. |
+
+protected Varargs |
+LuaClosure.execute(LuaValue[] stack,
+ Varargs varargs)
+
++ |
+
+ Varargs |
+LuaTable.inext(LuaValue key)
+
++ Get the next element after a particular key in the + contiguous array part of a table |
+
+ Varargs |
+LuaValue.inext(LuaValue index)
+
++ Find the next integer-key,value pair if this is a table,
+ return NIL if there are no more, or throw a LuaError if not a table. |
+
+ Varargs |
+LuaValue.invoke()
+
++ Call this with 0 arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invoke(LuaValue[] args)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invoke(LuaValue[] args,
+ Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invoke(LuaValue arg1,
+ LuaValue arg2,
+ Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invoke(LuaValue arg,
+ Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaClosure.invoke(Varargs varargs)
+
++ |
+
+ Varargs |
+LuaValue.invoke(Varargs args)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invokemethod(LuaValue name)
+
++ Call named method on this with 0 arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invokemethod(LuaValue name,
+ LuaValue[] args)
+
++ Call named method on this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invokemethod(LuaValue name,
+ Varargs args)
+
++ Call named method on this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invokemethod(java.lang.String name)
+
++ Call named method on this with 0 arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invokemethod(java.lang.String name,
+ LuaValue[] args)
+
++ Call named method on this with 1 argument, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invokemethod(java.lang.String name,
+ Varargs args)
+
++ Call named method on this with 1 argument, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaTable.next(LuaValue key)
+
++ Get the next element after a particular key in the table |
+
+ Varargs |
+LuaValue.next(LuaValue index)
+
++ Find the next key,value pair if this is a table,
+ return NIL if there are no more, or throw a LuaError if not a table. |
+
+ Varargs |
+WeakTable.next(LuaValue key)
+
++ Get the next element after a particular key in the table |
+
+ Varargs |
+LuaClosure.onInvoke(Varargs varargs)
+
++ |
+
+ Varargs |
+LuaValue.onInvoke(Varargs args)
+
++ Callback used during tail call processing to invoke the function once. |
+
+ Varargs |
+LuaThread.resume(Varargs args)
+
++ Start or resume this thread |
+
+ Varargs |
+Varargs.subargs(int start)
+
++ Create a Varargs instance containing arguments starting at index start |
+
+static Varargs |
+LuaValue.tailcallOf(LuaValue func,
+ Varargs args)
+
++ Construct a TailcallVarargs around a function and arguments. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue[] v)
+
++ Construct a Varargs around an array of LuaValue s. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue[] v,
+ int offset,
+ int length)
+
++ Construct a Varargs around an array of LuaValue s. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue[] v,
+ int offset,
+ int length,
+ Varargs more)
+
++ Construct a Varargs around an array of LuaValue s. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue[] v,
+ Varargs r)
+
++ Construct a Varargs around an array of LuaValue s. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue v1,
+ LuaValue v2,
+ Varargs v3)
+
++ Construct a Varargs around a set of 3 or more LuaValue s. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue v,
+ Varargs r)
+
++ Construct a Varargs around a set of 2 or more LuaValue s. |
+
+static Varargs |
+LuaThread.yield(Varargs args)
+
++ Yield the current thread with arguments |
+
+ +
Methods in org.luaj.vm2 with parameters of type Varargs | +|
---|---|
+protected Varargs |
+LuaClosure.execute(LuaValue[] stack,
+ Varargs varargs)
+
++ |
+
+ Varargs |
+LuaValue.invoke(LuaValue[] args,
+ Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invoke(LuaValue arg1,
+ LuaValue arg2,
+ Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invoke(LuaValue arg,
+ Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaClosure.invoke(Varargs varargs)
+
++ |
+
+ Varargs |
+LuaValue.invoke(Varargs args)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invokemethod(LuaValue name,
+ Varargs args)
+
++ Call named method on this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
+ Varargs |
+LuaValue.invokemethod(java.lang.String name,
+ Varargs args)
+
++ Call named method on this with 1 argument, including metatag processing,
+ and retain all return values in a Varargs . |
+
+static LuaTable |
+LuaValue.listOf(LuaValue[] unnamedValues,
+ Varargs lastarg)
+
++ Construct a LuaTable initialized with supplied array values. |
+
+ Varargs |
+LuaClosure.onInvoke(Varargs varargs)
+
++ |
+
+ Varargs |
+LuaValue.onInvoke(Varargs args)
+
++ Callback used during tail call processing to invoke the function once. |
+
+static void |
+Print.printState(LuaClosure cl,
+ int pc,
+ LuaValue[] stack,
+ int top,
+ Varargs varargs)
+
++ Print the state of a LuaClosure that is being executed |
+
+ void |
+LuaValue.rawsetlist(int key0,
+ Varargs values)
+
++ Set list values in a table without invoking metatag processing |
+
+ Varargs |
+LuaThread.resume(Varargs args)
+
++ Start or resume this thread |
+
+static LuaTable |
+LuaValue.tableOf(LuaValue[] namedValues,
+ LuaValue[] unnamedValues,
+ Varargs lastarg)
+
++ Construct a LuaTable initialized with supplied named values and sequential elements in an array part and as varargs. |
+
+static LuaTable |
+LuaValue.tableOf(Varargs varargs,
+ int firstarg)
+
++ Construct a LuaTable initialized with supplied array values. |
+
+static Varargs |
+LuaValue.tailcallOf(LuaValue func,
+ Varargs args)
+
++ Construct a TailcallVarargs around a function and arguments. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue[] v,
+ int offset,
+ int length,
+ Varargs more)
+
++ Construct a Varargs around an array of LuaValue s. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue[] v,
+ Varargs r)
+
++ Construct a Varargs around an array of LuaValue s. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue v1,
+ LuaValue v2,
+ Varargs v3)
+
++ Construct a Varargs around a set of 3 or more LuaValue s. |
+
+static Varargs |
+LuaValue.varargsOf(LuaValue v,
+ Varargs r)
+
++ Construct a Varargs around a set of 2 or more LuaValue s. |
+
+static Varargs |
+LuaThread.yield(Varargs args)
+
++ Yield the current thread with arguments |
+
+ +
Constructors in org.luaj.vm2 with parameters of type Varargs | +|
---|---|
LuaTable(LuaValue[] named,
+ LuaValue[] unnamed,
+ Varargs lastarg)
+
++ Construct table with named and unnamed parts. |
+|
LuaTable(Varargs varargs)
+
++ Construct table of unnamed elements. |
+|
LuaTable(Varargs varargs,
+ int firstarg)
+
++ Construct table of unnamed elements. |
+|
TailcallVarargs(LuaValue object,
+ LuaValue methodname,
+ Varargs args)
+
++ |
+|
TailcallVarargs(LuaValue f,
+ Varargs args)
+
++ |
+
+Uses of Varargs in org.luaj.vm2.lib | +
---|
+ +
Subclasses of Varargs in org.luaj.vm2.lib | +|
---|---|
+ class |
+BaseLib
+
++ Subclass of LibFunction which implements the lua basic library functions. |
+
+ class |
+CoroutineLib
+
++ Subclass of LibFunction which implements the lua standard coroutine
+ library. |
+
+ class |
+DebugLib
+
++ Subclass of LibFunction which implements the lua standard debug
+ library. |
+
+ class |
+IoLib
+
++ Abstract base class extending LibFunction which implements the
+ core of the lua standard io library. |
+
+protected class |
+IoLib.File
+
++ |
+
+ class |
+LibFunction
+
++ Subclass of LuaFunction common to Java functions exposed to lua. |
+
+ class |
+MathLib
+
++ Subclass of LibFunction which implements the lua standard math
+ library. |
+
+ class |
+OneArgFunction
+
++ Abstract base class for Java function implementations that take one argument and + return one value. |
+
+ class |
+OsLib
+
++ Subclass of LibFunction which implements the standard lua os library. |
+
+ class |
+PackageLib
+
++ Subclass of LibFunction which implements the lua standard package and module
+ library functions. |
+
+ class |
+StringLib
+
++ Subclass of LibFunction which implements the lua standard string
+ library. |
+
+ class |
+TableLib
+
++ Subclass of LibFunction which implements the lua standard table
+ library. |
+
+ class |
+ThreeArgFunction
+
++ Abstract base class for Java function implementations that take two arguments and + return one value. |
+
+ class |
+TwoArgFunction
+
++ Abstract base class for Java function implementations that take two arguments and + return one value. |
+
+ class |
+VarArgFunction
+
++ Abstract base class for Java function implementations that takes varaiable arguments and + returns multiple return values. |
+
+ class |
+ZeroArgFunction
+
++ Abstract base class for Java function implementations that take no arguments and + return one value. |
+
+ +
Methods in org.luaj.vm2.lib that return Varargs | +|
---|---|
+ Varargs |
+IoLib._file_close(LuaValue file)
+
++ |
+
+ Varargs |
+IoLib._file_flush(LuaValue file)
+
++ |
+
+ Varargs |
+IoLib._file_lines(LuaValue file)
+
++ |
+
+ Varargs |
+IoLib._file_read(LuaValue file,
+ Varargs subargs)
+
++ |
+
+ Varargs |
+IoLib._file_seek(LuaValue file,
+ java.lang.String whence,
+ int offset)
+
++ |
+
+ Varargs |
+IoLib._file_setvbuf(LuaValue file,
+ java.lang.String mode,
+ int size)
+
++ |
+
+ Varargs |
+IoLib._file_write(LuaValue file,
+ Varargs subargs)
+
++ |
+
+protected static Varargs |
+DebugLib._getinfo(Varargs args,
+ LuaValue level0func)
+
++ |
+
+ Varargs |
+IoLib._io_close(LuaValue file)
+
++ |
+
+ Varargs |
+IoLib._io_flush()
+
++ |
+
+ Varargs |
+IoLib._io_index(LuaValue v)
+
++ |
+
+ Varargs |
+IoLib._io_input(LuaValue file)
+
++ |
+
+ Varargs |
+IoLib._io_lines(java.lang.String filename)
+
++ |
+
+ Varargs |
+IoLib._io_open(java.lang.String filename,
+ java.lang.String mode)
+
++ |
+
+ Varargs |
+IoLib._io_output(LuaValue filename)
+
++ |
+
+ Varargs |
+IoLib._io_popen(java.lang.String prog,
+ java.lang.String mode)
+
++ |
+
+ Varargs |
+IoLib._io_read(Varargs args)
+
++ |
+
+ Varargs |
+IoLib._io_tmpfile()
+
++ |
+
+ Varargs |
+IoLib._io_type(LuaValue obj)
+
++ |
+
+ Varargs |
+IoLib._io_write(Varargs args)
+
++ |
+
+ Varargs |
+IoLib._lines_iter(LuaValue file)
+
++ |
+
+static Varargs |
+StringLib.char_(Varargs args)
+
++ string.char (...) + + Receives zero or more integers. |
+
+ Varargs |
+CoroutineLib.invoke(Varargs args)
+
++ |
+
+ Varargs |
+DebugLib.invoke(Varargs args)
+
++ |
+
+ Varargs |
+OneArgFunction.invoke(Varargs varargs)
+
++ |
+
+ Varargs |
+OsLib.invoke(Varargs args)
+
++ |
+
+ Varargs |
+ThreeArgFunction.invoke(Varargs varargs)
+
++ |
+
+ Varargs |
+TwoArgFunction.invoke(Varargs varargs)
+
++ |
+
+ Varargs |
+VarArgFunction.invoke(Varargs args)
+
++ Override and implement for the best performance. |
+
+ Varargs |
+ZeroArgFunction.invoke(Varargs varargs)
+
++ |
+
+static Varargs |
+BaseLib.loadFile(java.lang.String filename)
+
++ Load from a named file, returning the chunk or nil,error of can't load |
+
+static Varargs |
+PackageLib.loadlib(Varargs args)
+
++ |
+
+static Varargs |
+BaseLib.loadStream(java.io.InputStream is,
+ java.lang.String chunkname)
+
++ |
+
+ Varargs |
+PackageLib.module(Varargs args)
+
++ module (name [, ...]) + + Creates a module. |
+
+ Varargs |
+VarArgFunction.onInvoke(Varargs args)
+
++ Override to provide a call implementation that runs in an environment + that can participate in setfenv, and behaves as expected + when returning TailcallVarargs. |
+
+static Varargs |
+BaseLib.pcall(LuaValue func,
+ Varargs args,
+ LuaValue errfunc)
+
++ |
+
+ +
Methods in org.luaj.vm2.lib with parameters of type Varargs | +|
---|---|
+ Varargs |
+IoLib._file_read(LuaValue file,
+ Varargs subargs)
+
++ |
+
+ Varargs |
+IoLib._file_write(LuaValue file,
+ Varargs subargs)
+
++ |
+
+protected static Varargs |
+DebugLib._getinfo(Varargs args,
+ LuaValue level0func)
+
++ |
+
+ Varargs |
+IoLib._io_read(Varargs args)
+
++ |
+
+ Varargs |
+IoLib._io_write(Varargs args)
+
++ |
+
+static Varargs |
+StringLib.char_(Varargs args)
+
++ string.char (...) + + Receives zero or more integers. |
+
+static void |
+DebugLib.debugBytecode(int pc,
+ Varargs extras,
+ int top)
+
++ Called by Closures on bytecode execution |
+
+static void |
+DebugLib.debugSetupCall(Varargs args,
+ LuaValue[] stack)
+
++ Called by Closures to set up stack and arguments to next call |
+
+ Varargs |
+CoroutineLib.invoke(Varargs args)
+
++ |
+
+ Varargs |
+DebugLib.invoke(Varargs args)
+
++ |
+
+ Varargs |
+OneArgFunction.invoke(Varargs varargs)
+
++ |
+
+ Varargs |
+OsLib.invoke(Varargs args)
+
++ |
+
+ Varargs |
+ThreeArgFunction.invoke(Varargs varargs)
+
++ |
+
+ Varargs |
+TwoArgFunction.invoke(Varargs varargs)
+
++ |
+
+ Varargs |
+VarArgFunction.invoke(Varargs args)
+
++ Override and implement for the best performance. |
+
+ Varargs |
+ZeroArgFunction.invoke(Varargs varargs)
+
++ |
+
+static Varargs |
+PackageLib.loadlib(Varargs args)
+
++ |
+
+ Varargs |
+PackageLib.module(Varargs args)
+
++ module (name [, ...]) + + Creates a module. |
+
+ Varargs |
+VarArgFunction.onInvoke(Varargs args)
+
++ Override to provide a call implementation that runs in an environment + that can participate in setfenv, and behaves as expected + when returning TailcallVarargs. |
+
+static Varargs |
+BaseLib.pcall(LuaValue func,
+ Varargs args,
+ LuaValue errfunc)
+
++ |
+
+Uses of Varargs in org.luaj.vm2.lib.jme | +
---|
+ +
Subclasses of Varargs in org.luaj.vm2.lib.jme | +|
---|---|
+ class |
+JmeIoLib
+
++ Subclass of IoLib and therefore LibFunction which implements the lua standard io
+ library for the JSE platform. |
+
+Uses of Varargs in org.luaj.vm2.lib.jse | +
---|
+ +
Subclasses of Varargs in org.luaj.vm2.lib.jse | +|
---|---|
+ class |
+JseBaseLib
+
++ Subclass of BaseLib and LibFunction which implements the lua basic library functions
+ and provides a directory based ResourceFinder as the BaseLib.FINDER . |
+
+ class |
+JseIoLib
+
++ Subclass of IoLib and therefore LibFunction which implements the lua standard io
+ library for the JSE platform. |
+
+ class |
+JseMathLib
+
++ Subclass of LibFunction which implements the lua standard math
+ library. |
+
+static class |
+JseMathLib.JseMathLib1
+
++ |
+
+static class |
+JseMathLib.JseMathLib2
+
++ |
+
+ class |
+JseOsLib
+
++ Subclass of LibFunction which implements the standard lua os library. |
+
+ class |
+LuajavaLib
+
++ Subclass of LibFunction which implements the features of the luajava package. |
+
+ +
Methods in org.luaj.vm2.lib.jse that return Varargs | +|
---|---|
+ Varargs |
+LuajavaLib.invoke(Varargs args)
+
++ |
+
+ +
Methods in org.luaj.vm2.lib.jse with parameters of type Varargs | +|
---|---|
+ Varargs |
+LuajavaLib.invoke(Varargs args)
+
++ |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Lua + org.luaj.vm2.compiler.LuaC ++
public class LuaC
+Compiler for Lua. +
+ Compiles lua source files into lua bytecode within a Prototype
,
+ loads lua binary files directly into aPrototype
,
+ and optionaly instantiates a LuaClosure
around the result
+ using a user-supplied environment.
+
+ Implements the LoadState.LuaCompiler
interface for loading
+ initialized chunks, which is an interface common to
+ lua bytecode compiling and java bytecode compiling.
+
+ Teh LuaC
compiler is installed by default by both the
+ JsePlatform
and JmePlatform
classes,
+ so in the following example, the default LuaC
compiler
+ will be used:
+
LuaValue _G = JsePlatform.standardGlobals();
+ LoadState.load( new ByteArrayInputStream("print 'hello'".getBytes()), "main.lua", _G ).call();
+
++ +
+
LoadState.LuaCompiler
,
+LuaJC
,
+JsePlatform
,
+JmePlatform
,
+BaseLib
,
+LuaValue
,
+LoadState.LuaCompiler
,
+Prototype
+Field Summary | +|
---|---|
+static LuaC |
+instance
+
++ |
+
+static int |
+MAXSTACK
+
++ |
+
+ int |
+nCcalls
+
++ |
+
Fields inherited from class org.luaj.vm2.Lua | +
---|
_VERSION, BITRK, LFIELDS_PER_FLUSH, LUA_MULTRET, luaP_opmodes, MASK_A, MASK_B, MASK_Bx, MASK_C, MASK_NOT_A, MASK_NOT_B, MASK_NOT_Bx, MASK_NOT_C, MASK_NOT_OP, MASK_OP, MAX_OP, MAXARG_A, MAXARG_B, MAXARG_Bx, MAXARG_C, MAXARG_sBx, MAXINDEXRK, NUM_OPCODES, OP_ADD, OP_AND, OP_CALL, OP_CLOSE, OP_CLOSURE, OP_CONCAT, OP_DIV, OP_EQ, OP_FORLOOP, OP_FORPREP, OP_GE, OP_GETGLOBAL, OP_GETTABLE, OP_GETUPVAL, OP_GT, OP_JMP, OP_LE, OP_LEN, OP_LOADBOOL, OP_LOADK, OP_LOADNIL, OP_LT, OP_MOD, OP_MOVE, OP_MUL, OP_NEQ, OP_NEWTABLE, OP_NOT, OP_OR, OP_POW, OP_RETURN, OP_SELF, OP_SETGLOBAL, OP_SETLIST, OP_SETTABLE, OP_SETUPVAL, OP_SUB, OP_TAILCALL, OP_TEST, OP_TESTSET, OP_TFORLOOP, OP_UNM, OP_VARARG, POS_A, POS_B, POS_Bx, POS_C, POS_OP, SIZE_A, SIZE_B, SIZE_Bx, SIZE_C, SIZE_OP, VARARG_HASARG, VARARG_ISVARARG, VARARG_NEEDSARG |
+
+Constructor Summary | +|
---|---|
+protected |
+LuaC()
+
++ |
+
+Method Summary | +|
---|---|
+protected static void |
+_assert(boolean b)
+
++ |
+
+static Prototype |
+compile(java.io.InputStream stream,
+ java.lang.String name)
+
++ Compile a prototype or load as a binary chunk |
+
+static void |
+install()
+
++ Install the compiler so that LoadState will first + try to use it when handed bytes that are + not already a compiled lua chunk. |
+
+ LuaFunction |
+load(java.io.InputStream stream,
+ java.lang.String name,
+ LuaValue env)
+
++ Load into a Closure or LuaFunction, with the supplied initial environment |
+
+ LuaFunction |
+load(Prototype p,
+ java.lang.String filename,
+ LuaValue env)
+
++ |
+
+ LuaString |
+newTString(byte[] bytes,
+ int offset,
+ int len)
+
++ |
+
+ java.lang.String |
+pushfstring(java.lang.String string)
+
++ |
+
Methods inherited from class org.luaj.vm2.Lua | +
---|
GET_OPCODE, GETARG_A, GETARG_B, GETARG_Bx, GETARG_C, GETARG_sBx, getBMode, getCMode, getOpMode, INDEXK, ISK, RKASK, testAMode, testTMode |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Field Detail | +
---|
+public static final LuaC instance+
+public static final int MAXSTACK+
+public int nCcalls+
+Constructor Detail | +
---|
+protected LuaC()+
+Method Detail | +
---|
+public static void install()+
+
+protected static void _assert(boolean b)+
+public LuaFunction load(java.io.InputStream stream, + java.lang.String name, + LuaValue env) + throws java.io.IOException+
+
load
in interface LoadState.LuaCompiler
java.io.IOException
+public static Prototype compile(java.io.InputStream stream, + java.lang.String name) + throws java.io.IOException+
+
java.io.IOException
+public LuaString newTString(byte[] bytes, + int offset, + int len)+
+public java.lang.String pushfstring(java.lang.String string)+
+public LuaFunction load(Prototype p, + java.lang.String filename, + LuaValue env)+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LuaC | +|
---|---|
org.luaj.vm2.compiler | ++ |
+Uses of LuaC in org.luaj.vm2.compiler | +
---|
+ +
Fields in org.luaj.vm2.compiler declared as LuaC | +|
---|---|
+static LuaC |
+LuaC.instance
+
++ |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Classes
+
+ +LuaC |
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+Class Summary | +|
---|---|
LuaC | +Compiler for Lua. | +
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use org.luaj.vm2.compiler | +|
---|---|
org.luaj.vm2.compiler | ++ |
+Classes in org.luaj.vm2.compiler used by org.luaj.vm2.compiler | +|
---|---|
LuaC
+
+ + Compiler for Lua. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.OneArgFunction + org.luaj.vm2.lib.BaseLib ++
public class BaseLib
+Subclass of LibFunction
which implements the lua basic library functions.
+
+ This contains all library functions listed as "basic functions" in the lua documentation for JME.
+ The functions dofile and loadfile use the
+ FINDER
instance to find resource files.
+ Since JME has no file system by default, BaseLib
implements
+ ResourceFinder
using Class.getResource(String)
,
+ which is the closest equivalent on JME.
+ The default loader chain in PackageLib
will use these as well.
+
+ To use basic library functions that include a ResourceFinder
based on
+ directory lookup, use JseBaseLib
instead.
+
+ Typically, this library is included as part of a call to either
+ JmePlatform#standardGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ LuaThread.setGlobals(_G);
+ _G.load(new BaseLib());
+ _G.get("print").call(LuaValue.valueOf("hello, world"));
+
+ Doing so will ensure the library is properly initialized
+ and loaded into the globals table.
+ + This is a direct port of the corresponding library in C. +
+ +
+
JseBaseLib
,
+ResourceFinder
,
+FINDER
,
+LibFunction
,
+JsePlatform
,
+JmePlatform
,
+http://www.lua.org/manual/5.1/manual.html#5.1+Field Summary | +|
---|---|
+static ResourceFinder |
+FINDER
+
++ Singleton file opener for this Java ClassLoader realm. |
+
+static BaseLib |
+instance
+
++ |
+
+ java.io.PrintStream |
+STDERR
+
++ |
+
+ java.io.InputStream |
+STDIN
+
++ |
+
+ java.io.PrintStream |
+STDOUT
+
++ |
+
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
BaseLib()
+
++ Construct a base libarary instance. |
+
+Method Summary | +|
---|---|
+ LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ java.io.InputStream |
+findResource(java.lang.String filename)
+
++ ResourceFinder implementation + + Tries to open the file as a resource, which can work for . |
+
+static Varargs |
+loadFile(java.lang.String filename)
+
++ Load from a named file, returning the chunk or nil,error of can't load |
+
+static Varargs |
+loadStream(java.io.InputStream is,
+ java.lang.String chunkname)
+
++ |
+
+static Varargs |
+pcall(LuaValue func,
+ Varargs args,
+ LuaValue errfunc)
+
++ |
+
Methods inherited from class org.luaj.vm2.lib.OneArgFunction | +
---|
call, call, call, invoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static BaseLib instance+
+public java.io.InputStream STDIN+
+public java.io.PrintStream STDOUT+
+public java.io.PrintStream STDERR+
+public static ResourceFinder FINDER+
+
+Constructor Detail | +
---|
+public BaseLib()+
+
+Method Detail | +
---|
+public LuaValue call(LuaValue arg)+
LuaValue
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class OneArgFunction
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+LuaValue.method(String,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue)
+public java.io.InputStream findResource(java.lang.String filename)+
+
findResource
in interface ResourceFinder
BaseLib
,
+JseBaseLib
+public static Varargs pcall(LuaValue func, + Varargs args, + LuaValue errfunc)+
+public static Varargs loadFile(java.lang.String filename)+
+
+public static Varargs loadStream(java.io.InputStream is, + java.lang.String chunkname)+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.VarArgFunction + org.luaj.vm2.lib.CoroutineLib ++
public class CoroutineLib
+Subclass of LibFunction
which implements the lua standard coroutine
+ library.
+
+ The coroutine library in luaj has the same behavior as the + coroutine library in C, but is implemented using Java Threads to maintain + the call state between invocations. Therefore it can be yielded from anywhere, + similar to the "Coco" yield-from-anywhere patch available for C-based lua. + However, coroutines that are yielded but never resumed to complete their execution + may not be collected by the garbage collector. +
+ Typically, this library is included as part of a call to either
+ JsePlatform#standardGlobals()
or JmePlatform#standardGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ _G.load(new CoroutineLib());
+
+ Doing so will ensure the library is properly initialized
+ and loaded into the globals table.
+ +
+ +
+
LibFunction
,
+JsePlatform
,
+JmePlatform
,
+http://www.lua.org/manual/5.1/manual.html#5.2+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
CoroutineLib()
+
++ |
+
+Method Summary | +|
---|---|
+ Varargs |
+invoke(Varargs args)
+
++ Override and implement for the best performance. |
+
Methods inherited from class org.luaj.vm2.lib.VarArgFunction | +
---|
call, call, call, call, onInvoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public CoroutineLib()+
+Method Detail | +
---|
+public Varargs invoke(Varargs args)+
VarArgFunction
+
invoke
in class VarArgFunction
args
- the arguments to the function call.
+Varargs
instance.LuaValue.varargsOf(LuaValue[])
,
+LuaValue.call(LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.invoke(LuaValue,Varargs)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.VarArgFunction + org.luaj.vm2.lib.DebugLib ++
public class DebugLib
+Subclass of LibFunction
which implements the lua standard debug
+ library.
+
+ The debug library in luaj tries to emulate the behavior of the corresponding C-based lua library.
+ To do this, it must maintain a separate stack of calls to LuaClosure
and LibFunction
+ instances.
+ Especially when lua-to-java bytecode compiling is being used
+ via a LuaCompiler
such as LuaJC
,
+ this cannot be done in all cases.
+
+ Typically, this library is included as part of a call to either
+ JsePlatform#debugGlobals()
or JmePlatform#debugGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ _G.load(new DebugLib());
+
+ Doing so will ensure the library is properly initialized
+ and loaded into the globals table.
+ +
+ +
+
LibFunction
,
+JsePlatform
,
+JmePlatform
,
+http://www.lua.org/manual/5.1/manual.html#5.9+Field Summary | +|
---|---|
+static boolean |
+CALLS
+
++ |
+
+static boolean |
+DEBUG_ENABLED
+
++ |
+
+static boolean |
+TRACE
+
++ |
+
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
DebugLib()
+
++ |
+
+Method Summary | +|
---|---|
+protected static Varargs |
+_getinfo(Varargs args,
+ LuaValue level0func)
+
++ |
+
+static void |
+debugBytecode(int pc,
+ Varargs extras,
+ int top)
+
++ Called by Closures on bytecode execution |
+
+static void |
+debugOnCall(LuaThread thread,
+ int calls,
+ LuaFunction func)
+
++ Called by Closures and recursing java functions on entry |
+
+static void |
+debugOnReturn(LuaThread thread,
+ int calls)
+
++ Called by Closures and recursing java functions on return |
+
+static void |
+debugSetupCall(Varargs args,
+ LuaValue[] stack)
+
++ Called by Closures to set up stack and arguments to next call |
+
+static java.lang.String |
+fileline()
+
++ Get file and line for the nearest calling closure. |
+
+static java.lang.String |
+fileline(int level)
+
++ Get file and line for a particular level, even if it is a java function. |
+
+ Varargs |
+invoke(Varargs args)
+
++ Override and implement for the best performance. |
+
+static java.lang.String |
+sourceshort(Prototype p)
+
++ |
+
+static java.lang.String |
+traceback(int level)
+
++ Get a traceback as a string for the current thread |
+
+static java.lang.String |
+traceback(LuaThread thread,
+ int level)
+
++ Get a traceback for a particular thread. |
+
Methods inherited from class org.luaj.vm2.lib.VarArgFunction | +
---|
call, call, call, call, onInvoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static final boolean CALLS+
+public static final boolean TRACE+
+public static boolean DEBUG_ENABLED+
+Constructor Detail | +
---|
+public DebugLib()+
+Method Detail | +
---|
+public Varargs invoke(Varargs args)+
VarArgFunction
+
invoke
in class VarArgFunction
args
- the arguments to the function call.
+Varargs
instance.LuaValue.varargsOf(LuaValue[])
,
+LuaValue.call(LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.invoke(LuaValue,Varargs)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+public static void debugSetupCall(Varargs args, + LuaValue[] stack)+
+
+public static void debugOnCall(LuaThread thread, + int calls, + LuaFunction func)+
+
thread
- the thread for the callcalls
- the number of calls in the call stackfunc
- the function called+public static void debugOnReturn(LuaThread thread, + int calls)+
+
thread
- the thread for the callcalls
- the number of calls in the call stack+public static void debugBytecode(int pc, + Varargs extras, + int top)+
+
+protected static Varargs _getinfo(Varargs args, + LuaValue level0func)+
+public static java.lang.String sourceshort(Prototype p)+
+public static java.lang.String traceback(int level)+
+
+public static java.lang.String traceback(LuaThread thread, + int level)+
+
thread
- LuaThread to provide stack trace forlevel
- 0-based level to start reporting on
++public static java.lang.String fileline()+
+
+public static java.lang.String fileline(int level)+
+
level
- 0-based index of level to get
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.lib.IoLib.File ++
protected abstract class IoLib.File
+
+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
+protected |
+IoLib.File()
+
++ |
+
+Method Summary | +|
---|---|
+abstract void |
+close()
+
++ |
+
+abstract void |
+flush()
+
++ |
+
+ LuaValue |
+get(LuaValue key)
+
++ Get a value in a table including metatag processing using INDEX . |
+
+abstract boolean |
+isclosed()
+
++ |
+
+abstract boolean |
+isstdfile()
+
++ |
+
+abstract int |
+peek()
+
++ |
+
+abstract int |
+read()
+
++ |
+
+abstract int |
+read(byte[] bytes,
+ int offset,
+ int length)
+
++ |
+
+abstract int |
+remaining()
+
++ |
+
+abstract int |
+seek(java.lang.String option,
+ int bytecount)
+
++ |
+
+abstract void |
+setvbuf(java.lang.String mode,
+ int size)
+
++ |
+
+ java.lang.String |
+tojstring()
+
++ Convert to human readable String for any type. |
+
+ int |
+type()
+
++ Get the enumeration value for the type of this value. |
+
+ java.lang.String |
+typename()
+
++ Get the String name of the type of this value. |
+
+abstract void |
+write(LuaString string)
+
++ |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+protected IoLib.File()+
+Method Detail | +
---|
+public abstract void write(LuaString string) + throws java.io.IOException+
java.io.IOException
+public abstract void flush() + throws java.io.IOException+
java.io.IOException
+public abstract boolean isstdfile()+
+public abstract void close() + throws java.io.IOException+
java.io.IOException
+public abstract boolean isclosed()+
+public abstract int seek(java.lang.String option, + int bytecount) + throws java.io.IOException+
java.io.IOException
+public abstract void setvbuf(java.lang.String mode, + int size)+
+public abstract int remaining() + throws java.io.IOException+
java.io.IOException
+public abstract int peek() + throws java.io.IOException, + java.io.EOFException+
java.io.IOException
+java.io.EOFException
+public abstract int read() + throws java.io.IOException, + java.io.EOFException+
java.io.IOException
+java.io.EOFException
+public abstract int read(byte[] bytes, + int offset, + int length) + throws java.io.IOException+
java.io.IOException
+public LuaValue get(LuaValue key)+
LuaValue
INDEX
.
++
get
in class LuaValue
key
- the key to look up, must not be NIL
or null
+LuaValue
for that key, or NIL
if not found and no metatagLuaValue.get(int)
,
+LuaValue.get(String)
,
+LuaValue.rawget(LuaValue)
+public int type()+
LuaValue
+
type
in class LuaValue
TNIL
,
+ TBOOLEAN
,
+ TNUMBER
,
+ TSTRING
,
+ TTABLE
,
+ TFUNCTION
,
+ TUSERDATA
,
+ TTHREAD
LuaValue.typename()
+public java.lang.String typename()+
LuaValue
+
+
typename
in class LuaValue
LuaValue.TYPE_NAMES
+ corresponding to the type of this value:
+ "nil", "boolean", "number", "string",
+ "table", "function", "userdata", "thread"LuaValue.type()
+public java.lang.String tojstring()+
LuaValue
+
tojstring
in class LuaValue
LuaValue.tostring()
,
+LuaValue.optjstring(String)
,
+LuaValue.checkjstring()
,
+LuaValue.isstring()
,
+TSTRING
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.OneArgFunction + org.luaj.vm2.lib.IoLib ++
public abstract class IoLib
+Abstract base class extending LibFunction
which implements the
+ core of the lua standard io
library.
+
+ It contains the implementation of the io library support that is common to
+ the JSE and JME platforms.
+ In practice on of the concrete IOLib subclasses is chosen:
+ JseIoLib
for the JSE platform, and
+ JmeIoLib
for the JME platform.
+
+ The JSE implementation conforms almost completely to the C-based lua library, + while the JME implementation follows closely except in the area of random-access files, + which are difficult to support properly on JME. +
+ Typically, this library is included as part of a call to either
+ JsePlatform#standardGlobals()
or JmePlatform#standardGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ _G.load(new JseIoLib());
+ LuaThread.setGlobals(_G);
+ _G.load(new JseBaseLib());
+ _G.load(new PackageLib());
+ _G.load(new JseIoLib());
+ _G.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
+
+ Doing so will ensure the library is properly initialized
+ and loaded into the globals table.
+ + This has been implemented to match as closely as possible the behavior in the corresponding library in C. +
+ +
+
LibFunction
,
+JsePlatform
,
+JmePlatform
,
+JseIoLib
,
+JmeIoLib
,
+http://www.lua.org/manual/5.1/manual.html#5.7+Nested Class Summary | +|
---|---|
+protected class |
+IoLib.File
+
++ |
+
+Field Summary | +|
---|---|
+static java.lang.String[] |
+FILE_NAMES
+
++ |
+
+static java.lang.String[] |
+IO_NAMES
+
++ |
+
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
IoLib()
+
++ |
+
+Method Summary | +|
---|---|
+ Varargs |
+_file_close(LuaValue file)
+
++ |
+
+ Varargs |
+_file_flush(LuaValue file)
+
++ |
+
+ Varargs |
+_file_lines(LuaValue file)
+
++ |
+
+ Varargs |
+_file_read(LuaValue file,
+ Varargs subargs)
+
++ |
+
+ Varargs |
+_file_seek(LuaValue file,
+ java.lang.String whence,
+ int offset)
+
++ |
+
+ Varargs |
+_file_setvbuf(LuaValue file,
+ java.lang.String mode,
+ int size)
+
++ |
+
+ Varargs |
+_file_write(LuaValue file,
+ Varargs subargs)
+
++ |
+
+ Varargs |
+_io_close(LuaValue file)
+
++ |
+
+ Varargs |
+_io_flush()
+
++ |
+
+ Varargs |
+_io_index(LuaValue v)
+
++ |
+
+ Varargs |
+_io_input(LuaValue file)
+
++ |
+
+ Varargs |
+_io_lines(java.lang.String filename)
+
++ |
+
+ Varargs |
+_io_open(java.lang.String filename,
+ java.lang.String mode)
+
++ |
+
+ Varargs |
+_io_output(LuaValue filename)
+
++ |
+
+ Varargs |
+_io_popen(java.lang.String prog,
+ java.lang.String mode)
+
++ |
+
+ Varargs |
+_io_read(Varargs args)
+
++ |
+
+ Varargs |
+_io_tmpfile()
+
++ |
+
+ Varargs |
+_io_type(LuaValue obj)
+
++ |
+
+ Varargs |
+_io_write(Varargs args)
+
++ |
+
+ Varargs |
+_lines_iter(LuaValue file)
+
++ |
+
+ LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+static LuaValue |
+freadall(IoLib.File f)
+
++ |
+
+static LuaValue |
+freadbytes(IoLib.File f,
+ int count)
+
++ |
+
+static LuaValue |
+freadline(IoLib.File f)
+
++ |
+
+static LuaValue |
+freadnumber(IoLib.File f)
+
++ |
+
+static LuaValue |
+freaduntil(IoLib.File f,
+ boolean lineonly)
+
++ |
+
+protected abstract IoLib.File |
+openFile(java.lang.String filename,
+ boolean readMode,
+ boolean appendMode,
+ boolean updateMode,
+ boolean binaryMode)
+
++ Open a file in a particular mode. |
+
+protected abstract IoLib.File |
+openProgram(java.lang.String prog,
+ java.lang.String mode)
+
++ Start a new process and return a file for input or output |
+
+protected abstract IoLib.File |
+tmpFile()
+
++ Open a temporary file. |
+
+protected abstract IoLib.File |
+wrapStdin()
+
++ Wrap the standard input. |
+
+protected abstract IoLib.File |
+wrapStdout()
+
++ Wrap the standard output. |
+
Methods inherited from class org.luaj.vm2.lib.OneArgFunction | +
---|
call, call, call, invoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static final java.lang.String[] IO_NAMES+
+public static final java.lang.String[] FILE_NAMES+
+Constructor Detail | +
---|
+public IoLib()+
+Method Detail | +
---|
+protected abstract IoLib.File wrapStdin() + throws java.io.IOException+
+
java.io.IOException
+protected abstract IoLib.File wrapStdout() + throws java.io.IOException+
+
java.io.IOException
+protected abstract IoLib.File openFile(java.lang.String filename, + boolean readMode, + boolean appendMode, + boolean updateMode, + boolean binaryMode) + throws java.io.IOException+
+
filename
- readMode
- true if opening in read modeappendMode
- true if opening in append modeupdateMode
- true if opening in update modebinaryMode
- true if opening in binary mode
+java.io.IOException
- if could not be opened+protected abstract IoLib.File tmpFile() + throws java.io.IOException+
+
java.io.IOException
- if could not be opened+protected abstract IoLib.File openProgram(java.lang.String prog, + java.lang.String mode) + throws java.io.IOException+
+
prog
- the program to executemode
- "r" to read, "w" to write
+java.io.IOException
- if an i/o exception occurs+public LuaValue call(LuaValue arg)+
LuaValue
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class OneArgFunction
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+LuaValue.method(String,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue)
+public Varargs _io_flush() + throws java.io.IOException+
java.io.IOException
+public Varargs _io_tmpfile() + throws java.io.IOException+
java.io.IOException
+public Varargs _io_close(LuaValue file) + throws java.io.IOException+
java.io.IOException
+public Varargs _io_input(LuaValue file)+
+public Varargs _io_output(LuaValue filename)+
+public Varargs _io_type(LuaValue obj)+
+public Varargs _io_popen(java.lang.String prog, + java.lang.String mode) + throws java.io.IOException+
java.io.IOException
+public Varargs _io_open(java.lang.String filename, + java.lang.String mode) + throws java.io.IOException+
java.io.IOException
+public Varargs _io_lines(java.lang.String filename)+
+public Varargs _io_read(Varargs args) + throws java.io.IOException+
java.io.IOException
+public Varargs _io_write(Varargs args) + throws java.io.IOException+
java.io.IOException
+public Varargs _file_close(LuaValue file) + throws java.io.IOException+
java.io.IOException
+public Varargs _file_flush(LuaValue file) + throws java.io.IOException+
java.io.IOException
+public Varargs _file_setvbuf(LuaValue file, + java.lang.String mode, + int size)+
+public Varargs _file_lines(LuaValue file)+
+public Varargs _file_read(LuaValue file, + Varargs subargs) + throws java.io.IOException+
java.io.IOException
+public Varargs _file_seek(LuaValue file, + java.lang.String whence, + int offset) + throws java.io.IOException+
java.io.IOException
+public Varargs _file_write(LuaValue file, + Varargs subargs) + throws java.io.IOException+
java.io.IOException
+public Varargs _io_index(LuaValue v)+
+public Varargs _lines_iter(LuaValue file) + throws java.io.IOException+
java.io.IOException
+public static LuaValue freadbytes(IoLib.File f, + int count) + throws java.io.IOException+
java.io.IOException
+public static LuaValue freaduntil(IoLib.File f, + boolean lineonly) + throws java.io.IOException+
java.io.IOException
+public static LuaValue freadline(IoLib.File f) + throws java.io.IOException+
java.io.IOException
+public static LuaValue freadall(IoLib.File f) + throws java.io.IOException+
java.io.IOException
+public static LuaValue freadnumber(IoLib.File f) + throws java.io.IOException+
java.io.IOException
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction ++
public abstract class LibFunction
+Subclass of LuaFunction
common to Java functions exposed to lua.
+
+ To provide for common implementations in JME and JSE, + library functions are typically grouped on one or more library classes + and an opcode per library function is defined and used to key the switch + to the correct function within the library. +
+ Since lua functions can be called with too few or too many arguments,
+ and there are overloaded LuaValue.call()
functions with varying
+ number of arguments, a Java function exposed in lua needs to handle the
+ argument fixup when a function is called with a number of arguments
+ differs from that expected.
+
+ To simplify the creation of library functions, + there are 5 direct subclasses to handle common cases based on number of + argument values and number of return return values. +
+
+ To be a Java library that can be loaded via require
, it should have
+ a public constructor that returns a LuaValue
that, when executed,
+ initializes the library.
+
+ For example, the following code will implement a library called "hyperbolic" + with two functions, "sinh", and "cosh": +
import org.luaj.vm2.LuaValue;
+ import org.luaj.vm2.lib.OneArgFunction;
+
+ public class hyperbolic extends OneArgFunction {
+
+ public hyperbolic() {}
+
+ public LuaValue call(LuaValue libname) {
+ LuaValue library = tableOf();
+ library.set( "sinh", new sinh() );
+ library.set( "cosh", new cosh() );
+ env.set( "hyperbolic", library );
+ return library;
+ }
+
+ static class sinh extends OneArgFunction {
+ public LuaValue call(LuaValue x) {
+ return LuaValue.valueOf(Math.sinh(x.checkdouble()));
+ }
+ }
+
+ static class cosh extends OneArgFunction {
+ public LuaValue call(LuaValue x) {
+ return LuaValue.valueOf(Math.cosh(x.checkdouble()));
+ }
+ }
+}
+
+ The default constructor is used to instantiate the library
+ in response to require 'hyperbolic'
statement,
+ provided it is on Javas class path.
+ This instance is then invoked with the name supplied to require()
+ as the only argument, and library should initialized whatever global
+ data it needs to and place it into the environment if needed.
+ In this case, it creates two function, 'sinh', and 'cosh', and puts
+ them into a global table called 'hyperbolic.'
+ It placed the library table into the globals via the LuaFunction.env
+ local variable which corresponds to the globals that apply when the
+ library is loaded.
+ + To test it, a script such as this can be used: +
local t = require('hyperbolic')
+ print( 't', t )
+ print( 'hyperbolic', hyperbolic )
+ for k,v in pairs(t) do
+ print( 'k,v', k,v )
+ end
+ print( 'sinh(.5)', hyperbolic.sinh(.5) )
+ print( 'cosh(.5)', hyperbolic.cosh(.5) )
+
+ + It should produce something like: +
t table: 3dbbd23f
+ hyperbolic table: 3dbbd23f
+ k,v cosh function: 3dbbd128
+ k,v sinh function: 3dbbd242
+ sinh(.5) 0.5210953
+ cosh(.5) 1.127626
+
+
+ See the source code in any of the library functions
+ such as BaseLib
or TableLib
for other examples.
+
+ +
+
+Field Summary | +|
---|---|
+protected java.lang.String |
+name
+
++ The common name for this function, useful for debugging. |
+
+protected int |
+opcode
+
++ User-defined opcode to differentiate between instances of the library function class. |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
+protected |
+LibFunction()
+
++ Default constructor for use by subclasses |
+
+Method Summary | +|
---|---|
+protected void |
+bind(LuaValue env,
+ java.lang.Class factory,
+ java.lang.String[] names)
+
++ Bind a set of library functions. |
+
+protected void |
+bind(LuaValue env,
+ java.lang.Class factory,
+ java.lang.String[] names,
+ int firstopcode)
+
++ Bind a set of library functions, with an offset |
+
+protected static LuaValue[] |
+newupe()
+
++ Java code generation utility to allocate storage for upvalue, leave it empty |
+
+protected static LuaValue[] |
+newupl(LuaValue v)
+
++ Java code generation utility to allocate storage for upvalue, initialize with value |
+
+protected static LuaValue[] |
+newupn()
+
++ Java code generation utility to allocate storage for upvalue, initialize with nil |
+
+ java.lang.String |
+tojstring()
+
++ Convert to human readable String for any type. |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+protected int opcode+
+ Subclass will typicall switch on this value to provide the specific behavior for each function. +
+
+protected java.lang.String name+
+ Binding functions initialize this to the name to which it is bound. +
+
+Constructor Detail | +
---|
+protected LibFunction()+
+
+Method Detail | +
---|
+public java.lang.String tojstring()+
LuaValue
+
tojstring
in class LuaValue
LuaValue.tostring()
,
+LuaValue.optjstring(String)
,
+LuaValue.checkjstring()
,
+LuaValue.isstring()
,
+TSTRING
+protected void bind(LuaValue env, + java.lang.Class factory, + java.lang.String[] names)+
+ An array of names is provided, and the first name is bound + with opcode = 0, second with 1, etc. +
+
env
- The environment to apply to each bound functionfactory
- the Class to instantiate for each bound functionnames
- array of String names, one for each function.bind(LuaValue, Class, String[], int)
+protected void bind(LuaValue env, + java.lang.Class factory, + java.lang.String[] names, + int firstopcode)+
+ An array of names is provided, and the first name is bound
+ with opcode = firstopcode
, second with firstopcode+1
, etc.
+
+
env
- The environment to apply to each bound functionfactory
- the Class to instantiate for each bound functionnames
- array of String names, one for each function.firstopcode
- the first opcode to usebind(LuaValue, Class, String[])
+protected static LuaValue[] newupe()+
+
+protected static LuaValue[] newupn()+
+
+protected static LuaValue[] newupl(LuaValue v)+
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.OneArgFunction + org.luaj.vm2.lib.MathLib ++
public class MathLib
+Subclass of LibFunction
which implements the lua standard math
+ library.
+
+ It contains only the math library support that is possible on JME.
+ For a more complete implementation based on math functions specific to JSE
+ use JseMathLib
.
+ In Particular the following math functions are not implemented by this library:
+
+ The implementations of exp()
and pow()
are constructed by
+ hand for JME, so will be slower and less accurate than when executed on the JSE platform.
+
+ Typically, this library is included as part of a call to either
+ JmePlatform#standardGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ LuaThread.setGlobals(_G);
+ _G.load(new BaseLib());
+ _G.load(new PackageLib());
+ _G.load(new MathLib());
+ System.out.println( _G.get("math").get("sqrt").call( LuaValue.valueOf(2) ) );
+
+ Doing so will ensure the library is properly initialized
+ and loaded into the globals table.
+ + This has been implemented to match as closely as possible the behavior in the corresponding library in C. +
+ +
+
LibFunction
,
+JsePlatform
,
+JmePlatform
,
+JseMathLib
,
+http://www.lua.org/manual/5.1/manual.html#5.6+Field Summary | +|
---|---|
+static MathLib |
+MATHLIB
+
++ |
+
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
MathLib()
+
++ |
+
+Method Summary | +|
---|---|
+ LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+static double |
+dpow_d(double a,
+ double b)
+
++ |
+
+protected static double |
+dpow_default(double a,
+ double b)
+
++ Default JME version computes using longhand heuristics. |
+
+ double |
+dpow_lib(double a,
+ double b)
+
++ Hook to override default dpow behavior with faster implementation. |
+
+static LuaValue |
+dpow(double a,
+ double b)
+
++ compute power using installed math library, or default if there is no math library installed |
+
Methods inherited from class org.luaj.vm2.lib.OneArgFunction | +
---|
call, call, call, invoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static MathLib MATHLIB+
+Constructor Detail | +
---|
+public MathLib()+
+Method Detail | +
---|
+public LuaValue call(LuaValue arg)+
LuaValue
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class OneArgFunction
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+LuaValue.method(String,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue)
+public static LuaValue dpow(double a, + double b)+
+
+public static double dpow_d(double a, + double b)+
+public double dpow_lib(double a, + double b)+
+
+protected static double dpow_default(double a, + double b)+
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.OneArgFunction ++
public abstract class OneArgFunction
+Abstract base class for Java function implementations that take one argument and + return one value. +
+ Subclasses need only implement LuaValue.call(LuaValue)
to complete this class,
+ simplifying development.
+ All other uses of call()
, invoke(Varargs)
,etc,
+ are routed through this method by this class,
+ dropping or extending arguments with nil
values as required.
+
+ If more than one argument are required, or no arguments are required,
+ or variable argument or variable return values,
+ then use one of the related function
+ ZeroArgFunction
, TwoArgFunction
, ThreeArgFunction
, or VarArgFunction
.
+
+ See LibFunction
for more information on implementation libraries and library functions.
+
+ +
+
call(LuaValue)
,
+LibFunction
,
+ZeroArgFunction
,
+TwoArgFunction
,
+ThreeArgFunction
,
+VarArgFunction
+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
OneArgFunction()
+
++ Default constructor |
+|
OneArgFunction(LuaValue env)
+
++ Constructor with specific environment |
+
+Method Summary | +|
---|---|
+ LuaValue |
+call()
+
++ Call this with 0 arguments, including metatag processing,
+ and return only the first return value. |
+
+abstract LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2)
+
++ Call this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ Call this with 3 arguments, including metatag processing,
+ and return only the first return value. |
+
+ Varargs |
+invoke(Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public OneArgFunction()+
+
+public OneArgFunction(LuaValue env)+
+
env
- The environment to apply during constructon.+Method Detail | +
---|
+public abstract LuaValue call(LuaValue arg)+
LuaValue
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+LuaValue.method(String,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue)
+public final LuaValue call()+
LuaValue
this
with 0 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
(this())
, or NIL
if there were none.LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.method(String)
,
+LuaValue.method(LuaValue)
+public final LuaValue call(LuaValue arg1, + LuaValue arg2)+
LuaValue
this
with 2 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called function
+(this(arg1,arg2))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue)
,
+LuaValue.method(String,LuaValue,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue,LuaValue)
+public LuaValue call(LuaValue arg1, + LuaValue arg2, + LuaValue arg3)+
LuaValue
this
with 3 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called functionarg3
- Second argument to supply to the called function
+(this(arg1,arg2,arg3))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue, LuaValue)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+public Varargs invoke(Varargs varargs)+
LuaValue
this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ If this
is a LuaFunction
, call it, and return all values.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a method call, use LuaValue.invokemethod(LuaValue)
instead.
+
+
invoke
in class LuaValue
varargs
- Varargs containing the arguments to supply to the called function
+Varargs
instance.LuaValue.varargsOf(LuaValue[])
,
+LuaValue.call(LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.invoke(LuaValue,Varargs)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.VarArgFunction + org.luaj.vm2.lib.OsLib ++
public class OsLib
+Subclass of LibFunction
which implements the standard lua os
library.
+
+ It is a usable base with simplified stub functions + for library functions that cannot be implemented uniformly + on Jse and Jme. +
+ This can be installed as-is on either platform, or extended + and refined to be used in a complete Jse implementation. +
+ Because the nature of the os
library is to encapsulate
+ os-specific features, the behavior of these functions varies considerably
+ from their counterparts in the C platform.
+
+ The following functions have limited implementations of features + that are not supported well on Jme: +
execute()
remove()
rename()
tmpname()
+ Typically, this library is included as part of a call to either
+ JmePlatform#standardGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ LuaThread.setGlobals(_G);
+ _G.load(new BaseLib());
+ _G.load(new PackageLib());
+ _G.load(new OsLib());
+ System.out.println( _G.get("os").get("time").call() );
+
+ Doing so will ensure the library is properly initialized
+ and loaded into the globals table.
+ +
+ +
+
LibFunction
,
+JseOsLib
,
+JsePlatform
,
+JmePlatform
,
+http://www.lua.org/manual/5.1/manual.html#5.8+Field Summary | +|
---|---|
+static java.lang.String |
+TMP_PREFIX
+
++ |
+
+static java.lang.String |
+TMP_SUFFIX
+
++ |
+
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
OsLib()
+
++ Create and OsLib instance. |
+
+Method Summary | +|
---|---|
+protected double |
+clock()
+
++ |
+
+protected java.lang.String |
+date(java.lang.String format,
+ double time)
+
++ If the time argument is present, this is the time to be formatted + (see the os.time function for a description of this value). |
+
+protected double |
+difftime(double t2,
+ double t1)
+
++ Returns the number of seconds from time t1 to time t2. |
+
+protected int |
+execute(java.lang.String command)
+
++ This function is equivalent to the C function system. |
+
+protected void |
+exit(int code)
+
++ Calls the C function exit, with an optional code, to terminate the host program. |
+
+protected java.lang.String |
+getenv(java.lang.String varname)
+
++ Returns the value of the process environment variable varname, + or null if the variable is not defined. |
+
+ LuaValue |
+init()
+
++ |
+
+ Varargs |
+invoke(Varargs args)
+
++ Override and implement for the best performance. |
+
+protected void |
+remove(java.lang.String filename)
+
++ Deletes the file or directory with the given name. |
+
+protected void |
+rename(java.lang.String oldname,
+ java.lang.String newname)
+
++ Renames file or directory named oldname to newname. |
+
+protected java.lang.String |
+setlocale(java.lang.String locale,
+ java.lang.String category)
+
++ Sets the current locale of the program. |
+
+protected long |
+time(LuaTable table)
+
++ Returns the current time when called without arguments, + or a time representing the date and time specified by the given table. |
+
+protected java.lang.String |
+tmpname()
+
++ Returns a string with a file name that can be used for a temporary file. |
+
Methods inherited from class org.luaj.vm2.lib.VarArgFunction | +
---|
call, call, call, call, onInvoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static java.lang.String TMP_PREFIX+
+public static java.lang.String TMP_SUFFIX+
+Constructor Detail | +
---|
+public OsLib()+
+
+Method Detail | +
---|
+public LuaValue init()+
+public Varargs invoke(Varargs args)+
VarArgFunction
+
invoke
in class VarArgFunction
args
- the arguments to the function call.
+Varargs
instance.LuaValue.varargsOf(LuaValue[])
,
+LuaValue.call(LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.invoke(LuaValue,Varargs)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+protected double clock()+
+protected double difftime(double t2, + double t1)+
+
t2
- t1
-
++protected java.lang.String date(java.lang.String format, + double time)+
+
format
- time
- time since epoch, or -1 if not supplied
++protected int execute(java.lang.String command)+
+
command
- command to pass to the system+protected void exit(int code)+
+
code
- +protected java.lang.String getenv(java.lang.String varname)+
+
varname
-
++protected void remove(java.lang.String filename) + throws java.io.IOException+
+
filename
-
+java.io.IOException
- if it fails+protected void rename(java.lang.String oldname, + java.lang.String newname) + throws java.io.IOException+
+
oldname
- old file namenewname
- new file name
+java.io.IOException
- if it fails+protected java.lang.String setlocale(java.lang.String locale, + java.lang.String category)+
+
locale
- category
-
++protected long time(LuaTable table)+
+
table
-
++protected java.lang.String tmpname()+
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.OneArgFunction + org.luaj.vm2.lib.PackageLib ++
public class PackageLib
+Subclass of LibFunction
which implements the lua standard package and module
+ library functions.
+
+
+ Typically, this library is included as part of a call to either
+ JsePlatform#standardGlobals()
or JmePlatform#standardGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ LuaThread.setGlobals(_G);
+ _G.load(new BaseLib());
+ _G.load(new PackageLib());
+ System.out.println( _G.get("require").call(LuaValue.valueOf("hyperbolic")) );
+
+ In practice, the first 4 lines of the above are minimal requirements to get
+ and initialize a globals table capable of basic reqire, print, and other functions,
+ so it is much more convenient to use the JsePlatform
and JmePlatform
+ utility classes instead.
+
+ This has been implemented to match as closely as possible the behavior in the corresponding library in C.
+ However, the default filesystem search semantics are different and delegated to the bas library
+ as outlined in the BaseLib
and JseBaseLib
documetnation.
+
+ +
+
LibFunction
,
+BaseLib
,
+JseBaseLib
,
+JsePlatform
,
+JmePlatform
,
+http://www.lua.org/manual/5.1/manual.html#5.3+Field Summary | +|
---|---|
+static java.lang.String |
+DEFAULT_LUA_PATH
+
++ |
+
+static PackageLib |
+instance
+
++ Most recent instance of PackageLib |
+
+ LuaValue |
+java_loader
+
++ Loader that loads as a Java class. |
+
+ LuaTable |
+LOADED
+
++ |
+
+ LuaValue |
+lua_loader
+
++ Loader that loads as a lua script using the LUA_PATH |
+
+ LuaTable |
+PACKAGE
+
++ |
+
+ LuaValue |
+preload_loader
+
++ Loader that loads from preload table if found there |
+
+ java.io.InputStream |
+STDIN
+
++ |
+
+ java.io.PrintStream |
+STDOUT
+
++ |
+
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
PackageLib()
+
++ |
+
+Method Summary | +|
---|---|
+ LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+static Varargs |
+loadlib(Varargs args)
+
++ |
+
+ Varargs |
+module(Varargs args)
+
++ module (name [, ...]) + + Creates a module. |
+
+ LuaValue |
+require(LuaValue arg)
+
++ require (modname) + + Loads the given module. |
+
+ void |
+setIsLoaded(java.lang.String name,
+ LuaTable value)
+
++ Allow packages to mark themselves as loaded |
+
+ void |
+setLuaPath(java.lang.String newLuaPath)
+
++ |
+
+static java.lang.String |
+toClassname(java.lang.String filename)
+
++ Convert lua filename to valid class name |
+
+ java.lang.String |
+tojstring()
+
++ Convert to human readable String for any type. |
+
Methods inherited from class org.luaj.vm2.lib.OneArgFunction | +
---|
call, call, call, invoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static java.lang.String DEFAULT_LUA_PATH+
+public java.io.InputStream STDIN+
+public java.io.PrintStream STDOUT+
+public LuaTable LOADED+
+public LuaTable PACKAGE+
+public static PackageLib instance+
+
+public LuaValue preload_loader+
+
+public LuaValue lua_loader+
+
+public LuaValue java_loader+
+
+Constructor Detail | +
---|
+public PackageLib()+
+Method Detail | +
---|
+public LuaValue call(LuaValue arg)+
LuaValue
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class OneArgFunction
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+LuaValue.method(String,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue)
+public void setIsLoaded(java.lang.String name, + LuaTable value)+
+
+public void setLuaPath(java.lang.String newLuaPath)+
+public java.lang.String tojstring()+
LuaValue
+
tojstring
in class LibFunction
LuaValue.tostring()
,
+LuaValue.optjstring(String)
,
+LuaValue.checkjstring()
,
+LuaValue.isstring()
,
+TSTRING
+public Varargs module(Varargs args)+
+
+public LuaValue require(LuaValue arg)+
+
+public static Varargs loadlib(Varargs args)+
+public static final java.lang.String toClassname(java.lang.String filename)+
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
public interface ResourceFinder
+Interface for opening application resource files such as scripts sources. +
+ This is used by required to load files that are part of + the application, and implemented by BaseLib + for both the Jme and Jse platforms. +
+ The Jme version of base lib BaseLib
+ implements BaseLib.FINDER
via Class.getResourceAsStream(String)
,
+ while the Jse version JseBaseLib
implements it using File.File(String)
.
+
+ The io library does not use this API for file manipulation. +
+
+ +
+
BaseLib
,
+BaseLib.FINDER
,
+JseBaseLib
,
+JmePlatform
,
+JsePlatform
+Method Summary | +|
---|---|
+ java.io.InputStream |
+findResource(java.lang.String filename)
+
++ Try to open a file, or return null if not found. |
+
+Method Detail | +
---|
+java.io.InputStream findResource(java.lang.String filename)+
+
filename
-
+BaseLib
,
+JseBaseLib
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.OneArgFunction + org.luaj.vm2.lib.StringLib ++
public class StringLib
+Subclass of LibFunction
which implements the lua standard string
+ library.
+
+
+ Typically, this library is included as part of a call to either
+ JsePlatform#standardGlobals()
or JmePlatform#standardGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ LuaThread.setGlobals(_G);
+ _G.load(new BaseLib());
+ _G.load(new PackageLib());
+ _G.load(new StringLib());
+ System.out.println( _G.get("string").get("upper").call( LuaValue.valueOf("abcde") ) );
+
+ Doing so will ensure the library is properly initialized
+ and loaded into the globals table.
+ + This is a direct port of the corresponding library in C. +
+ +
+
LibFunction
,
+JsePlatform
,
+JmePlatform
,
+http://www.lua.org/manual/5.1/manual.html#5.4+Field Summary | +|
---|---|
+static LuaTable |
+instance
+
++ |
+
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
StringLib()
+
++ |
+
+Method Summary | +|
---|---|
+ LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+static Varargs |
+char_(Varargs args)
+
++ string.char (...) + + Receives zero or more integers. |
+
Methods inherited from class org.luaj.vm2.lib.OneArgFunction | +
---|
call, call, call, invoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static LuaTable instance+
+Constructor Detail | +
---|
+public StringLib()+
+Method Detail | +
---|
+public LuaValue call(LuaValue arg)+
LuaValue
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class OneArgFunction
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+LuaValue.method(String,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue)
+public static Varargs char_(Varargs args)+
+
args
- the calling VM
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.OneArgFunction + org.luaj.vm2.lib.TableLib ++
public class TableLib
+Subclass of LibFunction
which implements the lua standard table
+ library.
+
+
+ Typically, this library is included as part of a call to either
+ JsePlatform#standardGlobals()
or JmePlatform#standardGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ LuaThread.setGlobals(_G);
+ _G.load(new BaseLib());
+ _G.load(new PackageLib());
+ _G.load(new TableLib());
+ LuaValue tbl = LuaValue.listOf( new LuaValue[] {
+ LuaValue.valueOf( "abc" ),
+ LuaValue.valueOf( "def" ) } );
+ LuaValue sep = LuaValue.valueOf( "-" );
+ System.out.println( _G.get("table").get("concat").call( tbl, sep ) );
+
+ Doing so will ensure the library is properly initialized
+ and loaded into the globals table.
+ + This has been implemented to match as closely as possible the behavior in the corresponding library in C. +
+ +
+
LibFunction
,
+JsePlatform
,
+JmePlatform
,
+http://www.lua.org/manual/5.1/manual.html#5.5+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
TableLib()
+
++ |
+
+Method Summary | +|
---|---|
+ LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
Methods inherited from class org.luaj.vm2.lib.OneArgFunction | +
---|
call, call, call, invoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public TableLib()+
+Method Detail | +
---|
+public LuaValue call(LuaValue arg)+
LuaValue
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class OneArgFunction
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+LuaValue.method(String,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue)
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.ThreeArgFunction ++
public abstract class ThreeArgFunction
+Abstract base class for Java function implementations that take two arguments and + return one value. +
+ Subclasses need only implement LuaValue.call(LuaValue,LuaValue,LuaValue)
to complete this class,
+ simplifying development.
+ All other uses of call()
, invoke(Varargs)
,etc,
+ are routed through this method by this class,
+ dropping or extending arguments with nil
values as required.
+
+ If more or less than three arguments are required,
+ or variable argument or variable return values,
+ then use one of the related function
+ ZeroArgFunction
, OneArgFunction
, TwoArgFunction
, or VarArgFunction
.
+
+ See LibFunction
for more information on implementation libraries and library functions.
+
+ +
+
call(LuaValue,LuaValue,LuaValue)
,
+LibFunction
,
+ZeroArgFunction
,
+OneArgFunction
,
+TwoArgFunction
,
+VarArgFunction
+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
ThreeArgFunction()
+
++ Default constructor |
+|
ThreeArgFunction(LuaValue env)
+
++ Constructor with specific environment |
+
+Method Summary | +|
---|---|
+ LuaValue |
+call()
+
++ Call this with 0 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2)
+
++ Call this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+abstract LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ Call this with 3 arguments, including metatag processing,
+ and return only the first return value. |
+
+ Varargs |
+invoke(Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public ThreeArgFunction()+
+
+public ThreeArgFunction(LuaValue env)+
+
env
- The environment to apply during constructon.+Method Detail | +
---|
+public abstract LuaValue call(LuaValue arg1, + LuaValue arg2, + LuaValue arg3)+
LuaValue
this
with 3 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called functionarg3
- Second argument to supply to the called function
+(this(arg1,arg2,arg3))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue, LuaValue)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+public final LuaValue call()+
LuaValue
this
with 0 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
(this())
, or NIL
if there were none.LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.method(String)
,
+LuaValue.method(LuaValue)
+public final LuaValue call(LuaValue arg)+
LuaValue
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+LuaValue.method(String,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue)
+public LuaValue call(LuaValue arg1, + LuaValue arg2)+
LuaValue
this
with 2 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called function
+(this(arg1,arg2))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue)
,
+LuaValue.method(String,LuaValue,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue,LuaValue)
+public Varargs invoke(Varargs varargs)+
LuaValue
this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ If this
is a LuaFunction
, call it, and return all values.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a method call, use LuaValue.invokemethod(LuaValue)
instead.
+
+
invoke
in class LuaValue
varargs
- Varargs containing the arguments to supply to the called function
+Varargs
instance.LuaValue.varargsOf(LuaValue[])
,
+LuaValue.call(LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.invoke(LuaValue,Varargs)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.TwoArgFunction ++
public abstract class TwoArgFunction
+Abstract base class for Java function implementations that take two arguments and + return one value. +
+ Subclasses need only implement LuaValue.call(LuaValue,LuaValue)
to complete this class,
+ simplifying development.
+ All other uses of call()
, invoke(Varargs)
,etc,
+ are routed through this method by this class,
+ dropping or extending arguments with nil
values as required.
+
+ If more or less than two arguments are required,
+ or variable argument or variable return values,
+ then use one of the related function
+ ZeroArgFunction
, OneArgFunction
, ThreeArgFunction
, or VarArgFunction
.
+
+ See LibFunction
for more information on implementation libraries and library functions.
+
+ +
+
call(LuaValue,LuaValue)
,
+LibFunction
,
+ZeroArgFunction
,
+OneArgFunction
,
+ThreeArgFunction
,
+VarArgFunction
+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
TwoArgFunction()
+
++ Default constructor |
+|
TwoArgFunction(LuaValue env)
+
++ Constructor with specific environment |
+
+Method Summary | +|
---|---|
+ LuaValue |
+call()
+
++ Call this with 0 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+abstract LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2)
+
++ Call this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ Call this with 3 arguments, including metatag processing,
+ and return only the first return value. |
+
+ Varargs |
+invoke(Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public TwoArgFunction()+
+
+public TwoArgFunction(LuaValue env)+
+
env
- The environment to apply during constructon.+Method Detail | +
---|
+public abstract LuaValue call(LuaValue arg1, + LuaValue arg2)+
LuaValue
this
with 2 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called function
+(this(arg1,arg2))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue)
,
+LuaValue.method(String,LuaValue,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue,LuaValue)
+public final LuaValue call()+
LuaValue
this
with 0 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
(this())
, or NIL
if there were none.LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.method(String)
,
+LuaValue.method(LuaValue)
+public final LuaValue call(LuaValue arg)+
LuaValue
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+LuaValue.method(String,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue)
+public LuaValue call(LuaValue arg1, + LuaValue arg2, + LuaValue arg3)+
LuaValue
this
with 3 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called functionarg3
- Second argument to supply to the called function
+(this(arg1,arg2,arg3))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue, LuaValue)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+public Varargs invoke(Varargs varargs)+
LuaValue
this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ If this
is a LuaFunction
, call it, and return all values.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a method call, use LuaValue.invokemethod(LuaValue)
instead.
+
+
invoke
in class LuaValue
varargs
- Varargs containing the arguments to supply to the called function
+Varargs
instance.LuaValue.varargsOf(LuaValue[])
,
+LuaValue.call(LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.invoke(LuaValue,Varargs)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.VarArgFunction ++
public abstract class VarArgFunction
+Abstract base class for Java function implementations that takes varaiable arguments and + returns multiple return values. +
+ Subclasses need only implement LuaValue.invoke(Varargs)
to complete this class,
+ simplifying development.
+ All other uses of call(LuaValue)
, LuaValue.invoke()
,etc,
+ are routed through this method by this class,
+ converting arguments to and
+ dropping or extending return values with nil
values as required.
+
+ If between one and three arguments are required, and only one return value is returned,
+ ZeroArgFunction
, OneArgFunction
, TwoArgFunction
, or ThreeArgFunction
.
+
+ See LibFunction
for more information on implementation libraries and library functions.
+
+ +
+
invoke(Varargs)
,
+LibFunction
,
+ZeroArgFunction
,
+OneArgFunction
,
+TwoArgFunction
,
+ThreeArgFunction
+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
VarArgFunction()
+
++ |
+|
VarArgFunction(LuaValue env)
+
++ |
+
+Method Summary | +|
---|---|
+ LuaValue |
+call()
+
++ Call this with 0 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2)
+
++ Call this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ Call this with 3 arguments, including metatag processing,
+ and return only the first return value. |
+
+ Varargs |
+invoke(Varargs args)
+
++ Override and implement for the best performance. |
+
+ Varargs |
+onInvoke(Varargs args)
+
++ Override to provide a call implementation that runs in an environment + that can participate in setfenv, and behaves as expected + when returning TailcallVarargs. |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public VarArgFunction()+
+public VarArgFunction(LuaValue env)+
+Method Detail | +
---|
+public LuaValue call()+
LuaValue
this
with 0 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
(this())
, or NIL
if there were none.LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.method(String)
,
+LuaValue.method(LuaValue)
+public LuaValue call(LuaValue arg)+
LuaValue
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+LuaValue.method(String,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue)
+public LuaValue call(LuaValue arg1, + LuaValue arg2)+
LuaValue
this
with 2 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called function
+(this(arg1,arg2))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue)
,
+LuaValue.method(String,LuaValue,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue,LuaValue)
+public LuaValue call(LuaValue arg1, + LuaValue arg2, + LuaValue arg3)+
LuaValue
this
with 3 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called functionarg3
- Second argument to supply to the called function
+(this(arg1,arg2,arg3))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue, LuaValue)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+public Varargs invoke(Varargs args)+
+
invoke
in class LuaValue
args
- the arguments to the function call.
+Varargs
instance.LuaValue.varargsOf(LuaValue[])
,
+LuaValue.call(LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.invoke(LuaValue,Varargs)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+public Varargs onInvoke(Varargs args)+
+
onInvoke
in class LuaValue
args
- the arguments to the function call.
+LuaValue.call()
,
+LuaValue.invoke()
,
+LuaValue.method(LuaValue)
,
+LuaValue.invokemethod(LuaValue)
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.ZeroArgFunction ++
public abstract class ZeroArgFunction
+Abstract base class for Java function implementations that take no arguments and + return one value. +
+ Subclasses need only implement LuaValue.call()
to complete this class,
+ simplifying development.
+ All other uses of call(LuaValue)
, invoke(Varargs)
,etc,
+ are routed through this method by this class.
+
+ If one or more arguments are required, or variable argument or variable return values,
+ then use one of the related function
+ OneArgFunction
, TwoArgFunction
, ThreeArgFunction
, or VarArgFunction
.
+
+ See LibFunction
for more information on implementation libraries and library functions.
+
+ +
+
call()
,
+LibFunction
,
+OneArgFunction
,
+TwoArgFunction
,
+ThreeArgFunction
,
+VarArgFunction
+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
ZeroArgFunction()
+
++ Default constructor |
+|
ZeroArgFunction(LuaValue env)
+
++ Constructor with specific environment |
+
+Method Summary | +|
---|---|
+abstract LuaValue |
+call()
+
++ Call this with 0 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2)
+
++ Call this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
+ LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2,
+ LuaValue arg3)
+
++ Call this with 3 arguments, including metatag processing,
+ and return only the first return value. |
+
+ Varargs |
+invoke(Varargs varargs)
+
++ Call this with variable arguments, including metatag processing,
+ and retain all return values in a Varargs . |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public ZeroArgFunction()+
+
+public ZeroArgFunction(LuaValue env)+
+
env
- The environment to apply during constructon.+Method Detail | +
---|
+public abstract LuaValue call()+
LuaValue
this
with 0 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
(this())
, or NIL
if there were none.LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.method(String)
,
+LuaValue.method(LuaValue)
+public LuaValue call(LuaValue arg)+
LuaValue
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+LuaValue.method(String,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue)
+public LuaValue call(LuaValue arg1, + LuaValue arg2)+
LuaValue
this
with 2 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called function
+(this(arg1,arg2))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue)
,
+LuaValue.method(String,LuaValue,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue,LuaValue)
+public LuaValue call(LuaValue arg1, + LuaValue arg2, + LuaValue arg3)+
LuaValue
this
with 3 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class LuaValue
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called functionarg3
- Second argument to supply to the called function
+(this(arg1,arg2,arg3))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue, LuaValue)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+public Varargs invoke(Varargs varargs)+
LuaValue
this
with variable arguments, including metatag processing,
+ and retain all return values in a Varargs
.
+
+ If this
is a LuaFunction
, call it, and return all values.
+ Otherwise, look for the CALL
metatag and call that.
+
+ To get a particular return value, us Varargs.arg(int)
+
+ To call this
as a method call, use LuaValue.invokemethod(LuaValue)
instead.
+
+
invoke
in class LuaValue
varargs
- Varargs containing the arguments to supply to the called function
+Varargs
instance.LuaValue.varargsOf(LuaValue[])
,
+LuaValue.call(LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.invoke(LuaValue,Varargs)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use BaseLib | +|
---|---|
org.luaj.vm2.lib | ++ |
org.luaj.vm2.lib.jse | ++ |
+Uses of BaseLib in org.luaj.vm2.lib | +
---|
+ +
Fields in org.luaj.vm2.lib declared as BaseLib | +|
---|---|
+static BaseLib |
+BaseLib.instance
+
++ |
+
+Uses of BaseLib in org.luaj.vm2.lib.jse | +
---|
+ +
Subclasses of BaseLib in org.luaj.vm2.lib.jse | +|
---|---|
+ class |
+JseBaseLib
+
++ Subclass of BaseLib and LibFunction which implements the lua basic library functions
+ and provides a directory based ResourceFinder as the FINDER . |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use IoLib.File | +|
---|---|
org.luaj.vm2.lib | ++ |
org.luaj.vm2.lib.jme | ++ |
org.luaj.vm2.lib.jse | ++ |
+Uses of IoLib.File in org.luaj.vm2.lib | +
---|
+ +
Methods in org.luaj.vm2.lib that return IoLib.File | +|
---|---|
+protected abstract IoLib.File |
+IoLib.openFile(java.lang.String filename,
+ boolean readMode,
+ boolean appendMode,
+ boolean updateMode,
+ boolean binaryMode)
+
++ Open a file in a particular mode. |
+
+protected abstract IoLib.File |
+IoLib.openProgram(java.lang.String prog,
+ java.lang.String mode)
+
++ Start a new process and return a file for input or output |
+
+protected abstract IoLib.File |
+IoLib.tmpFile()
+
++ Open a temporary file. |
+
+protected abstract IoLib.File |
+IoLib.wrapStdin()
+
++ Wrap the standard input. |
+
+protected abstract IoLib.File |
+IoLib.wrapStdout()
+
++ Wrap the standard output. |
+
+ +
Methods in org.luaj.vm2.lib with parameters of type IoLib.File | +|
---|---|
+static LuaValue |
+IoLib.freadall(IoLib.File f)
+
++ |
+
+static LuaValue |
+IoLib.freadbytes(IoLib.File f,
+ int count)
+
++ |
+
+static LuaValue |
+IoLib.freadline(IoLib.File f)
+
++ |
+
+static LuaValue |
+IoLib.freadnumber(IoLib.File f)
+
++ |
+
+static LuaValue |
+IoLib.freaduntil(IoLib.File f,
+ boolean lineonly)
+
++ |
+
+Uses of IoLib.File in org.luaj.vm2.lib.jme | +
---|
+ +
Methods in org.luaj.vm2.lib.jme that return IoLib.File | +|
---|---|
+protected IoLib.File |
+JmeIoLib.openFile(java.lang.String filename,
+ boolean readMode,
+ boolean appendMode,
+ boolean updateMode,
+ boolean binaryMode)
+
++ |
+
+protected IoLib.File |
+JmeIoLib.openProgram(java.lang.String prog,
+ java.lang.String mode)
+
++ |
+
+protected IoLib.File |
+JmeIoLib.tmpFile()
+
++ |
+
+protected IoLib.File |
+JmeIoLib.wrapStdin()
+
++ |
+
+protected IoLib.File |
+JmeIoLib.wrapStdout()
+
++ |
+
+Uses of IoLib.File in org.luaj.vm2.lib.jse | +
---|
+ +
Methods in org.luaj.vm2.lib.jse that return IoLib.File | +|
---|---|
+protected IoLib.File |
+JseIoLib.openFile(java.lang.String filename,
+ boolean readMode,
+ boolean appendMode,
+ boolean updateMode,
+ boolean binaryMode)
+
++ |
+
+protected IoLib.File |
+JseIoLib.openProgram(java.lang.String prog,
+ java.lang.String mode)
+
++ |
+
+protected IoLib.File |
+JseIoLib.tmpFile()
+
++ |
+
+protected IoLib.File |
+JseIoLib.wrapStdin()
+
++ |
+
+protected IoLib.File |
+JseIoLib.wrapStdout()
+
++ |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use IoLib | +|
---|---|
org.luaj.vm2.lib.jme | ++ |
org.luaj.vm2.lib.jse | ++ |
+Uses of IoLib in org.luaj.vm2.lib.jme | +
---|
+ +
Subclasses of IoLib in org.luaj.vm2.lib.jme | +|
---|---|
+ class |
+JmeIoLib
+
++ Subclass of IoLib and therefore LibFunction which implements the lua standard io
+ library for the JSE platform. |
+
+Uses of IoLib in org.luaj.vm2.lib.jse | +
---|
+ +
Subclasses of IoLib in org.luaj.vm2.lib.jse | +|
---|---|
+ class |
+JseIoLib
+
++ Subclass of IoLib and therefore LibFunction which implements the lua standard io
+ library for the JSE platform. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LibFunction | +|
---|---|
org.luaj.vm2.lib | ++ |
org.luaj.vm2.lib.jme | ++ |
org.luaj.vm2.lib.jse | ++ |
+Uses of LibFunction in org.luaj.vm2.lib | +
---|
+ +
Subclasses of LibFunction in org.luaj.vm2.lib | +|
---|---|
+ class |
+BaseLib
+
++ Subclass of LibFunction which implements the lua basic library functions. |
+
+ class |
+CoroutineLib
+
++ Subclass of LibFunction which implements the lua standard coroutine
+ library. |
+
+ class |
+DebugLib
+
++ Subclass of LibFunction which implements the lua standard debug
+ library. |
+
+ class |
+IoLib
+
++ Abstract base class extending LibFunction which implements the
+ core of the lua standard io library. |
+
+ class |
+MathLib
+
++ Subclass of LibFunction which implements the lua standard math
+ library. |
+
+ class |
+OneArgFunction
+
++ Abstract base class for Java function implementations that take one argument and + return one value. |
+
+ class |
+OsLib
+
++ Subclass of LibFunction which implements the standard lua os library. |
+
+ class |
+PackageLib
+
++ Subclass of LibFunction which implements the lua standard package and module
+ library functions. |
+
+ class |
+StringLib
+
++ Subclass of LibFunction which implements the lua standard string
+ library. |
+
+ class |
+TableLib
+
++ Subclass of LibFunction which implements the lua standard table
+ library. |
+
+ class |
+ThreeArgFunction
+
++ Abstract base class for Java function implementations that take two arguments and + return one value. |
+
+ class |
+TwoArgFunction
+
++ Abstract base class for Java function implementations that take two arguments and + return one value. |
+
+ class |
+VarArgFunction
+
++ Abstract base class for Java function implementations that takes varaiable arguments and + returns multiple return values. |
+
+ class |
+ZeroArgFunction
+
++ Abstract base class for Java function implementations that take no arguments and + return one value. |
+
+Uses of LibFunction in org.luaj.vm2.lib.jme | +
---|
+ +
Subclasses of LibFunction in org.luaj.vm2.lib.jme | +|
---|---|
+ class |
+JmeIoLib
+
++ Subclass of IoLib and therefore LibFunction which implements the lua standard io
+ library for the JSE platform. |
+
+Uses of LibFunction in org.luaj.vm2.lib.jse | +
---|
+ +
Subclasses of LibFunction in org.luaj.vm2.lib.jse | +|
---|---|
+ class |
+JseBaseLib
+
++ Subclass of BaseLib and LibFunction which implements the lua basic library functions
+ and provides a directory based ResourceFinder as the BaseLib.FINDER . |
+
+ class |
+JseIoLib
+
++ Subclass of IoLib and therefore LibFunction which implements the lua standard io
+ library for the JSE platform. |
+
+ class |
+JseMathLib
+
++ Subclass of LibFunction which implements the lua standard math
+ library. |
+
+static class |
+JseMathLib.JseMathLib1
+
++ |
+
+static class |
+JseMathLib.JseMathLib2
+
++ |
+
+ class |
+JseOsLib
+
++ Subclass of LibFunction which implements the standard lua os library. |
+
+ class |
+LuajavaLib
+
++ Subclass of LibFunction which implements the features of the luajava package. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use MathLib | +|
---|---|
org.luaj.vm2.lib | ++ |
org.luaj.vm2.lib.jse | ++ |
+Uses of MathLib in org.luaj.vm2.lib | +
---|
+ +
Fields in org.luaj.vm2.lib declared as MathLib | +|
---|---|
+static MathLib |
+MathLib.MATHLIB
+
++ |
+
+Uses of MathLib in org.luaj.vm2.lib.jse | +
---|
+ +
Subclasses of MathLib in org.luaj.vm2.lib.jse | +|
---|---|
+ class |
+JseMathLib
+
++ Subclass of LibFunction which implements the lua standard math
+ library. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use OneArgFunction | +|
---|---|
org.luaj.vm2.lib | ++ |
org.luaj.vm2.lib.jme | ++ |
org.luaj.vm2.lib.jse | ++ |
+Uses of OneArgFunction in org.luaj.vm2.lib | +
---|
+ +
Subclasses of OneArgFunction in org.luaj.vm2.lib | +|
---|---|
+ class |
+BaseLib
+
++ Subclass of LibFunction which implements the lua basic library functions. |
+
+ class |
+IoLib
+
++ Abstract base class extending LibFunction which implements the
+ core of the lua standard io library. |
+
+ class |
+MathLib
+
++ Subclass of LibFunction which implements the lua standard math
+ library. |
+
+ class |
+PackageLib
+
++ Subclass of LibFunction which implements the lua standard package and module
+ library functions. |
+
+ class |
+StringLib
+
++ Subclass of LibFunction which implements the lua standard string
+ library. |
+
+ class |
+TableLib
+
++ Subclass of LibFunction which implements the lua standard table
+ library. |
+
+Uses of OneArgFunction in org.luaj.vm2.lib.jme | +
---|
+ +
Subclasses of OneArgFunction in org.luaj.vm2.lib.jme | +|
---|---|
+ class |
+JmeIoLib
+
++ Subclass of IoLib and therefore LibFunction which implements the lua standard io
+ library for the JSE platform. |
+
+Uses of OneArgFunction in org.luaj.vm2.lib.jse | +
---|
+ +
Subclasses of OneArgFunction in org.luaj.vm2.lib.jse | +|
---|---|
+ class |
+JseBaseLib
+
++ Subclass of BaseLib and LibFunction which implements the lua basic library functions
+ and provides a directory based ResourceFinder as the BaseLib.FINDER . |
+
+ class |
+JseIoLib
+
++ Subclass of IoLib and therefore LibFunction which implements the lua standard io
+ library for the JSE platform. |
+
+ class |
+JseMathLib
+
++ Subclass of LibFunction which implements the lua standard math
+ library. |
+
+static class |
+JseMathLib.JseMathLib1
+
++ |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use OsLib | +|
---|---|
org.luaj.vm2.lib.jse | ++ |
+Uses of OsLib in org.luaj.vm2.lib.jse | +
---|
+ +
Subclasses of OsLib in org.luaj.vm2.lib.jse | +|
---|---|
+ class |
+JseOsLib
+
++ Subclass of LibFunction which implements the standard lua os library. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use PackageLib | +|
---|---|
org.luaj.vm2.lib | ++ |
+Uses of PackageLib in org.luaj.vm2.lib | +
---|
+ +
Fields in org.luaj.vm2.lib declared as PackageLib | +|
---|---|
+static PackageLib |
+PackageLib.instance
+
++ Most recent instance of PackageLib |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use ResourceFinder | +|
---|---|
org.luaj.vm2.lib | ++ |
org.luaj.vm2.lib.jse | ++ |
+Uses of ResourceFinder in org.luaj.vm2.lib | +
---|
+ +
Classes in org.luaj.vm2.lib that implement ResourceFinder | +|
---|---|
+ class |
+BaseLib
+
++ Subclass of LibFunction which implements the lua basic library functions. |
+
+ +
Fields in org.luaj.vm2.lib declared as ResourceFinder | +|
---|---|
+static ResourceFinder |
+BaseLib.FINDER
+
++ Singleton file opener for this Java ClassLoader realm. |
+
+Uses of ResourceFinder in org.luaj.vm2.lib.jse | +
---|
+ +
Classes in org.luaj.vm2.lib.jse that implement ResourceFinder | +|
---|---|
+ class |
+JseBaseLib
+
++ Subclass of BaseLib and LibFunction which implements the lua basic library functions
+ and provides a directory based ResourceFinder as the BaseLib.FINDER . |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use TwoArgFunction | +|
---|---|
org.luaj.vm2.lib.jse | ++ |
+Uses of TwoArgFunction in org.luaj.vm2.lib.jse | +
---|
+ +
Subclasses of TwoArgFunction in org.luaj.vm2.lib.jse | +|
---|---|
+static class |
+JseMathLib.JseMathLib2
+
++ |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use VarArgFunction | +|
---|---|
org.luaj.vm2.lib | ++ |
org.luaj.vm2.lib.jse | ++ |
+Uses of VarArgFunction in org.luaj.vm2.lib | +
---|
+ +
Subclasses of VarArgFunction in org.luaj.vm2.lib | +|
---|---|
+ class |
+CoroutineLib
+
++ Subclass of LibFunction which implements the lua standard coroutine
+ library. |
+
+ class |
+DebugLib
+
++ Subclass of LibFunction which implements the lua standard debug
+ library. |
+
+ class |
+OsLib
+
++ Subclass of LibFunction which implements the standard lua os library. |
+
+Uses of VarArgFunction in org.luaj.vm2.lib.jse | +
---|
+ +
Subclasses of VarArgFunction in org.luaj.vm2.lib.jse | +|
---|---|
+ class |
+JseOsLib
+
++ Subclass of LibFunction which implements the standard lua os library. |
+
+ class |
+LuajavaLib
+
++ Subclass of LibFunction which implements the features of the luajava package. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.OneArgFunction + org.luaj.vm2.lib.IoLib + org.luaj.vm2.lib.jme.JmeIoLib ++
public class JmeIoLib
+Subclass of IoLib
and therefore LibFunction
which implements the lua standard io
+ library for the JSE platform.
+
+ The implementation of the is based on CLDC 1.0 and StreamConnection. + However, seek is not supported. +
+ Typically, this library is included as part of a call to
+ JmePlatform.standardGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ LuaThread.setGlobals(_G);
+ _G.load(new BaseLib());
+ _G.load(new PackageLib());
+ _G.load(new JmeIoLib());
+ _G.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
+
+ Doing so will ensure the library is properly initialized
+ and loaded into the globals table.
+ + This has been implemented to match as closely as possible the behavior in the corresponding library in C. +
+ +
+
LibFunction
,
+JsePlatform
,
+JmePlatform
,
+IoLib
,
+JseIoLib
,
+http://www.lua.org/manual/5.1/manual.html#5.6+Nested Class Summary | +
---|
Nested classes/interfaces inherited from class org.luaj.vm2.lib.IoLib | +
---|
IoLib.File |
+
+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.lib.IoLib | +
---|
FILE_NAMES, IO_NAMES |
+
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
JmeIoLib()
+
++ |
+
+Method Summary | +|
---|---|
+protected IoLib.File |
+openFile(java.lang.String filename,
+ boolean readMode,
+ boolean appendMode,
+ boolean updateMode,
+ boolean binaryMode)
+
++ Open a file in a particular mode. |
+
+protected IoLib.File |
+openProgram(java.lang.String prog,
+ java.lang.String mode)
+
++ Start a new process and return a file for input or output |
+
+protected IoLib.File |
+tmpFile()
+
++ Open a temporary file. |
+
+protected IoLib.File |
+wrapStdin()
+
++ Wrap the standard input. |
+
+protected IoLib.File |
+wrapStdout()
+
++ Wrap the standard output. |
+
Methods inherited from class org.luaj.vm2.lib.IoLib | +
---|
_file_close, _file_flush, _file_lines, _file_read, _file_seek, _file_setvbuf, _file_write, _io_close, _io_flush, _io_index, _io_input, _io_lines, _io_open, _io_output, _io_popen, _io_read, _io_tmpfile, _io_type, _io_write, _lines_iter, call, freadall, freadbytes, freadline, freadnumber, freaduntil |
+
Methods inherited from class org.luaj.vm2.lib.OneArgFunction | +
---|
call, call, call, invoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JmeIoLib()+
+Method Detail | +
---|
+protected IoLib.File wrapStdin() + throws java.io.IOException+
IoLib
+
wrapStdin
in class IoLib
java.io.IOException
+protected IoLib.File wrapStdout() + throws java.io.IOException+
IoLib
+
wrapStdout
in class IoLib
java.io.IOException
+protected IoLib.File openFile(java.lang.String filename, + boolean readMode, + boolean appendMode, + boolean updateMode, + boolean binaryMode) + throws java.io.IOException+
IoLib
+
openFile
in class IoLib
readMode
- true if opening in read modeappendMode
- true if opening in append modeupdateMode
- true if opening in update modebinaryMode
- true if opening in binary mode
+java.io.IOException
- if could not be opened+protected IoLib.File openProgram(java.lang.String prog, + java.lang.String mode) + throws java.io.IOException+
IoLib
+
openProgram
in class IoLib
prog
- the program to executemode
- "r" to read, "w" to write
+java.io.IOException
- if an i/o exception occurs+protected IoLib.File tmpFile() + throws java.io.IOException+
IoLib
+
tmpFile
in class IoLib
java.io.IOException
- if could not be opened
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.lib.jme.JmePlatform ++
public class JmePlatform
+The JmePlatform
class is a convenience class to standardize
+ how globals tables are initialized for the JME platform.
+
+ The JME platform, being limited, cannot implement all libraries in all aspects. The main limitations are +
MathLib
for detailsBaseLib
for detailsOsLib
for detailsJmeIoLib
for detailsLuajavaLib
for details
+ It is used to allocate either a set of standard globals using
+ standardGlobals()
or debug globals using debugGlobals()
+
+ A simple example of initializing globals and using them from Java is: +
LuaValue _G = JmePlatform.standardGlobals();
+ _G.get("print").call(LuaValue.valueOf("hello, world"));
+
+ + Once globals are created, a simple way to load and run a script is: +
LoadState.load( getClass().getResourceAsStream("main.lua"), "main.lua", _G ).call();
+
+
+ although require
could also be used:
+
_G.get("require").call(LuaValue.valueOf("main"));
+
+ For this to succeed, the file "main.lua" must be a resource in the class path.
+ See BaseLib
for details on finding scripts using ResourceFinder
.
+ + The standard globals will contain all standard libraries in their JME flavors: +
BaseLib
PackageLib
TableLib
StringLib
CoroutineLib
MathLib
JmeIoLib
OsLib
LuaC
compiler is installed so lua files may be loaded in their source form.
+
+ The debug globals are simply the standard globals plus the debug
library DebugLib
.
+
+
+ The class ensures that initialization is done in the correct order,
+ and that linkage is made to LuaThread.setGlobals(LuaValue)
.
+
+ +
+
JsePlatform
,
+LoadState
+Constructor Summary | +|
---|---|
JmePlatform()
+
++ |
+
+Method Summary | +|
---|---|
+static LuaTable |
+debugGlobals()
+
++ Create standard globals including the debug library. |
+
+static LuaTable |
+standardGlobals()
+
++ Create a standard set of globals for JME including all the libraries. |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JmePlatform()+
+Method Detail | +
---|
+public static LuaTable standardGlobals()+
+
debugGlobals()
,
+JsePlatform
,
+JmePlatform
+public static LuaTable debugGlobals()+
debug
library.
++
#standarsGlobals()
,
+JsePlatform
,
+JmePlatform
,
+DebugLib
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Classes
+
+ +JmeIoLib + +JmePlatform |
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+Class Summary | +|
---|---|
JmeIoLib | +Subclass of IoLib and therefore LibFunction which implements the lua standard io
+ library for the JSE platform. |
+
JmePlatform | +The JmePlatform class is a convenience class to standardize
+ how globals tables are initialized for the JME platform. |
+
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.lib.jse.CoerceJavaToLua ++
public class CoerceJavaToLua
+Helper class to coerce values from Java to lua within the luajava library. +
+ This class is primarily used by the LuajavaLib
,
+ but can also be used directly when working with Java/lua bindings.
+
+ To coerce scalar types, the various, generally the valueOf(type)
methods
+ on LuaValue
may be used:
+
LuaValue.valueOf(boolean)
LuaValue.valueOf(byte[])
LuaValue.valueOf(double)
LuaValue.valueOf(int)
LuaValue.valueOf(String)
+ To coerce arrays of objects and lists, the listOf(..)
and tableOf(...)
methods
+ on LuaValue
may be used:
+
LuaValue.listOf(LuaValue[])
LuaValue.listOf(LuaValue[], org.luaj.vm2.Varargs)
LuaValue.tableOf(LuaValue[])
LuaValue.tableOf(LuaValue[], LuaValue[], org.luaj.vm2.Varargs)
coerce(Object)
looks as the type and dimesioning
+ of the argument and tries to guess the best fit for corrsponding lua scalar,
+ table, or table of tables.
++ +
+
coerce(Object)
,
+LuajavaLib
+Constructor Summary | +|
---|---|
CoerceJavaToLua()
+
++ |
+
+Method Summary | +|
---|---|
+static LuaValue |
+coerce(java.lang.Object o)
+
++ Coerse a Java object to a corresponding lua value. |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Constructor Detail | +
---|
+public CoerceJavaToLua()+
+Method Detail | +
---|
+public static LuaValue coerce(java.lang.Object o)+
+ Integral types boolean
, byte
, char
, and int
+ will become LuaInteger
;
+ long
, float
, and double
will become LuaDouble
;
+ String
and byte[]
will become LuaString
;
+ other types will become LuaUserdata
.
+
+
o
- Java object needing conversion
+LuaValue
corresponding to the supplied Java value.LuaValue
,
+LuaInteger
,
+LuaDouble
,
+LuaString
,
+LuaUserdata
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.lib.jse.CoerceLuaToJava ++
public class CoerceLuaToJava
+Helper class to coerce values from lua to Java within the luajava library. +
+ This class is primarily used by the LuajavaLib
,
+ but can also be used directly when working with Java/lua bindings.
+
+ To coerce to specific Java values, generally the toType()
methods
+ on LuaValue
may be used:
+
LuaValue.toboolean()
LuaValue.tobyte()
LuaValue.tochar()
LuaValue.toshort()
LuaValue.toint()
LuaValue.tofloat()
LuaValue.todouble()
LuaValue.tojstring()
LuaValue.touserdata()
LuaValue.touserdata(Class)
+ For data in lua tables, the various methods on LuaTable
can be used directly
+ to convert data to something more useful.
+
+ +
+
LuajavaLib
,
+CoerceJavaToLua
+Constructor Summary | +|
---|---|
CoerceLuaToJava()
+
++ |
+
+Method Summary | +|
---|---|
+static java.lang.Object |
+coerce(LuaValue value,
+ java.lang.Class clazz)
+
++ Coerce a LuaValue value to a specified java class |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Constructor Detail | +
---|
+public CoerceLuaToJava()+
+Method Detail | +
---|
+public static java.lang.Object coerce(LuaValue value, + java.lang.Class clazz)+
+
value
- LuaValue to coerceclazz
- Class to coerce into
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.OneArgFunction + org.luaj.vm2.lib.BaseLib + org.luaj.vm2.lib.jse.JseBaseLib ++
public class JseBaseLib
+Subclass of BaseLib
and LibFunction
which implements the lua basic library functions
+ and provides a directory based ResourceFinder
as the BaseLib.FINDER
.
+
+ Since JME has no file system by default, BaseLib
implements
+ ResourceFinder
using Class.getResource(String)
.
+ The JseBaseLib
implements FINDER
by scanning the current directory
+ first, then falling back to Class.getResource(String)
if that fails.
+ Otherwise, the behavior is the same as that of BaseLib
.
+
+ Typically, this library is included as part of a call to
+ JsePlatform.standardGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ LuaThread.setGlobals(_G);
+ _G.load(new JseBaseLib());
+ _G.get("print").call(LuaValue.valueOf("hello, world"));
+
+ Doing so will ensure the library is properly initialized
+ and loaded into the globals table.
+ + This is a direct port of the corresponding library in C. +
+ +
+
BaseLib
,
+ResourceFinder
,
+BaseLib.FINDER
,
+LibFunction
,
+JsePlatform
,
+JmePlatform
,
+http://www.lua.org/manual/5.1/manual.html#5.1+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.lib.BaseLib | +
---|
FINDER, instance, STDERR, STDIN, STDOUT |
+
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
JseBaseLib()
+
++ Construct a JSE base library instance |
+
+Method Summary | +|
---|---|
+ java.io.InputStream |
+findResource(java.lang.String filename)
+
++ Try to open a file in the current working directory, + or fall back to base opener if not found. |
+
Methods inherited from class org.luaj.vm2.lib.BaseLib | +
---|
call, loadFile, loadStream, pcall |
+
Methods inherited from class org.luaj.vm2.lib.OneArgFunction | +
---|
call, call, call, invoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JseBaseLib()+
+
+Method Detail | +
---|
+public java.io.InputStream findResource(java.lang.String filename)+
+
findResource
in interface ResourceFinder
findResource
in class BaseLib
filename
-
+BaseLib
,
+ResourceFinder
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.OneArgFunction + org.luaj.vm2.lib.IoLib + org.luaj.vm2.lib.jse.JseIoLib ++
public class JseIoLib
+Subclass of IoLib
and therefore LibFunction
which implements the lua standard io
+ library for the JSE platform.
+
+ It uses RandomAccessFile to implement seek on files. +
+ Typically, this library is included as part of a call to
+ JsePlatform.standardGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ LuaThread.setGlobals(_G);
+ _G.load(new JseBaseLib());
+ _G.load(new PackageLib());
+ _G.load(new JseIoLib());
+ _G.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
+
+ Doing so will ensure the library is properly initialized
+ and loaded into the globals table.
+ + This has been implemented to match as closely as possible the behavior in the corresponding library in C. +
+ +
+
LibFunction
,
+JsePlatform
,
+JmePlatform
,
+IoLib
,
+JmeIoLib
,
+http://www.lua.org/manual/5.1/manual.html#5.7+Nested Class Summary | +
---|
Nested classes/interfaces inherited from class org.luaj.vm2.lib.IoLib | +
---|
IoLib.File |
+
+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.lib.IoLib | +
---|
FILE_NAMES, IO_NAMES |
+
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
JseIoLib()
+
++ |
+
+Method Summary | +|
---|---|
+protected IoLib.File |
+openFile(java.lang.String filename,
+ boolean readMode,
+ boolean appendMode,
+ boolean updateMode,
+ boolean binaryMode)
+
++ Open a file in a particular mode. |
+
+protected IoLib.File |
+openProgram(java.lang.String prog,
+ java.lang.String mode)
+
++ Start a new process and return a file for input or output |
+
+protected IoLib.File |
+tmpFile()
+
++ Open a temporary file. |
+
+protected IoLib.File |
+wrapStdin()
+
++ Wrap the standard input. |
+
+protected IoLib.File |
+wrapStdout()
+
++ Wrap the standard output. |
+
Methods inherited from class org.luaj.vm2.lib.IoLib | +
---|
_file_close, _file_flush, _file_lines, _file_read, _file_seek, _file_setvbuf, _file_write, _io_close, _io_flush, _io_index, _io_input, _io_lines, _io_open, _io_output, _io_popen, _io_read, _io_tmpfile, _io_type, _io_write, _lines_iter, call, freadall, freadbytes, freadline, freadnumber, freaduntil |
+
Methods inherited from class org.luaj.vm2.lib.OneArgFunction | +
---|
call, call, call, invoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JseIoLib()+
+Method Detail | +
---|
+protected IoLib.File wrapStdin() + throws java.io.IOException+
IoLib
+
wrapStdin
in class IoLib
java.io.IOException
+protected IoLib.File wrapStdout() + throws java.io.IOException+
IoLib
+
wrapStdout
in class IoLib
java.io.IOException
+protected IoLib.File openFile(java.lang.String filename, + boolean readMode, + boolean appendMode, + boolean updateMode, + boolean binaryMode) + throws java.io.IOException+
IoLib
+
openFile
in class IoLib
readMode
- true if opening in read modeappendMode
- true if opening in append modeupdateMode
- true if opening in update modebinaryMode
- true if opening in binary mode
+java.io.IOException
- if could not be opened+protected IoLib.File openProgram(java.lang.String prog, + java.lang.String mode) + throws java.io.IOException+
IoLib
+
openProgram
in class IoLib
prog
- the program to executemode
- "r" to read, "w" to write
+java.io.IOException
- if an i/o exception occurs+protected IoLib.File tmpFile() + throws java.io.IOException+
IoLib
+
tmpFile
in class IoLib
java.io.IOException
- if could not be opened
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.OneArgFunction + org.luaj.vm2.lib.jse.JseMathLib.JseMathLib1 ++
public static final class JseMathLib.JseMathLib1
+
+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
JseMathLib.JseMathLib1()
+
++ |
+
+Method Summary | +|
---|---|
+ LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
Methods inherited from class org.luaj.vm2.lib.OneArgFunction | +
---|
call, call, call, invoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JseMathLib.JseMathLib1()+
+Method Detail | +
---|
+public LuaValue call(LuaValue arg)+
LuaValue
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class OneArgFunction
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+LuaValue.method(String,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue)
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.TwoArgFunction + org.luaj.vm2.lib.jse.JseMathLib.JseMathLib2 ++
public static final class JseMathLib.JseMathLib2
+
+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
JseMathLib.JseMathLib2()
+
++ |
+
+Method Summary | +|
---|---|
+ LuaValue |
+call(LuaValue arg1,
+ LuaValue arg2)
+
++ Call this with 2 arguments, including metatag processing,
+ and return only the first return value. |
+
Methods inherited from class org.luaj.vm2.lib.TwoArgFunction | +
---|
call, call, call, invoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JseMathLib.JseMathLib2()+
+Method Detail | +
---|
+public LuaValue call(LuaValue arg1, + LuaValue arg2)+
LuaValue
this
with 2 arguments, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class TwoArgFunction
arg1
- First argument to supply to the called functionarg2
- Second argument to supply to the called function
+(this(arg1,arg2))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue,LuaValue)
,
+LuaValue.method(String,LuaValue,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue,LuaValue)
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.OneArgFunction + org.luaj.vm2.lib.MathLib + org.luaj.vm2.lib.jse.JseMathLib ++
public class JseMathLib
+Subclass of LibFunction
which implements the lua standard math
+ library.
+
+ It contains all lua math functions, including those not available on the JME platform.
+ See org.luaj.lib.MathLib
for the exception list.
+
+ Typically, this library is included as part of a call to
+ JsePlatform.standardGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ LuaThread.setGlobals(_G);
+ _G.load(new JseBaseLib());
+ _G.load(new PackageLib());
+ _G.load(new JseMathLib());
+ System.out.println( _G.get("math").get("sqrt").call( LuaValue.valueOf(2) ) );
+
+ Doing so will ensure the library is properly initialized
+ and loaded into the globals table.
+ + This has been implemented to match as closely as possible the behavior in the corresponding library in C. +
+ +
+
LibFunction
,
+JsePlatform
,
+JmePlatform
,
+JseMathLib
,
+http://www.lua.org/manual/5.1/manual.html#5.6+Nested Class Summary | +|
---|---|
+static class |
+JseMathLib.JseMathLib1
+
++ |
+
+static class |
+JseMathLib.JseMathLib2
+
++ |
+
+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.lib.MathLib | +
---|
MATHLIB |
+
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
JseMathLib()
+
++ |
+
+Method Summary | +|
---|---|
+ LuaValue |
+call(LuaValue arg)
+
++ Call this with 1 argument, including metatag processing,
+ and return only the first return value. |
+
+ double |
+dpow_lib(double a,
+ double b)
+
++ Faster, better version of pow() used by arithmetic operator ^ |
+
Methods inherited from class org.luaj.vm2.lib.MathLib | +
---|
dpow_d, dpow_default, dpow |
+
Methods inherited from class org.luaj.vm2.lib.OneArgFunction | +
---|
call, call, call, invoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JseMathLib()+
+Method Detail | +
---|
+public LuaValue call(LuaValue arg)+
LuaValue
this
with 1 argument, including metatag processing,
+ and return only the first return value.
+
+ If this
is a LuaFunction
, call it,
+ and return only its first return value, dropping any others.
+ Otherwise, look for the CALL
metatag and call that.
+
+ If the return value is a Varargs
, only the 1st value will be returned.
+ To get multiple values, use LuaValue.invoke()
instead.
+
+ To call this
as a method call, use LuaValue.method(LuaValue)
instead.
+
+
call
in class MathLib
arg
- First argument to supply to the called function
+(this(arg))
, or NIL
if there were none.LuaValue.call()
,
+LuaValue.call(LuaValue,LuaValue)
,
+LuaValue.call(LuaValue, LuaValue, LuaValue)
,
+#invoke(LuaValue)
,
+LuaValue.method(String,LuaValue)
,
+LuaValue.method(LuaValue,LuaValue)
+public double dpow_lib(double a, + double b)+
+
dpow_lib
in class MathLib
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.VarArgFunction + org.luaj.vm2.lib.OsLib + org.luaj.vm2.lib.jse.JseOsLib ++
public class JseOsLib
+Subclass of LibFunction
which implements the standard lua os
library.
+
+ This contains more complete implementations of the following functions + using features that are specific to JSE: +
execute()
remove()
rename()
tmpname()
+ Because the nature of the os
library is to encapsulate
+ os-specific features, the behavior of these functions varies considerably
+ from their counterparts in the C platform.
+
+ Typically, this library is included as part of a call to either
+ JsePlatform.standardGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ LuaThread.setGlobals(_G);
+ _G.load(new JseBaseLib());
+ _G.load(new PackageLib());
+ _G.load(new JseOsLib());
+ System.out.println( _G.get("os").get("time").call() );
+
+ Doing so will ensure the library is properly initialized
+ and loaded into the globals table.
+ +
+ +
+
LibFunction
,
+OsLib
,
+JsePlatform
,
+JmePlatform
,
+http://www.lua.org/manual/5.1/manual.html#5.8+Field Summary | +|
---|---|
+static int |
+EXEC_ERROR
+
++ return code indicating the execute() threw an unknown exception |
+
+static int |
+EXEC_INTERRUPTED
+
++ return code indicating the execute() was interrupted |
+
+static int |
+EXEC_IOEXCEPTION
+
++ return code indicating the execute() threw an I/O exception |
+
Fields inherited from class org.luaj.vm2.lib.OsLib | +
---|
TMP_PREFIX, TMP_SUFFIX |
+
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
JseOsLib()
+
++ public constructor |
+
+Method Summary | +|
---|---|
+protected int |
+execute(java.lang.String command)
+
++ This function is equivalent to the C function system. |
+
+protected void |
+remove(java.lang.String filename)
+
++ Deletes the file or directory with the given name. |
+
+protected void |
+rename(java.lang.String oldname,
+ java.lang.String newname)
+
++ Renames file or directory named oldname to newname. |
+
+protected java.lang.String |
+tmpname()
+
++ Returns a string with a file name that can be used for a temporary file. |
+
Methods inherited from class org.luaj.vm2.lib.OsLib | +
---|
clock, date, difftime, exit, getenv, init, invoke, setlocale, time |
+
Methods inherited from class org.luaj.vm2.lib.VarArgFunction | +
---|
call, call, call, call, onInvoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Field Detail | +
---|
+public static int EXEC_IOEXCEPTION+
+
+public static int EXEC_INTERRUPTED+
+
+public static int EXEC_ERROR+
+
+Constructor Detail | +
---|
+public JseOsLib()+
+
+Method Detail | +
---|
+protected int execute(java.lang.String command)+
OsLib
+
execute
in class OsLib
command
- command to pass to the system+protected void remove(java.lang.String filename) + throws java.io.IOException+
OsLib
+
remove
in class OsLib
java.io.IOException
- if it fails+protected void rename(java.lang.String oldname, + java.lang.String newname) + throws java.io.IOException+
OsLib
+
rename
in class OsLib
oldname
- old file namenewname
- new file name
+java.io.IOException
- if it fails+protected java.lang.String tmpname()+
OsLib
+
tmpname
in class OsLib
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.lib.jse.JsePlatform ++
public class JsePlatform
+The JsePlatform
class is a convenience class to standardize
+ how globals tables are initialized for the JSE platform.
+
+ It is used to allocate either a set of standard globals using
+ standardGlobals()
or debug globals using debugGlobals()
+
+ A simple example of initializing globals and using them from Java is: +
LuaValue _G = JsePlatform.standardGlobals();
+ _G.get("print").call(LuaValue.valueOf("hello, world"));
+
+ + Once globals are created, a simple way to load and run a script is: +
LoadState.load( new FileInputStream("main.lua"), "main.lua", _G ).call();
+
+
+ although require
could also be used:
+
_G.get("require").call(LuaValue.valueOf("main"));
+
+ For this to succeed, the file "main.lua" must be in the current directory or a resource.
+ See JseBaseLib
for details on finding scripts using ResourceFinder
.
+
+ The standard globals will contain all standard libraries plus luajava
:
+
JseBaseLib
PackageLib
TableLib
StringLib
CoroutineLib
JseMathLib
JseIoLib
JseOsLib
LuajavaLib
LuaC
compiler is installed so lua files may be loaded in their source form.
+
+ The debug globals are simply the standard globals plus the debug
library DebugLib
.
+
+ The class ensures that initialization is done in the correct order,
+ and that linkage is made to LuaThread.setGlobals(LuaValue)
.
+
+ +
+
JmePlatform
+Constructor Summary | +|
---|---|
JsePlatform()
+
++ |
+
+Method Summary | +|
---|---|
+static LuaTable |
+debugGlobals()
+
++ Create standard globals including the debug library. |
+
+static LuaTable |
+standardGlobals()
+
++ Create a standard set of globals for JSE including all the libraries. |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JsePlatform()+
+Method Detail | +
---|
+public static LuaTable standardGlobals()+
+
debugGlobals()
,
+JsePlatform
,
+JmePlatform
+public static LuaTable debugGlobals()+
debug
library.
++
standardGlobals()
,
+JsePlatform
,
+JmePlatform
,
+DebugLib
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.lib.jse.JseProcess ++
public class JseProcess
+Analog of Process that pipes input and output to client-specified streams. +
+ +
+
+Constructor Summary | +|
---|---|
JseProcess(java.lang.String[] cmd,
+ java.io.InputStream stdin,
+ java.io.OutputStream stdout,
+ java.io.OutputStream stderr)
+
++ Construct a process around a command, with specified streams to redirect input and output to. |
+|
JseProcess(java.lang.String cmd,
+ java.io.InputStream stdin,
+ java.io.OutputStream stdout,
+ java.io.OutputStream stderr)
+
++ Construct a process around a command, with specified streams to redirect input and output to. |
+
+Method Summary | +|
---|---|
+ int |
+exitValue()
+
++ Get the exit value of the process. |
+
+ int |
+waitFor()
+
++ Wait for the process to complete, and all pending output to finish. |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JseProcess(java.lang.String[] cmd, + java.io.InputStream stdin, + java.io.OutputStream stdout, + java.io.OutputStream stderr) + throws java.io.IOException+
+
cmd
- The command to execute, including arguments, if anystdin
- Optional InputStream to read from as process input, or null if input is not needed.stdout
- Optional OutputStream to copy process output to, or null if output is ignored.stderr
- Optinoal OutputStream to copy process stderr output to, or null if output is ignored.
+java.io.IOException
- If the system process could not be created.Process
+public JseProcess(java.lang.String cmd, + java.io.InputStream stdin, + java.io.OutputStream stdout, + java.io.OutputStream stderr) + throws java.io.IOException+
+
cmd
- The command to execute, including arguments, if anystdin
- Optional InputStream to read from as process input, or null if input is not needed.stdout
- Optional OutputStream to copy process output to, or null if output is ignored.stderr
- Optinoal OutputStream to copy process stderr output to, or null if output is ignored.
+java.io.IOException
- If the system process could not be created.Process
+Method Detail | +
---|
+public int exitValue()+
+
+public int waitFor() + throws java.lang.InterruptedException+
+
java.lang.InterruptedException
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.Varargs + org.luaj.vm2.LuaValue + org.luaj.vm2.LuaFunction + org.luaj.vm2.lib.LibFunction + org.luaj.vm2.lib.VarArgFunction + org.luaj.vm2.lib.jse.LuajavaLib ++
public class LuajavaLib
+Subclass of LibFunction
which implements the features of the luajava package.
+
+ Luajava is an approach to mixing lua and java using simple functions that bind + java classes and methods to lua dynamically. The API is documented on the + luajava documentation pages. +
+ Typically, this library is included as part of a call to either
+ JsePlatform.standardGlobals()
+
+ To instantiate and use it directly,
+ link it into your globals table via LuaValue.load(LuaValue)
using code such as:
+
LuaTable _G = new LuaTable();
+ LuaThread.setGlobals(_G);
+ LuaC.install();
+ _G.load(new BaseLib());
+ _G.load(new PackageLib());
+ _G.load(new LuajavaLib());
+ _G.get("loadstring").call( LuaValue.valueOf(
+ "sys = luajava.bindClass('java.lang.System')\n"+
+ "print ( sys:currentTimeMillis() )\n" ) ).call();
+
+ This example is not intended to be realistic - only to show how the LuajavaLib
+ may be initialized by hand. In practice, the luajava
library is available
+ on all JSE platforms via the call to JsePlatform.standardGlobals()
+ and the luajava api's are simply invoked from lua.
+ + This has been implemented to match as closely as possible the behavior in the corresponding library in C. +
+ +
+
LibFunction
,
+JsePlatform
,
+JmePlatform
,
+LuaC
,
+http://www.keplerproject.org/luajava/manual.html#luareference+Field Summary | +
---|
Fields inherited from class org.luaj.vm2.lib.LibFunction | +
---|
name, opcode |
+
Fields inherited from class org.luaj.vm2.LuaFunction | +
---|
env, s_metatable |
+
Fields inherited from class org.luaj.vm2.LuaValue | +
---|
ADD, CALL, CONCAT, DIV, EMPTYSTRING, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO |
+
+Constructor Summary | +|
---|---|
LuajavaLib()
+
++ |
+
+Method Summary | +|
---|---|
+protected java.lang.Class |
+classForName(java.lang.String name)
+
++ |
+
+ Varargs |
+invoke(Varargs args)
+
++ Override and implement for the best performance. |
+
Methods inherited from class org.luaj.vm2.lib.VarArgFunction | +
---|
call, call, call, call, onInvoke |
+
Methods inherited from class org.luaj.vm2.lib.LibFunction | +
---|
bind, bind, newupe, newupl, newupn, tojstring |
+
Methods inherited from class org.luaj.vm2.LuaFunction | +
---|
checkfunction, getfenv, getmetatable, isfunction, optfunction, setfenv, type, typename |
+
Methods inherited from class org.luaj.vm2.Varargs | +
---|
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, subargs, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type |
+
Methods inherited from class java.lang.Object | +
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public LuajavaLib()+
+Method Detail | +
---|
+public Varargs invoke(Varargs args)+
VarArgFunction
+
invoke
in class VarArgFunction
args
- the arguments to the function call.
+Varargs
instance.LuaValue.varargsOf(LuaValue[])
,
+LuaValue.call(LuaValue)
,
+LuaValue.invoke()
,
+LuaValue.invoke(LuaValue,Varargs)
,
+LuaValue.invokemethod(String,Varargs)
,
+LuaValue.invokemethod(LuaValue,Varargs)
+protected java.lang.Class classForName(java.lang.String name) + throws java.lang.ClassNotFoundException+
java.lang.ClassNotFoundException
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Classes
+
+ +CoerceJavaToLua + +CoerceLuaToJava + +JseBaseLib + +JseIoLib + +JseMathLib + +JseMathLib.JseMathLib1 + +JseMathLib.JseMathLib2 + +JseOsLib + +JsePlatform + +JseProcess + +LuajavaLib |
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+Class Summary | +|
---|---|
CoerceJavaToLua | +Helper class to coerce values from Java to lua within the luajava library. | +
CoerceLuaToJava | +Helper class to coerce values from lua to Java within the luajava library. | +
JseBaseLib | +Subclass of BaseLib and LibFunction which implements the lua basic library functions
+ and provides a directory based ResourceFinder as the BaseLib.FINDER . |
+
JseIoLib | +Subclass of IoLib and therefore LibFunction which implements the lua standard io
+ library for the JSE platform. |
+
JseMathLib | +Subclass of LibFunction which implements the lua standard math
+ library. |
+
JseMathLib.JseMathLib1 | ++ |
JseMathLib.JseMathLib2 | ++ |
JseOsLib | +Subclass of LibFunction which implements the standard lua os library. |
+
JsePlatform | +The JsePlatform class is a convenience class to standardize
+ how globals tables are initialized for the JSE platform. |
+
JseProcess | +Analog of Process that pipes input and output to client-specified streams. | +
LuajavaLib | +Subclass of LibFunction which implements the features of the luajava package. |
+
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Interfaces
+
+ +ResourceFinder |
+
+Classes
+
+ +BaseLib + +CoroutineLib + +DebugLib + +IoLib + +LibFunction + +MathLib + +OneArgFunction + +OsLib + +PackageLib + +StringLib + +TableLib + +ThreeArgFunction + +TwoArgFunction + +VarArgFunction + +ZeroArgFunction |
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+Interface Summary | +|
---|---|
ResourceFinder | +Interface for opening application resource files such as scripts sources. | +
+ +
+Class Summary | +|
---|---|
BaseLib | +Subclass of LibFunction which implements the lua basic library functions. |
+
CoroutineLib | +Subclass of LibFunction which implements the lua standard coroutine
+ library. |
+
DebugLib | +Subclass of LibFunction which implements the lua standard debug
+ library. |
+
IoLib | +Abstract base class extending LibFunction which implements the
+ core of the lua standard io library. |
+
LibFunction | +Subclass of LuaFunction common to Java functions exposed to lua. |
+
MathLib | +Subclass of LibFunction which implements the lua standard math
+ library. |
+
OneArgFunction | +Abstract base class for Java function implementations that take one argument and + return one value. | +
OsLib | +Subclass of LibFunction which implements the standard lua os library. |
+
PackageLib | +Subclass of LibFunction which implements the lua standard package and module
+ library functions. |
+
StringLib | +Subclass of LibFunction which implements the lua standard string
+ library. |
+
TableLib | +Subclass of LibFunction which implements the lua standard table
+ library. |
+
ThreeArgFunction | +Abstract base class for Java function implementations that take two arguments and + return one value. | +
TwoArgFunction | +Abstract base class for Java function implementations that take two arguments and + return one value. | +
VarArgFunction | +Abstract base class for Java function implementations that takes varaiable arguments and + returns multiple return values. | +
ZeroArgFunction | +Abstract base class for Java function implementations that take no arguments and + return one value. | +
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use org.luaj.vm2.lib | +|
---|---|
org.luaj.vm2.lib | ++ |
org.luaj.vm2.lib.jme | ++ |
org.luaj.vm2.lib.jse | ++ |
+Classes in org.luaj.vm2.lib used by org.luaj.vm2.lib | +|
---|---|
BaseLib
+
+ + Subclass of LibFunction which implements the lua basic library functions. |
+|
IoLib.File
+
+ + |
+|
LibFunction
+
+ + Subclass of LuaFunction common to Java functions exposed to lua. |
+|
MathLib
+
+ + Subclass of LibFunction which implements the lua standard math
+ library. |
+|
OneArgFunction
+
+ + Abstract base class for Java function implementations that take one argument and + return one value. |
+|
PackageLib
+
+ + Subclass of LibFunction which implements the lua standard package and module
+ library functions. |
+|
ResourceFinder
+
+ + Interface for opening application resource files such as scripts sources. |
+|
VarArgFunction
+
+ + Abstract base class for Java function implementations that takes varaiable arguments and + returns multiple return values. |
+
+Classes in org.luaj.vm2.lib used by org.luaj.vm2.lib.jme | +|
---|---|
IoLib
+
+ + Abstract base class extending LibFunction which implements the
+ core of the lua standard io library. |
+|
IoLib.File
+
+ + |
+|
LibFunction
+
+ + Subclass of LuaFunction common to Java functions exposed to lua. |
+|
OneArgFunction
+
+ + Abstract base class for Java function implementations that take one argument and + return one value. |
+
+Classes in org.luaj.vm2.lib used by org.luaj.vm2.lib.jse | +|
---|---|
BaseLib
+
+ + Subclass of LibFunction which implements the lua basic library functions. |
+|
IoLib
+
+ + Abstract base class extending LibFunction which implements the
+ core of the lua standard io library. |
+|
IoLib.File
+
+ + |
+|
LibFunction
+
+ + Subclass of LuaFunction common to Java functions exposed to lua. |
+|
MathLib
+
+ + Subclass of LibFunction which implements the lua standard math
+ library. |
+|
OneArgFunction
+
+ + Abstract base class for Java function implementations that take one argument and + return one value. |
+|
OsLib
+
+ + Subclass of LibFunction which implements the standard lua os library. |
+|
ResourceFinder
+
+ + Interface for opening application resource files such as scripts sources. |
+|
TwoArgFunction
+
+ + Abstract base class for Java function implementations that take two arguments and + return one value. |
+|
VarArgFunction
+
+ + Abstract base class for Java function implementations that takes varaiable arguments and + returns multiple return values. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + org.luaj.vm2.luajc.LuaJC ++
public class LuaJC
+Implementation of LoadState.LuaCompiler
which does direct
+ lua-to-java-bytecode compiling.
+
+ This requires the bcel library to be on the class path to work as expected.
+ If the library is not found, the default LuaC
lua-to-lua-bytecode
+ compiler will be used.
+
+ The compiler should be installed as part of globals initialization, + and before any scripts or lua code is executed. + A typical example is to install it following the globals creation, + as in the following: +
LuaValue _G = JsePlatform.standardGlobals();
+ LuaJC.install();
+ LoadState.load( new ByteArrayInputStream("print 'hello'".getBytes()), "main.lua", _G ).call();
+
++ +
+
LoadState.LuaCompiler
,
+LuaC
,
+JsePlatform
,
+JmePlatform
,
+BaseLib
,
+LuaValue
+Constructor Summary | +|
---|---|
LuaJC()
+
++ |
+
+Method Summary | +|
---|---|
+ java.util.Hashtable |
+compileAll(java.io.InputStream script,
+ java.lang.String chunkname,
+ java.lang.String filename)
+
++ |
+
+static LuaJC |
+getInstance()
+
++ |
+
+static void |
+install()
+
++ Install the compiler as the main compiler to use. |
+
+ LuaFunction |
+load(java.io.InputStream stream,
+ java.lang.String name,
+ LuaValue env)
+
++ Load into a Closure or LuaFunction from a Stream and initializes the environment |
+
Methods inherited from class java.lang.Object | +
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Constructor Detail | +
---|
+public LuaJC()+
+Method Detail | +
---|
+public static LuaJC getInstance()+
+public static final void install()+
+
+public java.util.Hashtable compileAll(java.io.InputStream script, + java.lang.String chunkname, + java.lang.String filename) + throws java.io.IOException+
java.io.IOException
+public LuaFunction load(java.io.InputStream stream, + java.lang.String name, + LuaValue env) + throws java.io.IOException+
LoadState.LuaCompiler
+
load
in interface LoadState.LuaCompiler
java.io.IOException
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LuaJC | +|
---|---|
org.luaj.vm2.luajc | ++ |
+Uses of LuaJC in org.luaj.vm2.luajc | +
---|
+ +
Methods in org.luaj.vm2.luajc that return LuaJC | +|
---|---|
+static LuaJC |
+LuaJC.getInstance()
+
++ |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Classes
+
+ +LuaJC |
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+Class Summary | +|
---|---|
LuaJC | +Implementation of LoadState.LuaCompiler which does direct
+ lua-to-java-bytecode compiling. |
+
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use org.luaj.vm2.luajc | +|
---|---|
org.luaj.vm2.luajc | ++ |
+Classes in org.luaj.vm2.luajc used by org.luaj.vm2.luajc | +|
---|---|
LuaJC
+
+ + Implementation of LoadState.LuaCompiler which does direct
+ lua-to-java-bytecode compiling. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Interfaces
+
+ +LoadState.LuaCompiler |
+
+Classes
+
+ +Buffer + +LoadState + +LocVars + +Lua + +LuaBoolean + +LuaClosure + +LuaDouble + +LuaFunction + +LuaInteger + +LuaNil + +LuaNumber + +LuaString + +LuaTable + +LuaThread + +LuaThread.CallStack + +LuaUserdata + +LuaValue + +Print + +Prototype + +TailcallVarargs + +UpValue + +Varargs + +WeakTable |
+
+Exceptions
+
+ +LuaError |
+
+Errors
+
+ +OrphanedThread |
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+Interface Summary | +|
---|---|
LoadState.LuaCompiler | +Interface for the compiler, if it is installed. | +
+ +
+Class Summary | +|
---|---|
Buffer | +String buffer for use in string library methods, optimized for production + of StrValue instances. | +
LoadState | +Class to manage loading of Prototype instances. |
+
LocVars | +Data class to hold debug information relatign to local variables for a Prototype |
+
Lua | +Constants for lua limits and opcodes. | +
LuaBoolean | +Extension of LuaValue which can hold a Java boolean as its value. |
+
LuaClosure | +Extension of LuaFunction which executes lua bytecode. |
+
LuaDouble | +Extension of LuaNumber which can hold a Java double as its value. |
+
LuaFunction | +Base class for functions implemented in Java. | +
LuaInteger | +Extension of LuaNumber which can hold a Java int as its value. |
+
LuaNil | +Class to encapsulate behavior of the singleton instance nil |
+
LuaNumber | +Base class for representing numbers as lua values directly. | +
LuaString | +Subclass of LuaValue for representing lua strings. |
+
LuaTable | +Subclass of LuaValue for representing lua tables. |
+
LuaThread | +Subclass of LuaValue that implements
+ a lua coroutine thread using Java Threads. |
+
LuaThread.CallStack | ++ |
LuaUserdata | ++ |
LuaValue | +Base class for all concrete lua type values. | +
Debug helper class to pretty-print lua bytecodes. | +|
Prototype | +Prototype representing compiled lua code. | +
TailcallVarargs | +Subclass of Varargs that represents a lua tail call
+ in a Java library function execution environment. |
+
UpValue | +Upvalue used with Closure formulation | +
Varargs | +Class to encapsulate varargs values, either as part of a variable argument list, or multiple return values. | +
WeakTable | +Subclass of LuaTable that provides weak key and weak value semantics. |
+
+ +
+Exception Summary | +|
---|---|
LuaError | +RuntimeException that is thrown and caught in response to a lua error. | +
+ +
+Error Summary | +|
---|---|
OrphanedThread | +Error sublcass that indicates a lua thread that is no
+ longer referenced has been detected. |
+
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use org.luaj.vm2 | +|
---|---|
org.luaj.vm2 | ++ |
org.luaj.vm2.compiler | ++ |
org.luaj.vm2.lib | ++ |
org.luaj.vm2.lib.jme | ++ |
org.luaj.vm2.lib.jse | ++ |
org.luaj.vm2.luajc | ++ |
+Classes in org.luaj.vm2 used by org.luaj.vm2 | +|
---|---|
Buffer
+
+ + String buffer for use in string library methods, optimized for production + of StrValue instances. |
+|
LoadState.LuaCompiler
+
+ + Interface for the compiler, if it is installed. |
+|
LocVars
+
+ + Data class to hold debug information relatign to local variables for a Prototype |
+|
Lua
+
+ + Constants for lua limits and opcodes. |
+|
LuaBoolean
+
+ + Extension of LuaValue which can hold a Java boolean as its value. |
+|
LuaClosure
+
+ + Extension of LuaFunction which executes lua bytecode. |
+|
LuaDouble
+
+ + Extension of LuaNumber which can hold a Java double as its value. |
+|
LuaFunction
+
+ + Base class for functions implemented in Java. |
+|
LuaInteger
+
+ + Extension of LuaNumber which can hold a Java int as its value. |
+|
LuaNumber
+
+ + Base class for representing numbers as lua values directly. |
+|
LuaString
+
+ + Subclass of LuaValue for representing lua strings. |
+|
LuaTable
+
+ + Subclass of LuaValue for representing lua tables. |
+|
LuaThread
+
+ + Subclass of LuaValue that implements
+ a lua coroutine thread using Java Threads. |
+|
LuaThread.CallStack
+
+ + |
+|
LuaUserdata
+
+ + |
+|
LuaValue
+
+ + Base class for all concrete lua type values. |
+|
Prototype
+
+ + Prototype representing compiled lua code. |
+|
UpValue
+
+ + Upvalue used with Closure formulation |
+|
Varargs
+
+ + Class to encapsulate varargs values, either as part of a variable argument list, or multiple return values. |
+
+Classes in org.luaj.vm2 used by org.luaj.vm2.compiler | +|
---|---|
LoadState.LuaCompiler
+
+ + Interface for the compiler, if it is installed. |
+|
Lua
+
+ + Constants for lua limits and opcodes. |
+|
LuaFunction
+
+ + Base class for functions implemented in Java. |
+|
LuaString
+
+ + Subclass of LuaValue for representing lua strings. |
+|
LuaValue
+
+ + Base class for all concrete lua type values. |
+|
Prototype
+
+ + Prototype representing compiled lua code. |
+
+Classes in org.luaj.vm2 used by org.luaj.vm2.lib | +|
---|---|
LuaFunction
+
+ + Base class for functions implemented in Java. |
+|
LuaString
+
+ + Subclass of LuaValue for representing lua strings. |
+|
LuaTable
+
+ + Subclass of LuaValue for representing lua tables. |
+|
LuaThread
+
+ + Subclass of LuaValue that implements
+ a lua coroutine thread using Java Threads. |
+|
LuaValue
+
+ + Base class for all concrete lua type values. |
+|
Prototype
+
+ + Prototype representing compiled lua code. |
+|
Varargs
+
+ + Class to encapsulate varargs values, either as part of a variable argument list, or multiple return values. |
+
+Classes in org.luaj.vm2 used by org.luaj.vm2.lib.jme | +|
---|---|
LuaFunction
+
+ + Base class for functions implemented in Java. |
+|
LuaTable
+
+ + Subclass of LuaValue for representing lua tables. |
+|
LuaValue
+
+ + Base class for all concrete lua type values. |
+|
Varargs
+
+ + Class to encapsulate varargs values, either as part of a variable argument list, or multiple return values. |
+
+Classes in org.luaj.vm2 used by org.luaj.vm2.lib.jse | +|
---|---|
LuaFunction
+
+ + Base class for functions implemented in Java. |
+|
LuaTable
+
+ + Subclass of LuaValue for representing lua tables. |
+|
LuaValue
+
+ + Base class for all concrete lua type values. |
+|
Varargs
+
+ + Class to encapsulate varargs values, either as part of a variable argument list, or multiple return values. |
+
+Classes in org.luaj.vm2 used by org.luaj.vm2.luajc | +|
---|---|
LoadState.LuaCompiler
+
+ + Interface for the compiler, if it is installed. |
+|
LuaFunction
+
+ + Base class for functions implemented in Java. |
+|
LuaValue
+
+ + Base class for all concrete lua type values. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+ | +
---|
All Classes
+
+
+Packages
+ |
+
+ + + diff --git a/luaj-2.0.3/docs/api/overview-summary.html b/luaj-2.0.3/docs/api/overview-summary.html new file mode 100644 index 0000000000..467df1d20b --- /dev/null +++ b/luaj-2.0.3/docs/api/overview-summary.html @@ -0,0 +1,176 @@ + + + +
+ +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Other Packages | +|
---|---|
org.luaj.vm2 | ++ |
org.luaj.vm2.compiler | ++ |
org.luaj.vm2.lib | ++ |
org.luaj.vm2.lib.jme | ++ |
org.luaj.vm2.lib.jse | ++ |
org.luaj.vm2.luajc | ++ |
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Package org.luaj.vm2 | +
---|
+Class org.luaj.vm2.LuaError extends java.lang.RuntimeException implements Serializable | +
---|
+serialVersionUID: 1L + +
+Serialized Fields | +
---|
+java.lang.String traceback+
+java.lang.Throwable cause+
+Class org.luaj.vm2.OrphanedThread extends java.lang.Error implements Serializable | +
---|
+ +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
{@code + * require 'hyperbolic' + * print('sinh', hyperbolic.sinh) + * print('sinh(1.0)', hyperbolic.sinh(1.0)) + * }+ * + * When require() loads the code, two things happen: 1) the public constructor + * is called to construct a library instance, and 2) the instance is invoked + * as a java call with no arguments. This invocation should be used to initialize + * the library, and add any values to globals that are desired. + */ +public class hyperbolic extends OneArgFunction { + + /** Public constructor. To be loaded via require(), the library class + * must have a public constructor. + */ + public hyperbolic() {} + + /** The implementation of the ZeroArgFunction interface. + * This will be called once when the library is loaded via require(). + * @param arg LuaString containing the name used in the call to require(). + * @return Value that will be returned in the require() call. In this case, + * it is the library itself. + */ + public LuaValue call(LuaValue libname) { + LuaValue library = tableOf(); + library.set( "sinh", new sinh() ); + library.set( "cosh", new cosh() ); + env.set( "hyperbolic", library ); + return library; + } + + /* Each library function is coded as a specific LibFunction based on the + * arguments it expects and returns. By using OneArgFunction, rather than + * LibFunction directly, the number of arguments supplied will be coerced + * to match what the implementation expects. */ + + /** Mathematical sinh function provided as a OneArgFunction. */ + static class sinh extends OneArgFunction { + public LuaValue call(LuaValue x) { + return LuaValue.valueOf(Math.sinh(x.checkdouble())); + } + } + + /** Mathematical cosh function provided as a OneArgFunction. */ + static class cosh extends OneArgFunction { + public LuaValue call(LuaValue x) { + return LuaValue.valueOf(Math.cosh(x.checkdouble())); + } + } +} \ No newline at end of file diff --git a/luaj-2.0.3/examples/lua/hello.lua b/luaj-2.0.3/examples/lua/hello.lua new file mode 100644 index 0000000000..5f66bcecea --- /dev/null +++ b/luaj-2.0.3/examples/lua/hello.lua @@ -0,0 +1 @@ +print( 'hello, world' ) \ No newline at end of file diff --git a/luaj-2.0.3/examples/lua/hyperbolicapp.lua b/luaj-2.0.3/examples/lua/hyperbolicapp.lua new file mode 100644 index 0000000000..ea10389af9 --- /dev/null +++ b/luaj-2.0.3/examples/lua/hyperbolicapp.lua @@ -0,0 +1,19 @@ +-- Sample luaj code to try loading and executing the 'hyperbolic' sample library +-- +-- The sample library source is in examples/jse/hyperbolic.java. +-- For this sample to work, that source must be compiled, and the class must +-- be on the class path. +-- +-- First load the library via require(). This will call the public constructor +-- for the class named 'hyperbolic' if it exists, and then initialize the +-- library by invoking LuaValue.call('hyperbolic') on that instance +require 'hyperbolic' + +-- Test that the table is in the globals, and the functions exist. +print('hyperbolic', hyperbolic) +print('hyperbolic.sinh', hyperbolic.sinh) +print('hyperbolic.cosh', hyperbolic.cosh) + +-- Try exercising the functions. +print('sinh(0.5)', hyperbolic.sinh(0.5)) +print('cosh(0.5)', hyperbolic.cosh(0.5)) diff --git a/luaj-2.0.3/examples/lua/logo.gif b/luaj-2.0.3/examples/lua/logo.gif new file mode 100644 index 0000000000..193e692084 Binary files /dev/null and b/luaj-2.0.3/examples/lua/logo.gif differ diff --git a/luaj-2.0.3/examples/lua/swingapp.lua b/luaj-2.0.3/examples/lua/swingapp.lua new file mode 100644 index 0000000000..2e1b6f0f03 --- /dev/null +++ b/luaj-2.0.3/examples/lua/swingapp.lua @@ -0,0 +1,132 @@ +-- Sample luaj program that presents an animated Swing window. +-- +-- This basic application handles key, and mouse input, has a basic animation loop, +-- and renders double-buffered graphics including the logo image in a swing frame. +-- + +-- bind to classes we need +local borderLayout = luajava.bindClass("java.awt.BorderLayout") +local jframe = luajava.bindClass("javax.swing.JFrame") +local bufferedImage = luajava.bindClass("java.awt.image.BufferedImage") +local swingUtilities = luajava.bindClass("javax.swing.SwingUtilities") +local thread = luajava.bindClass("java.lang.Thread") + +-- set up frame, get content pane +local frame = luajava.newInstance("javax.swing.JFrame", "Sample Luaj Application"); +local content = frame:getContentPane() + +-- add a buffered image as content +local image = luajava.newInstance("java.awt.image.BufferedImage", 640, 480, bufferedImage.TYPE_INT_RGB) +local icon = luajava.newInstance("javax.swing.ImageIcon", image) +local label = luajava.newInstance("javax.swing.JLabel", icon) + +-- add the main pane to the main content +content:add(label, borderLayout.CENTER) +frame:setDefaultCloseOperation(jframe.EXIT_ON_CLOSE) +frame:pack() + +-- simple animation framework +local tick,animate,render +local tnext = 0 +tick = luajava.createProxy("java.lang.Runnable", { + run = function() + swingUtilities:invokeLater(tick) + if os.time()< tnext then return thread:sleep(1) end + tnext = math.max(os.time(),tnext+1000/60) + pcall(animate) + pcall(render) + label:repaint(0,0,0,640,480) + end +}) + +-- the animation step moves the line endpoints +local x1,y1,x2,y2,xi,yi = 160,240,480,240,0,0 +local vx1,vy1,vx2,vy2,vxi,vyi = -5,-6,7,8,3,1 +local advance = function(x,vx,max,rnd) + x = x + vx + if x < 0 then + return 0, math.random(2,10) + elseif x > max then + return max, math.random(-10,-2) + end + return x, vx +end +animate = function() + x1,y1,x2,y2 = x1+1,y1+1,x2-1,y2-1 + x1,vx1 = advance(x1,vx1,640) + y1,vy1 = advance(y1,vy1,480) + x2,vx2 = advance(x2,vx2,640) + y2,vy2 = advance(y2,vy2,480) + xi,vxi = advance(xi,vxi,540) + yi,vyi = advance(yi,vyi,380) +end + +-- try loading the logo image from a couple locations +local imageio = luajava.bindClass("javax.imageio.ImageIO") +local file = luajava.bindClass("java.io.File") +local loadimage = function(path) + local s,i = pcall(imageio.read, imageio, luajava.new(file, path)) + return s and i +end +local logo = loadimage("logo.gif") or loadimage("examples/lua/logo.gif") + +-- the render step draws the scene +local g = image:getGraphics() +local bg = luajava.newInstance("java.awt.Color", 0x22112244, true); +local fg = luajava.newInstance("java.awt.Color", 0xffaa33); +render = function() + g:setColor(bg) + g:fillRect(0,0,640,480) + if logo then g:drawImage(logo,xi,yi) end + g:setColor(fg) + g:drawLine(x1,y1,x2,y2) +end + +-- add mouse listeners for specific mouse events +label:addMouseListener(luajava.createProxy("java.awt.event.MouseListener", { + mousePressed = function(e) + --print('mousePressed', e:getX(), e:getY(), e) + x1,y1 = e:getX(),e:getY() + end, + -- mouseClicked = function(e) end, + -- mouseEntered = function(e) end, + -- mouseExited = function(e) end, + -- mouseReleased = function(e) end, +})) +label:addMouseMotionListener(luajava.createProxy("java.awt.event.MouseMotionListener", { + mouseDragged = function(e) + --print('mouseDragged', e:getX(), e:getY(), e) + x2,y2 = e:getX(),e:getY() + end, + -- mouseMoved= function(e) end, +})) + +-- add key listeners +frame:addKeyListener(luajava.createProxy("java.awt.event.KeyListener", { + keyPressed = function(e) + local id, code, char, text = e:getID(), e:getKeyCode(), e:getKeyChar(), e:getKeyText(e:getKeyCode()) + print('key id, code, char, text, pcall(string.char,char)', id, code, char, text, pcall(string.char,char)) + end, + -- keyReleased = function(e) end, + -- keyTyped = function(e) end, +})) + +-- use the window listener to kick off animation +frame:addWindowListener(luajava.createProxy("java.awt.event.WindowListener", { + windowOpened = function(e) + swingUtilities:invokeLater(tick) + end, + -- windowActivated = function(e) end, + -- windowClosed = function(e) end, + -- windowClosing = function(e) end, + -- windowDeactivated = function(e) end, + -- windowDeiconified = function(e) end, + -- windowIconified = function(e) end, +})) + +-- utility function to load an image from a file, for reference +local loadimage = function(filename) +end + +-- Set window visible last to start app. +frame:setVisible(true) diff --git a/luaj-2.0.3/names.csv b/luaj-2.0.3/names.csv new file mode 100644 index 0000000000..5c6b8f8f1a --- /dev/null +++ b/luaj-2.0.3/names.csv @@ -0,0 +1,89 @@ +LuaValue Consructors,,Return type,,,,,,,,,, +,valueOf(boolean),LuaBoolean,,,,,,,,,, +,valueOf(null),LuaNil,,,,,,,,,, +,valueOf(int) ,LuaInteger,,,,,,,,,, +,valueOf(double),LuaNumber,,,,,,,,,, +,valueOf(long),LuaNumber,,,,,,,,,, +,valueOf(String),LuaString,,,,,,,,,, +,tableOf(...),LuaTable,,,,,,,,,, +,listOf(LuaValue[]),LuaTable,,,,,,,,,, +,userdataOf(Object),LuaUserdata,,,,,,,,,, +,"uerdataOf(Object,Value)",LuaUserdata,,,,,,,,,, +,,,,,,,Arugment type,,,,, +,,,LuaBoolean,LuaClosure,LuaFunction,LuaDouble,LuaInteger,LuaNil,LuaString,LuaTable,LuaThread,LuaUserdata +Type Check Functions,,,,,,,,,,,, +,isboolean,boolean,TRUE,f,f,f,f,f,f,f,f,f +,isclosure,boolean,f,TRUE,f,f,f,f,f,f,f,f +,isfunction,boolean,f,TRUE,TRUE,f,f,f,f,f,f,f +,isint,boolean,f,f,f,f,TRUE,f,true | f,f,f,f +,isinttype,boolean,f,f,f,f,TRUE,f,f,f,f,f +,isnumber,boolean,f,f,f,TRUE,TRUE,f,true | f,f,f,f +,islong,boolean,f,f,f,true | f,TRUE,f,true | f,f,f,f +,isnil,boolean,f,f,f,f,f,TRUE,f,f,f,f +,isstring,boolean,f,f,f,true | f,TRUE,f,TRUE,f,f,f +,istable,boolean,f,f,f,f,f,f,f,TRUE,f,f +,isthread,boolean,f,f,f,f,f,f,f,f,TRUE,f +,isuserdata,boolean,f,f,f,f,f,f,f,f,f,TRUE +,isuserdata(Class c),boolean,f,f,f,f,f,f,f,f,f,true | f + + +Java Type Coercion Functions,,,,,,,,,,,, +,toboolean,boolean,this.v,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE +,tobyte,byte,0,0,0,0,this.v | 0,0,this.v | 0,0,0,0 +,tochar,char,0,0,0,0,this.v | 0,0,this.v | 0,0,0,0 +,todouble,double,0,0,0,this.v,this.v,0,this.v | 0,0,0,0 +,tofloat,float,0,0,0,this.v | 0,this.v,0,this.v | 0,0,0,0 +,toint,int,0,0,0,0,this.v,0,this.v | 0,0,0,0 +,tolong,long,0,0,0,0,this.v,0,this.v | 0,0,0,0 +,toshort,short,0,0,0,0,this.v | 0,0,this.v | 0,0,0,0 +,tojstring,String,"""true""|""false""","""closure: x""","""name""",(str) this.v,(str) this.v,"""nil""",this.v,"""table: x""","""thread: x""","""userdata: x""" +,touserdata,Object,null,null,null,null,null,null,null,null,this,this.instance + +,,,LuaBoolean,LuaClosure,LuaFunction,LuaDouble,LuaInteger,LuaNil,LuaString,LuaTable,LuaThread,LuaUserdata +Optional Argument Conversion Functions,,,,,,,,,,,, +,optboolean,boolean,this,e,e,e,e,defval,e,e,e,e +,optclosure,LuaClosure,n,this,e,e,e,defval,e,e,e,e +,optdouble,double,e,e,e,this,this,defval,this | e,e,e,e +,optfunction,LuaFunction,n,this,this,e,e,defval,e,e,e,e +,optint,int,e,e,e,(int) this,this,defval,this | e,e,e,e +,optinteger,LuaInteger,e,e,e,(int) this,this,defval,this | e,e,e,e +,optlong,long,e,e,e,(long) this,this,defval,this | e,e,e,e +,optnumber,LuaNumber,e,e,e,this,this,defval,this | e,e,e,e +,optjstring,String,e,e,e,(str) this.v,(str) this.v,defval,this,e,e,e +,optstring,LuaString,e,e,e,(str) this.v,(str) this.v,defval,this,e,e,e +,opttable,LuaTable,e,e,e,e,e,defval,e,this,e,e +,optthread,LuaThread,e,e,e,e,e,defval,e,e,this,n +,optuserdata,Object,e,e,e,e,e,defval,e,e,e,instance +,optuserdata(Class c),Object,e,e,e,e,e,defval,e,e,e,instance | e + +Required Argument Conversion Functions,,,,,,,,,,,, +,checkboolean,boolean,this,e,e,e,e,e,e,e,e,e +,checkclosure,LuaClosure,e,this,e,e,e,e,e,e,e,e +,checkdouble,double,e,e,e,this,this,e,e,e,e,e +,checkfunction,LuaFunction,e,this,this,e,e,e,e,e,e,e +,checkint,int,e,e,e,this | e,this,e,e,e,e,e +,checkinteger,LuaInteger,e,e,e,e,this,e,e,e,e,e +,checklong,LuaNumber,e,e,e,this | e,this,e,e,e,e,e +,checknumber,LuaNumber,e,e,e,this,this,e,e,e,e,e +,checkjstring,String,e,e,e,(str) this.v,(str) this.v,e,(str) this.v,e,e,e +,checkstring,LuaString,e,e,e,(str) this.v,(str) this.v,e,this,e,e,e +,checktable,LuaTable,e,e,e,e,e,e,e,this,e,e +,checkthread,LuaThread,e,e,e,e,e,e,e,e,this,e +,checkuserdata,Object,e,e,e,e,e,e,e,e,e,instance +,checkuserdata(Class c),Object,e,e,e,e,e,e,e,e,e,instance | e +,checkvalue,LuaValue,this,this,this,this,this,e,this,this,this,this + +,,,LuaBoolean,LuaClosure,LuaFunction,LuaDouble,LuaInteger,LuaNil,LuaString,LuaTable,LuaThread,LuaUserdata +Lua Language Operations,,,,,,,,,,,, +,type,int,TBOOLEAN,TFUNCTION,TFUNCTION,TNUMBER,TNUMBER,TNIL,TSTRING,TTABLE,TTHREAD,TUSERDATA +,typename,string,"""boolean""","""function""","""function""","""number""","""number""","""nil""","""string""","""table""","""thread""","""userdata""" +,len,LuaInteger,e,e,e,e,e,e,#v,#v,e,e +,length,int,e,e,e,e,e,e,#v,#v,e,e +,getmetatable,LuaValue,static,static,static,static,static,static,static,instance,static ,instance +,setmetatable,LuaValue,e,e,e,e,e,e,e,instance,e,instance +,getfenv,LuaTable,e,instance,instance,e,e,e,e,e,instance,e +,setfenv,LuaFunction,e,instance,instance,e,e,e,e,e,instance,e +,call,LuaValue,__call,call,call,__call,__call,__call,__call,__call,__call,__call +,invoke,Varargs,__call,call,call,__call,__call,__call,__call,__call,__call,__call +,get,LuaValue,__index,__index,__index,__index,__index,__index,__index,get,__index,__index +,set,LuaValue,__newindex,__newindex,__newindex,__newindex,__newindex,__newindex,__newindex,set,__newindex,__newindex diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/Buffer.java b/luaj-2.0.3/src/core/org/luaj/vm2/Buffer.java new file mode 100644 index 0000000000..1789bc39de --- /dev/null +++ b/luaj-2.0.3/src/core/org/luaj/vm2/Buffer.java @@ -0,0 +1,260 @@ +/******************************************************************************* + * 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; + + +/** + * String buffer for use in string library methods, optimized for production + * of StrValue instances. + *
+ * The buffer can begin initially as a wrapped {@link LuaValue} + * and only when concatenation actually occurs are the bytes first copied. + *
+ * To convert back to a {@link LuaValue} again,
+ * the function {@link Buffer#value()} is used.
+ * @see LuaValue
+ * @see LuaValue#buffer()
+ * @see LuaString
+ */
+public final class Buffer {
+
+ /** Default capacity for a buffer: 64 */
+ private static final int DEFAULT_CAPACITY = 64;
+
+ /** Shared static array with no bytes */
+ private static final byte[] NOBYTES = {};
+
+ /** Bytes in this buffer */
+ private byte[] bytes;
+
+ /** Length of this buffer */
+ private int length;
+
+ /** Offset into the byte array */
+ private int offset;
+
+ /** Value of this buffer, when not represented in bytes */
+ private LuaValue value;
+
+ /**
+ * Create buffer with default capacity
+ * @see #DEFAULT_CAPACITY
+ */
+ public Buffer() {
+ this(DEFAULT_CAPACITY);
+ }
+
+ /**
+ * Create buffer with specified initial capacity
+ * @param initialCapacity the initial capacity
+ */
+ public Buffer( int initialCapacity ) {
+ bytes = new byte[ initialCapacity ];
+ length = 0;
+ offset = 0;
+ value = null;
+ }
+
+ /**
+ * Create buffer with specified initial value
+ * @param value the initial value
+ */
+ public Buffer(LuaValue value) {
+ bytes = NOBYTES;
+ length = offset = 0;
+ this.value = value;
+ }
+
+ /**
+ * Get buffer contents as a {@link LuaValue}
+ * @return value as a {@link LuaValue}, converting as necessary
+ */
+ public LuaValue value() {
+ return value != null? value: this.tostring();
+ }
+
+ /**
+ * Set buffer contents as a {@link LuaValue}
+ * @param value value to set
+ */
+ public Buffer setvalue(LuaValue value) {
+ bytes = NOBYTES;
+ offset = length = 0;
+ this.value = value;
+ return this;
+ }
+
+ /**
+ * Convert the buffer to a {@link LuaString}
+ * @return the value as a {@link LuaString}
+ */
+ public final LuaString tostring() {
+ realloc( length, 0 );
+ return LuaString.valueOf( bytes, offset, length );
+ }
+
+ /**
+ * Convert the buffer to a Java String
+ * @return the value as a Java String
+ */
+ public String tojstring() {
+ return value().tojstring();
+ }
+
+ /**
+ * Convert the buffer to a Java String
+ * @return the value as a Java String
+ */
+ public String toString() {
+ return tojstring();
+ }
+
+ /**
+ * Append a single byte to the buffer.
+ * @return {@code this} to allow call chaining
+ */
+ public final Buffer append( byte b ) {
+ makeroom( 0, 1 );
+ bytes[ offset + length++ ] = b;
+ return this;
+ }
+
+ /**
+ * Append a {@link LuaValue} to the buffer.
+ * @return {@code this} to allow call chaining
+ */
+ public final Buffer append( LuaValue val ) {
+ append( val.strvalue() );
+ return this;
+ }
+
+ /**
+ * Append a {@link LuaString} to the buffer.
+ * @return {@code this} to allow call chaining
+ */
+ public final Buffer append( LuaString str ) {
+ final int n = str.m_length;
+ makeroom( 0, n );
+ str.copyInto( 0, bytes, offset + length, n );
+ length += n;
+ return this;
+ }
+
+ /**
+ * Append a Java String to the buffer.
+ * The Java string will be converted to bytes using the UTF8 encoding.
+ * @return {@code this} to allow call chaining
+ * @see LuaString#encodeToUtf8(char[], byte[], int)
+ */
+ public final Buffer append( String str ) {
+ char[] chars = str.toCharArray();
+ /* DAN200 START */
+ /*
+ final int n = LuaString.lengthAsUtf8( chars );
+ makeroom( 0, n );
+ LuaString.encodeToUtf8( chars, bytes, offset + length );
+ length += n;
+ */
+ makeroom( 0, chars.length );
+ for( int i=0; i
+* A simple pattern for loading and executing code is
+*
+*
+* Prior to loading code, a compiler should be installed.
+*
+* By default, when using {@link JsePlatform} or {@JmePlatform}
+* to construct globals, the {@link LuaC} compiler is installed.
+*
+* To override the default compiler with, say, the {@link LuaJC}
+* lua-to-java bytecode compiler, install it before loading,
+* for example:
+*
+ * See the {@link LuaClosure} documentation for examples of how to use the compiler.
+ * @see LuaClosure
+ * @see #load(InputStream, String, LuaValue)
+ * */
+ public interface LuaCompiler {
+
+ /** Load into a Closure or LuaFunction from a Stream and initializes the environment
+ * @throws IOException */
+ public LuaFunction load(InputStream stream, String filename, LuaValue env) throws IOException;
+ }
+
+ /** Compiler instance, if installed */
+ public static LuaCompiler compiler = null;
+
+ /** Signature byte indicating the file is a compiled binary chunk */
+ private static final byte[] LUA_SIGNATURE = { '\033', 'L', 'u', 'a' };
+
+ /** Name for compiled chunks */
+ public static final String SOURCE_BINARY_STRING = "binary string";
+
+
+ /** for header of binary files -- this is Lua 5.1 */
+ public static final int LUAC_VERSION = 0x51;
+
+ /** for header of binary files -- this is the official format */
+ public static final int LUAC_FORMAT = 0;
+
+ /** size of header of binary files */
+ public static final int LUAC_HEADERSIZE = 12;
+
+ // values read from the header
+ private int luacVersion;
+ private int luacFormat;
+ private boolean luacLittleEndian;
+ private int luacSizeofInt;
+ private int luacSizeofSizeT;
+ private int luacSizeofInstruction;
+ private int luacSizeofLuaNumber;
+ private int luacNumberFormat;
+
+ /** input stream from which we are loading */
+ public final DataInputStream is;
+
+ /** Name of what is being loaded? */
+ String name;
+
+ private static final LuaValue[] NOVALUES = {};
+ private static final Prototype[] NOPROTOS = {};
+ private static final LocVars[] NOLOCVARS = {};
+ private static final LuaString[] NOSTRVALUES = {};
+ private static final int[] NOINTS = {};
+
+ /** Read buffer */
+ private byte[] buf = new byte[512];
+
+
+ /** Load a 4-byte int value from the input stream
+ * @return the int value laoded.
+ **/
+ int loadInt() throws IOException {
+ is.readFully(buf,0,4);
+ return luacLittleEndian?
+ (buf[3] << 24) | ((0xff & buf[2]) << 16) | ((0xff & buf[1]) << 8) | (0xff & buf[0]):
+ (buf[0] << 24) | ((0xff & buf[1]) << 16) | ((0xff & buf[2]) << 8) | (0xff & buf[3]);
+ }
+
+ /** Load an array of int values from the input stream
+ * @return the array of int values laoded.
+ **/
+ int[] loadIntArray() throws IOException {
+ int n = loadInt();
+ if ( n == 0 )
+ return NOINTS;
+
+ // read all data at once
+ int m = n << 2;
+ if ( buf.length < m )
+ buf = new byte[m];
+ is.readFully(buf,0,m);
+ int[] array = new int[n];
+ for ( int i=0, j=0; i
+ * These instance are not instantiated directly by clients.
+ * Instead, there are exactly twon instances of this class,
+ * {@link LuaValue#TRUE} and {@link LuaValue#FALSE}
+ * representing the lua values {@code true} and {@link false}.
+ * The function {@link LuaValue#valueOf(boolean)} will always
+ * return one of these two values.
+ *
+ * Any {@link LuaValue} can be converted to its equivalent
+ * boolean representation using {@link LuaValue#toboolean()}
+ *
+ * @see LuaValue
+ * @see LuaValue#valueOf(boolean)
+ * @see LuaValue#TRUE
+ * @see LuaValue#FALSE
+ */
+public final class LuaBoolean extends LuaValue {
+
+ /** The singleton instance representing lua {@code true} */
+ static final LuaBoolean _TRUE = new LuaBoolean(true);
+
+ /** The singleton instance representing lua {@code false} */
+ static final LuaBoolean _FALSE = new LuaBoolean(false);
+
+ /** Shared static metatable for boolean values represented in lua. */
+ public static LuaValue s_metatable;
+
+ /** The value of the boolean */
+ public final boolean v;
+
+ LuaBoolean(boolean b) {
+ this.v = b;
+ }
+
+ public int type() {
+ return LuaValue.TBOOLEAN;
+ }
+
+ public String typename() {
+ return "boolean";
+ }
+
+ public boolean isboolean() {
+ return true;
+ }
+
+ public LuaValue not() {
+ return v ? FALSE : LuaValue.TRUE;
+ }
+
+ /**
+ * Return the boolean value for this boolean
+ * @return value as a Java boolean
+ */
+ public boolean booleanValue() {
+ return v;
+ }
+
+ public boolean toboolean() {
+ return v;
+ }
+
+ public String tojstring() {
+ return v ? "true" : "false";
+ }
+
+ public boolean optboolean(boolean defval) {
+ return this.v;
+ }
+
+ public boolean checkboolean() {
+ return v;
+ }
+
+ public LuaValue getmetatable() {
+ return s_metatable;
+ }
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/LuaClosure.java b/luaj-2.0.3/src/core/org/luaj/vm2/LuaClosure.java
new file mode 100644
index 0000000000..8deb56b47d
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/LuaClosure.java
@@ -0,0 +1,521 @@
+/*******************************************************************************
+* 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 java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.luaj.vm2.LoadState.LuaCompiler;
+import org.luaj.vm2.compiler.LuaC;
+import org.luaj.vm2.lib.DebugLib;
+
+/**
+ * Extension of {@link LuaFunction} which executes lua bytecode.
+ *
+ * A {@link LuaClosure} is a combination of a {@link Prototype}
+ * and a {@link LuaValue} to use as an environment for execution.
+ *
+ * There are three main ways {@link LuaClosure} instances are created:
+ *
+ * To construct it directly, the {@link Prototype} is typically created via a compiler such as {@link LuaC}:
+ *
+ * To construct it indirectly, the {@link LuaC} compiler may be used,
+ * which implements the {@link LuaCompiler} interface:
+ *
+ * Typically, a closure that has just been loaded needs to be initialized by executing it,
+ * and its return value can be saved if needed:
+ *
+ * In the preceding, the loaded value is typed as {@link LuaFunction}
+ * to allow for the possibility of other compilers such as {@link LuaJC}
+ * producing {@link LuaFunction} directly without
+ * creating a {@link Prototype} or {@link LuaClosure}.
+ *
+ * Since a {@link LuaClosure} is a {@link LuaFunction} which is a {@link LuaValue},
+ * all the value operations can be used directly such as:
+ *
+ * These instance are not instantiated directly by clients, but indirectly
+ * via the static functions {@link LuaValue#valueOf(int)} or {@link LuaValue#valueOf(double)}
+ * functions. This ensures that values which can be represented as int
+ * are wrapped in {@link LuaInteger} instead of {@link LuaDouble}.
+ *
+ * Almost all API's implemented in LuaDouble are defined and documented in {@link LuaValue}.
+ *
+ * However the constants {@link #NAN}, {@link #POSINF}, {@link #NEGINF},
+ * {@link #JSTR_NAN}, {@link #JSTR_POSINF}, and {@link #JSTR_NEGINF} may be useful
+ * when dealing with Nan or Infinite values.
+ *
+ * LuaDouble also defines functions for handling the unique math rules of lua devision and modulo in
+ *
+ * @see LuaValue
+ * @see LuaNumber
+ * @see LuaInteger
+ * @see LuaValue#valueOf(int)
+ * @see LuaValue#valueOf(double)
+ */
+public class LuaDouble extends LuaNumber {
+
+ /** Constant LuaDouble representing NaN (not a number) */
+ public static final LuaDouble NAN = new LuaDouble( Double.NaN );
+
+ /** Constant LuaDouble representing positive infinity */
+ public static final LuaDouble POSINF = new LuaDouble( Double.POSITIVE_INFINITY );
+
+ /** Constant LuaDouble representing negative infinity */
+ public static final LuaDouble NEGINF = new LuaDouble( Double.NEGATIVE_INFINITY );
+
+ /** Constant String representation for NaN (not a number), "nan" */
+ public static final String JSTR_NAN = "nan";
+
+ /** Constant String representation for positive infinity, "inf" */
+ public static final String JSTR_POSINF = "inf";
+
+ /** Constant String representation for negative infinity, "-inf" */
+ public static final String JSTR_NEGINF = "-inf";
+
+ /** The value being held by this instance. */
+ final double v;
+
+ public static LuaNumber valueOf(double d) {
+ int id = (int) d;
+ return d==id? (LuaNumber) LuaInteger.valueOf(id): (LuaNumber) new LuaDouble(d);
+ }
+
+ /** Don't allow ints to be boxed by DoubleValues */
+ private LuaDouble(double d) {
+ this.v = d;
+ }
+
+ public int hashCode() {
+ long l = Double.doubleToLongBits(v);
+ return ((int)(l>>32)) | (int) l;
+ }
+
+ public boolean islong() {
+ return v == (long) v;
+ }
+
+ public byte tobyte() { return (byte) (long) v; }
+ public char tochar() { return (char) (long) v; }
+ public double todouble() { return v; }
+ public float tofloat() { return (float) v; }
+ public int toint() { return (int) (long) v; }
+ public long tolong() { return (long) v; }
+ public short toshort() { return (short) (long) v; }
+
+ public double optdouble(double defval) { return v; }
+ public int optint(int defval) { return (int) (long) v; }
+ public LuaInteger optinteger(LuaInteger defval) { return LuaInteger.valueOf((int) (long)v); }
+ public long optlong(long defval) { return (long) v; }
+
+ public LuaInteger checkinteger() { return LuaInteger.valueOf( (int) (long) v ); }
+
+ // unary operators
+ public LuaValue neg() { return valueOf(-v); }
+
+ // object equality, used for key comparison
+ public boolean equals(Object o) { return o instanceof LuaDouble? ((LuaDouble)o).v == v: false; }
+
+ // equality w/ metatable processing
+ public LuaValue eq( LuaValue val ) { return val.raweq(v)? TRUE: FALSE; }
+ public boolean eq_b( LuaValue val ) { return val.raweq(v); }
+
+ // equality w/o metatable processing
+ public boolean raweq( LuaValue val ) { return val.raweq(v); }
+ public boolean raweq( double val ) { return v == val; }
+ public boolean raweq( int val ) { return v == val; }
+
+ // basic binary arithmetic
+ public LuaValue add( LuaValue rhs ) { return rhs.add(v); }
+ public LuaValue add( double lhs ) { return LuaDouble.valueOf(lhs + v); }
+ public LuaValue sub( LuaValue rhs ) { return rhs.subFrom(v); }
+ public LuaValue sub( double rhs ) { return LuaDouble.valueOf(v - rhs); }
+ public LuaValue sub( int rhs ) { return LuaDouble.valueOf(v - rhs); }
+ public LuaValue subFrom( double lhs ) { return LuaDouble.valueOf(lhs - v); }
+ public LuaValue mul( LuaValue rhs ) { return rhs.mul(v); }
+ public LuaValue mul( double lhs ) { return LuaDouble.valueOf(lhs * v); }
+ public LuaValue mul( int lhs ) { return LuaDouble.valueOf(lhs * v); }
+ public LuaValue pow( LuaValue rhs ) { return rhs.powWith(v); }
+ public LuaValue pow( double rhs ) { return MathLib.dpow(v,rhs); }
+ public LuaValue pow( int rhs ) { return MathLib.dpow(v,rhs); }
+ public LuaValue powWith( double lhs ) { return MathLib.dpow(lhs,v); }
+ public LuaValue powWith( int lhs ) { return MathLib.dpow(lhs,v); }
+ public LuaValue div( LuaValue rhs ) { return rhs.divInto(v); }
+ public LuaValue div( double rhs ) { return LuaDouble.ddiv(v,rhs); }
+ public LuaValue div( int rhs ) { return LuaDouble.ddiv(v,rhs); }
+ public LuaValue divInto( double lhs ) { return LuaDouble.ddiv(lhs,v); }
+ public LuaValue mod( LuaValue rhs ) { return rhs.modFrom(v); }
+ public LuaValue mod( double rhs ) { return LuaDouble.dmod(v,rhs); }
+ public LuaValue mod( int rhs ) { return LuaDouble.dmod(v,rhs); }
+ public LuaValue modFrom( double lhs ) { return LuaDouble.dmod(lhs,v); }
+
+
+ /** Divide two double numbers according to lua math, and return a {@link LuaValue} result.
+ * @param lhs Left-hand-side of the division.
+ * @param rhs Right-hand-side of the division.
+ * @return {@link LuaValue} for the result of the division,
+ * taking into account positive and negiative infinity, and Nan
+ * @see #ddiv_d(double, double)
+ */
+ public static LuaValue ddiv(double lhs, double rhs) {
+ return rhs!=0? valueOf( lhs / rhs ): lhs>0? POSINF: lhs==0? NAN: NEGINF;
+ }
+
+ /** Divide two double numbers according to lua math, and return a double result.
+ * @param lhs Left-hand-side of the division.
+ * @param rhs Right-hand-side of the division.
+ * @return Value of the division, taking into account positive and negative infinity, and Nan
+ * @see #ddiv(double, double)
+ */
+ public static double ddiv_d(double lhs, double rhs) {
+ return rhs!=0? lhs / rhs: lhs>0? Double.POSITIVE_INFINITY: lhs==0? Double.NaN: Double.NEGATIVE_INFINITY;
+ }
+
+ /** Take modulo double numbers according to lua math, and return a {@link LuaValue} result.
+ * @param lhs Left-hand-side of the modulo.
+ * @param rhs Right-hand-side of the modulo.
+ * @return {@link LuaValue} for the result of the modulo,
+ * using lua's rules for modulo
+ * @see #dmod_d(double, double)
+ */
+ public static LuaValue dmod(double lhs, double rhs) {
+ return rhs!=0? valueOf( lhs-rhs*Math.floor(lhs/rhs) ): NAN;
+ }
+
+ /** Take modulo for double numbers according to lua math, and return a double result.
+ * @param lhs Left-hand-side of the modulo.
+ * @param rhs Right-hand-side of the modulo.
+ * @return double value for the result of the modulo,
+ * using lua's rules for modulo
+ * @see #dmod(double, double)
+ */
+ public static double dmod_d(double lhs, double rhs) {
+ return rhs!=0? lhs-rhs*Math.floor(lhs/rhs): Double.NaN;
+ }
+
+ // relational operators
+ public LuaValue lt( LuaValue rhs ) { return rhs.gt_b(v)? LuaValue.TRUE: FALSE; }
+ public LuaValue lt( double rhs ) { return v < rhs? TRUE: FALSE; }
+ public LuaValue lt( int rhs ) { return v < rhs? TRUE: FALSE; }
+ public boolean lt_b( LuaValue rhs ) { return rhs.gt_b(v); }
+ public boolean lt_b( int rhs ) { return v < rhs; }
+ public boolean lt_b( double rhs ) { return v < rhs; }
+ public LuaValue lteq( LuaValue rhs ) { return rhs.gteq_b(v)? LuaValue.TRUE: FALSE; }
+ public LuaValue lteq( double rhs ) { return v <= rhs? TRUE: FALSE; }
+ public LuaValue lteq( int rhs ) { return v <= rhs? TRUE: FALSE; }
+ public boolean lteq_b( LuaValue rhs ) { return rhs.gteq_b(v); }
+ public boolean lteq_b( int rhs ) { return v <= rhs; }
+ public boolean lteq_b( double rhs ) { return v <= rhs; }
+ public LuaValue gt( LuaValue rhs ) { return rhs.lt_b(v)? LuaValue.TRUE: FALSE; }
+ public LuaValue gt( double rhs ) { return v > rhs? TRUE: FALSE; }
+ public LuaValue gt( int rhs ) { return v > rhs? TRUE: FALSE; }
+ public boolean gt_b( LuaValue rhs ) { return rhs.lt_b(v); }
+ public boolean gt_b( int rhs ) { return v > rhs; }
+ public boolean gt_b( double rhs ) { return v > rhs; }
+ public LuaValue gteq( LuaValue rhs ) { return rhs.lteq_b(v)? LuaValue.TRUE: FALSE; }
+ public LuaValue gteq( double rhs ) { return v >= rhs? TRUE: FALSE; }
+ public LuaValue gteq( int rhs ) { return v >= rhs? TRUE: FALSE; }
+ public boolean gteq_b( LuaValue rhs ) { return rhs.lteq_b(v); }
+ public boolean gteq_b( int rhs ) { return v >= rhs; }
+ public boolean gteq_b( double rhs ) { return v >= rhs; }
+
+ // string comparison
+ public int strcmp( LuaString rhs ) { typerror("attempt to compare number with string"); return 0; }
+
+ public String tojstring() {
+ /*
+ if ( v == 0.0 ) { // never occurs in J2me
+ long bits = Double.doubleToLongBits( v );
+ return ( bits >> 63 == 0 ) ? "0" : "-0";
+ }
+ */
+ long l = (long) v;
+ if ( l == v )
+ return Long.toString(l);
+ if ( Double.isNaN(v) )
+ return JSTR_NAN;
+ if ( Double.isInfinite(v) )
+ return (v<0? JSTR_NEGINF: JSTR_POSINF);
+ return Float.toString((float)v);
+ }
+
+ public LuaString strvalue() {
+ return LuaString.valueOf(tojstring());
+ }
+
+ public LuaString optstring(LuaString defval) {
+ return LuaString.valueOf(tojstring());
+ }
+
+ public LuaValue tostring() {
+ return LuaString.valueOf(tojstring());
+ }
+
+ public String optjstring(String defval) {
+ return tojstring();
+ }
+
+ public LuaNumber optnumber(LuaNumber defval) {
+ return this;
+ }
+
+ public boolean isnumber() {
+ return true;
+ }
+
+ public boolean isstring() {
+ return true;
+ }
+
+ public LuaValue tonumber() {
+ return this;
+ }
+ public int checkint() { return (int) (long) v; }
+ public long checklong() { return (long) v; }
+ public LuaNumber checknumber() { return this; }
+ public double checkdouble() { return v; }
+
+ public String checkjstring() {
+ return tojstring();
+ }
+ public LuaString checkstring() {
+ return LuaString.valueOf(tojstring());
+ }
+
+ public LuaValue checkvalidkey() {
+ if ( Double.isNaN(v) )
+ throw new LuaError("table index expected, got nan");
+ return this;
+ }
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/LuaError.java b/luaj-2.0.3/src/core/org/luaj/vm2/LuaError.java
new file mode 100644
index 0000000000..fd9c62e4e5
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/LuaError.java
@@ -0,0 +1,132 @@
+/*******************************************************************************
+* Copyright (c) 2009-2011 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.lib.DebugLib;
+
+/**
+ * RuntimeException that is thrown and caught in response to a lua error.
+ *
+ * {@link LuaError} is used wherever a lua call to {@code error()}
+ * would be used within a script.
+ *
+ * Since it is an unchecked exception inheriting from {@link RuntimeException},
+ * Java method signatures do notdeclare this exception, althoug it can
+ * be thrown on almost any luaj Java operation.
+ * This is analagous to the fact that any lua script can throw a lua error at any time.
+ *
+ */
+public class LuaError extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ private String traceback;
+
+ /**
+ * Run the error hook if there is one
+ * @param msg the message to use in error hook processing.
+ * */
+ private static String errorHook(String msg) {
+ LuaThread thread = LuaThread.getRunning();
+ if ( thread.err != null ) {
+ LuaValue errfunc = thread.err;
+ thread.err = null;
+ try {
+ return errfunc.call( LuaValue.valueOf(msg) ).tojstring();
+ } catch ( Throwable t ) {
+ return "error in error handling";
+ } finally {
+ thread.err = errfunc;
+ }
+ }
+ return msg;
+ }
+
+ private Throwable cause;
+
+ /** Construct LuaError when a program exception occurs.
+ *
+ * All errors generated from lua code should throw LuaError(String) instead.
+ * @param cause the Throwable that caused the error, if known.
+ */
+ public LuaError(Throwable cause) {
+ super( errorHook( addFileLine( "vm error: "+cause ) ) );
+ this.cause = cause;
+ this.traceback = DebugLib.traceback(1);
+ }
+
+ /**
+ * Construct a LuaError with a specific message.
+ *
+ * @param message message to supply
+ */
+ public LuaError(String message) {
+ super( errorHook( addFileLine( message ) ) );
+ this.traceback = DebugLib.traceback(1);
+ }
+
+ /**
+ * Construct a LuaError with a message, and level to draw line number information from.
+ * @param message message to supply
+ * @param level where to supply line info from in call stack
+ */
+ public LuaError(String message, int level) {
+ super( errorHook( addFileLine( message, level ) ) );
+ this.traceback = DebugLib.traceback(1);
+ }
+
+ /**
+ * Add file and line info to a message at a particular level
+ * @param message the String message to use
+ * @param level where to supply line info from in call stack
+ * */
+ private static String addFileLine( String message, int level ) {
+ if ( message == null ) return null;
+ if ( level == 0 ) return message;
+ String fileline = DebugLib.fileline(level-1);
+ return fileline!=null? fileline+": "+message: message;
+ }
+
+ /** Add file and line info for the nearest enclosing closure
+ * @param message the String message to use
+ * */
+ private static String addFileLine( String message ) {
+ if ( message == null ) return null;
+ String fileline = DebugLib.fileline();
+ return fileline!=null? fileline+": "+message: message;
+ }
+
+ /** Print the message and stack trace */
+ public void printStackTrace() {
+ System.out.println( toString() );
+ if ( traceback != null )
+ System.out.println( traceback );
+ }
+
+ /**
+ * Get the cause, if any.
+ */
+ public Throwable getCause() {
+ return cause;
+ }
+
+
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/LuaFunction.java b/luaj-2.0.3/src/core/org/luaj/vm2/LuaFunction.java
new file mode 100644
index 0000000000..5a4f114632
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/LuaFunction.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2009-2011 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;
+
+/**
+ * Base class for functions implemented in Java.
+ *
+ * Direct subclass include {@link LibFunction} which is the base class for
+ * all built-in library functions coded in Java,
+ * and {@link LuaClosure}, which represents a lua closure
+ * whose bytecode is interpreted when the function is invoked.
+ * @see LuaValue
+ * @see LibFunction
+ * @see LuaClosure
+ */
+abstract
+public class LuaFunction extends LuaValue {
+
+ /** Shared static metatable for all functions and closures. */
+ public static LuaValue s_metatable;
+
+ protected LuaValue env;
+
+ public LuaFunction() {
+ this.env = NIL;
+ }
+
+ public LuaFunction(LuaValue env) {
+ this.env = env;
+ }
+
+ public int type() {
+ return TFUNCTION;
+ }
+
+ public String typename() {
+ return "function";
+ }
+
+ public boolean isfunction() {
+ return true;
+ }
+
+ public LuaValue checkfunction() {
+ return this;
+ }
+
+ public LuaFunction optfunction(LuaFunction defval) {
+ return this;
+ }
+
+ public LuaValue getmetatable() {
+ return s_metatable;
+ }
+
+ public LuaValue getfenv() {
+ return env;
+ }
+
+ public void setfenv(LuaValue env) {
+ this.env = env!=null? env: NIL;
+ }
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/LuaInteger.java b/luaj-2.0.3/src/core/org/luaj/vm2/LuaInteger.java
new file mode 100644
index 0000000000..008efdd4b8
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/LuaInteger.java
@@ -0,0 +1,215 @@
+/*******************************************************************************
+* 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.lib.MathLib;
+
+/**
+ * Extension of {@link LuaNumber} which can hold a Java int as its value.
+ *
+ * These instance are not instantiated directly by clients, but indirectly
+ * via the static functions {@link LuaValue#valueOf(int)} or {@link LuaValue#valueOf(double)}
+ * functions. This ensures that policies regarding pooling of instances are
+ * encapsulated.
+ *
+ * There are no API's specific to LuaInteger that are useful beyond what is already
+ * exposed in {@link LuaValue}.
+ *
+ * @see LuaValue
+ * @see LuaNumber
+ * @see LuaDouble
+ * @see LuaValue#valueOf(int)
+ * @see LuaValue#valueOf(double)
+ */
+public class LuaInteger extends LuaNumber {
+
+ private static final LuaInteger[] intValues = new LuaInteger[512];
+ static {
+ for ( int i=0; i<512; i++ )
+ intValues[i] = new LuaInteger(i-256);
+ }
+
+ public static LuaInteger valueOf(int i) {
+ return i<=255 && i>=-256? intValues[i+256]: new LuaInteger(i);
+ };
+
+ // TODO consider moving this to LuaValue
+ /** Return a LuaNumber that represents the value provided
+ * @param l long value to represent.
+ * @return LuaNumber that is eithe LuaInteger or LuaDouble representing l
+ * @see LuaValue#valueOf(int)
+ * @see LuaValue#valueOf(double)
+ */
+ public static LuaNumber valueOf(long l) {
+ int i = (int) l;
+ return l==i? (i<=255 && i>=-256? intValues[i+256]:
+ (LuaNumber) new LuaInteger(i)):
+ (LuaNumber) LuaDouble.valueOf(l);
+ }
+
+ /** The value being held by this instance. */
+ public final int v;
+
+ /**
+ * Package protected constructor.
+ * @see LuaValue#valueOf(int)
+ **/
+ LuaInteger(int i) {
+ this.v = i;
+ }
+
+ public boolean isint() { return true; }
+ public boolean isinttype() { return true; }
+ public boolean islong() { return true; }
+
+ public byte tobyte() { return (byte) v; }
+ public char tochar() { return (char) v; }
+ public double todouble() { return v; }
+ public float tofloat() { return v; }
+ public int toint() { return v; }
+ public long tolong() { return v; }
+ public short toshort() { return (short) v; }
+
+ public double optdouble(double defval) { return v; }
+ public int optint(int defval) { return v; }
+ public LuaInteger optinteger(LuaInteger defval) { return this; }
+ public long optlong(long defval) { return v; }
+
+ public String tojstring() {
+ return Integer.toString(v);
+ }
+
+ public LuaString strvalue() {
+ return LuaString.valueOf(Integer.toString(v));
+ }
+
+ public LuaString optstring(LuaString defval) {
+ return LuaString.valueOf(Integer.toString(v));
+ }
+
+ public LuaValue tostring() {
+ return LuaString.valueOf(Integer.toString(v));
+ }
+
+ public String optjstring(String defval) {
+ return Integer.toString(v);
+ }
+
+ public LuaInteger checkinteger() {
+ return this;
+ }
+
+ public boolean isstring() {
+ return true;
+ }
+
+ public int hashCode() {
+ return v;
+ }
+
+ // unary operators
+ public LuaValue neg() { return valueOf(-(long)v); }
+
+ // object equality, used for key comparison
+ public boolean equals(Object o) { return o instanceof LuaInteger? ((LuaInteger)o).v == v: false; }
+
+ // equality w/ metatable processing
+ public LuaValue eq( LuaValue val ) { return val.raweq(v)? TRUE: FALSE; }
+ public boolean eq_b( LuaValue val ) { return val.raweq(v); }
+
+ // equality w/o metatable processing
+ public boolean raweq( LuaValue val ) { return val.raweq(v); }
+ public boolean raweq( double val ) { return v == val; }
+ public boolean raweq( int val ) { return v == val; }
+
+ // arithmetic operators
+ public LuaValue add( LuaValue rhs ) { return rhs.add(v); }
+ public LuaValue add( double lhs ) { return LuaDouble.valueOf(lhs + v); }
+ public LuaValue add( int lhs ) { return LuaInteger.valueOf(lhs + (long)v); }
+ public LuaValue sub( LuaValue rhs ) { return rhs.subFrom(v); }
+ public LuaValue sub( double rhs ) { return LuaDouble.valueOf(v - rhs); }
+ public LuaValue sub( int rhs ) { return LuaDouble.valueOf(v - rhs); }
+ public LuaValue subFrom( double lhs ) { return LuaDouble.valueOf(lhs - v); }
+ public LuaValue subFrom( int lhs ) { return LuaInteger.valueOf(lhs - (long)v); }
+ public LuaValue mul( LuaValue rhs ) { return rhs.mul(v); }
+ public LuaValue mul( double lhs ) { return LuaDouble.valueOf(lhs * v); }
+ public LuaValue mul( int lhs ) { return LuaInteger.valueOf(lhs * (long)v); }
+ public LuaValue pow( LuaValue rhs ) { return rhs.powWith(v); }
+ public LuaValue pow( double rhs ) { return MathLib.dpow(v,rhs); }
+ public LuaValue pow( int rhs ) { return MathLib.dpow(v,rhs); }
+ public LuaValue powWith( double lhs ) { return MathLib.dpow(lhs,v); }
+ public LuaValue powWith( int lhs ) { return MathLib.dpow(lhs,v); }
+ public LuaValue div( LuaValue rhs ) { return rhs.divInto(v); }
+ public LuaValue div( double rhs ) { return LuaDouble.ddiv(v,rhs); }
+ public LuaValue div( int rhs ) { return LuaDouble.ddiv(v,rhs); }
+ public LuaValue divInto( double lhs ) { return LuaDouble.ddiv(lhs,v); }
+ public LuaValue mod( LuaValue rhs ) { return rhs.modFrom(v); }
+ public LuaValue mod( double rhs ) { return LuaDouble.dmod(v,rhs); }
+ public LuaValue mod( int rhs ) { return LuaDouble.dmod(v,rhs); }
+ public LuaValue modFrom( double lhs ) { return LuaDouble.dmod(lhs,v); }
+
+ // relational operators
+ public LuaValue lt( LuaValue rhs ) { return rhs.gt_b(v)? TRUE: FALSE; }
+ public LuaValue lt( double rhs ) { return v < rhs? TRUE: FALSE; }
+ public LuaValue lt( int rhs ) { return v < rhs? TRUE: FALSE; }
+ public boolean lt_b( LuaValue rhs ) { return rhs.gt_b(v); }
+ public boolean lt_b( int rhs ) { return v < rhs; }
+ public boolean lt_b( double rhs ) { return v < rhs; }
+ public LuaValue lteq( LuaValue rhs ) { return rhs.gteq_b(v)? TRUE: FALSE; }
+ public LuaValue lteq( double rhs ) { return v <= rhs? TRUE: FALSE; }
+ public LuaValue lteq( int rhs ) { return v <= rhs? TRUE: FALSE; }
+ public boolean lteq_b( LuaValue rhs ) { return rhs.gteq_b(v); }
+ public boolean lteq_b( int rhs ) { return v <= rhs; }
+ public boolean lteq_b( double rhs ) { return v <= rhs; }
+ public LuaValue gt( LuaValue rhs ) { return rhs.lt_b(v)? TRUE: FALSE; }
+ public LuaValue gt( double rhs ) { return v > rhs? TRUE: FALSE; }
+ public LuaValue gt( int rhs ) { return v > rhs? TRUE: FALSE; }
+ public boolean gt_b( LuaValue rhs ) { return rhs.lt_b(v); }
+ public boolean gt_b( int rhs ) { return v > rhs; }
+ public boolean gt_b( double rhs ) { return v > rhs; }
+ public LuaValue gteq( LuaValue rhs ) { return rhs.lteq_b(v)? TRUE: FALSE; }
+ public LuaValue gteq( double rhs ) { return v >= rhs? TRUE: FALSE; }
+ public LuaValue gteq( int rhs ) { return v >= rhs? TRUE: FALSE; }
+ public boolean gteq_b( LuaValue rhs ) { return rhs.lteq_b(v); }
+ public boolean gteq_b( int rhs ) { return v >= rhs; }
+ public boolean gteq_b( double rhs ) { return v >= rhs; }
+
+ // string comparison
+ public int strcmp( LuaString rhs ) { typerror("attempt to compare number with string"); return 0; }
+
+ public int checkint() {
+ return v;
+ }
+ public long checklong() {
+ return v;
+ }
+ public double checkdouble() {
+ return v;
+ }
+ public String checkjstring() {
+ return String.valueOf(v);
+ }
+ public LuaString checkstring() {
+ return valueOf( String.valueOf(v) );
+ }
+
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/LuaNil.java b/luaj-2.0.3/src/core/org/luaj/vm2/LuaNil.java
new file mode 100644
index 0000000000..a3960bc6cc
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/LuaNil.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+* Copyright (c) 2009-2011 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;
+
+/**
+ * Class to encapsulate behavior of the singleton instance {@code nil}
+ *
+ * There will be one instance of this class, {@link LuaValue#NIL},
+ * per Java virtual machine.
+ * However, the {@link Varargs} instance {@link LuaValue#NONE}
+ * which is the empty list,
+ * is also considered treated as a nil value by default.
+ *
+ * Although it is possible to test for nil using Java == operator,
+ * the recommended approach is to use the method {@link LuaValue#isnil()}
+ * instead. By using that any ambiguities between
+ * {@link LuaValue#NIL} and {@link LuaValue#NONE} are avoided.
+ * @see LuaValue
+ * @see LuaValue#NIL
+ */
+public class LuaNil extends LuaValue {
+
+ static final LuaNil _NIL = new LuaNil();
+
+ public static LuaValue s_metatable;
+
+ LuaNil() {}
+
+ public int type() {
+ return LuaValue.TNIL;
+ }
+
+ public String typename() {
+ return "nil";
+ }
+
+ public String tojstring() {
+ return "nil";
+ }
+
+ public LuaValue not() {
+ return LuaValue.TRUE;
+ }
+
+ public boolean toboolean() {
+ return false;
+ }
+
+ public boolean isnil() {
+ return true;
+ }
+
+ public LuaValue getmetatable() {
+ return s_metatable;
+ }
+
+ public boolean equals(Object o) {
+ return o instanceof LuaNil;
+ }
+
+ public LuaValue checknotnil() {
+ return argerror("value");
+ }
+
+ public LuaValue checkvalidkey() {
+ return typerror("table index");
+ }
+
+ // optional argument conversions - nil alwas falls badk to default value
+ public boolean optboolean(boolean defval) { return defval; }
+ public LuaClosure optclosure(LuaClosure defval) { return defval; }
+ public double optdouble(double defval) { return defval; }
+ public LuaFunction optfunction(LuaFunction defval) { return defval; }
+ public int optint(int defval) { return defval; }
+ public LuaInteger optinteger(LuaInteger defval) { return defval; }
+ public long optlong(long defval) { return defval; }
+ public LuaNumber optnumber(LuaNumber defval) { return defval; }
+ public LuaTable opttable(LuaTable defval) { return defval; }
+ public LuaThread optthread(LuaThread defval) { return defval; }
+ public String optjstring(String defval) { return defval; }
+ public LuaString optstring(LuaString defval) { return defval; }
+ public Object optuserdata(Object defval) { return defval; }
+ public Object optuserdata(Class c, Object defval) { return defval; }
+ public LuaValue optvalue(LuaValue defval) { return defval; }
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/LuaNumber.java b/luaj-2.0.3/src/core/org/luaj/vm2/LuaNumber.java
new file mode 100644
index 0000000000..ef97221828
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/LuaNumber.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2009-2011 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;
+
+/**
+ * Base class for representing numbers as lua values directly.
+ *
+ * The main subclasses are {@link LuaInteger} which holds values that fit in a java int,
+ * and {@link LuaDouble} which holds all other number values.
+ * @see LuaInteger
+ * @see LuaDouble
+ * @see LuaValue
+ *
+ */
+abstract
+public class LuaNumber extends LuaValue {
+
+ /** Shared static metatable for all number values represented in lua. */
+ public static LuaValue s_metatable;
+
+ public int type() {
+ return TNUMBER;
+ }
+
+ public String typename() {
+ return "number";
+ }
+
+ public LuaNumber checknumber() {
+ return this;
+ }
+
+ public LuaNumber checknumber(String errmsg) {
+ return this;
+ }
+
+ public LuaNumber optnumber(LuaNumber defval) {
+ return this;
+ }
+
+ public LuaValue tonumber() {
+ return this;
+ }
+
+ public boolean isnumber() {
+ return true;
+ }
+
+ public boolean isstring() {
+ return true;
+ }
+
+ public LuaValue getmetatable() {
+ return s_metatable;
+ }
+
+ public LuaValue concat(LuaValue rhs) { return rhs.concatTo(this); }
+ public Buffer concat(Buffer rhs) { return rhs.concatTo(this); }
+ public LuaValue concatTo(LuaNumber lhs) { return strvalue().concatTo(lhs.strvalue()); }
+ public LuaValue concatTo(LuaString lhs) { return strvalue().concatTo(lhs); }
+
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/LuaString.java b/luaj-2.0.3/src/core/org/luaj/vm2/LuaString.java
new file mode 100644
index 0000000000..5d33ba26c0
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/LuaString.java
@@ -0,0 +1,749 @@
+/*******************************************************************************
+* Copyright (c) 2009-2011 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 java.io.ByteArrayInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.String;
+import java.lang.ref.WeakReference;
+import java.util.Hashtable;
+
+import org.luaj.vm2.lib.MathLib;
+import org.luaj.vm2.lib.StringLib;
+
+/**
+ * Subclass of {@link LuaValue} for representing lua strings.
+ *
+ * Because lua string values are more nearly sequences of bytes than
+ * sequences of characters or unicode code points, the {@link LuaString}
+ * implementation holds the string value in an internal byte array.
+ *
+ * {@link LuaString} values are generally not mutable once constructed,
+ * so multiple {@link LuaString} values can chare a single byte array.
+ *
+ * Currently {@link LuaString}s are pooled via a centrally managed weak table.
+ * To ensure that as many string values as possible take advantage of this,
+ * Constructors are not exposed directly. As with number, booleans, and nil,
+ * instance construction should be via {@link LuaValue#valueOf(byte[])} or similar API.
+ *
+ * When Java Strings are used to initialize {@link LuaString} data, the UTF8 encoding is assumed.
+ * The functions
+ * {@link LuaString#lengthAsUtf8(char[]),
+ * {@link LuaString#encodeToUtf8(char[], byte[], int)}, and
+ * {@link LuaString#decodeAsUtf8(byte[], int, int)
+ * are used to convert back and forth between UTF8 byte arrays and character arrays.
+ *
+ * @see LuaValue
+ * @see LuaValue#valueOf(String)
+ * @see LuaValue#valueOf(byte[])
+ */
+public class LuaString extends LuaValue {
+
+ /** The singleton instance representing lua {@code true} */
+ public static LuaValue s_metatable;
+
+ /** The bytes for the string */
+ public final byte[] m_bytes;
+
+ /** The offset into the byte array, 0 means start at the first byte */
+ public final int m_offset;
+
+ /** The number of bytes that comprise this string */
+ public final int m_length;
+
+ private static final Hashtable index_java = new Hashtable();
+
+ private final static LuaString index_get(Hashtable indextable, Object key) {
+ WeakReference w = (WeakReference) indextable.get(key);
+ return w!=null? (LuaString) w.get(): null;
+ }
+
+ private final static void index_set(Hashtable indextable, Object key, LuaString value) {
+ indextable.put(key, new WeakReference(value));
+ }
+
+ /**
+ * Get a {@link LuaString} instance whose bytes match
+ * the supplied Java String using the UTF8 encoding.
+ * @param string Java String containing characters to encode as UTF8
+ * @return {@link LuaString} with UTF8 bytes corresponding to the supplied String
+ */
+ public static LuaString valueOf(String string) {
+ LuaString s = index_get( index_java, string );
+ if ( s != null ) return s;
+ char[] c = string.toCharArray();
+ /* DAN200 START */
+ /*
+ byte[] b = new byte[lengthAsUtf8(c)];
+ encodeToUtf8(c, b, 0);
+ */
+ byte[] b = new byte[c.length];
+ for( int i=0; i
+ * @param bytes byte buffer
+ * @param off offset into the byte buffer
+ * @param len length of the byte buffer
+ * @return {@link LuaString} wrapping the byte buffer
+ */
+ public static LuaString valueOf(byte[] bytes, int off, int len) {
+ return new LuaString(bytes, off, len);
+ }
+
+ /** Construct a {@link LuaString} using the supplied characters as byte values.
+ *
+ * Only th elow-order 8-bits of each character are used, the remainder is ignored.
+ *
+ * This is most useful for constructing byte sequences that do not conform to UTF8.
+ * @param bytes array of char, whose values are truncated at 8-bits each and put into a byte array.
+ * @return {@link LuaString} wrapping a copy of the byte buffer
+ */
+ public static LuaString valueOf(char[] bytes) {
+ int n = bytes.length;
+ byte[] b = new byte[n];
+ for ( int i=0; i
+ * @param bytes byte buffer
+ * @return {@link LuaString} wrapping the byte buffer
+ */
+ public static LuaString valueOf(byte[] bytes) {
+ return valueOf(bytes, 0, bytes.length);
+ }
+
+ /** Construct a {@link LuaString} around a byte array without copying the contents.
+ *
+ * The array is used directly after this is called, so clients must not change contents.
+ *
+ * @param bytes byte buffer
+ * @param offset offset into the byte buffer
+ * @param length length of the byte buffer
+ * @return {@link LuaString} wrapping the byte buffer
+ */
+ private LuaString(byte[] bytes, int offset, int length) {
+ this.m_bytes = bytes;
+ this.m_offset = offset;
+ this.m_length = length;
+ }
+
+ public boolean isstring() {
+ return true;
+ }
+
+ public LuaValue getmetatable() {
+ return s_metatable;
+ }
+
+ public int type() {
+ return LuaValue.TSTRING;
+ }
+
+ public String typename() {
+ return "string";
+ }
+
+ public String tojstring() {
+ /* DAN200 START */
+ /*
+ return decodeAsUtf8(m_bytes, m_offset, m_length);
+ */
+ char[] chars = new char[ m_length ];
+ for( int i=0; i
+ * The string should be measured first with lengthAsUtf8
+ * to make sure the given byte array is large enough.
+ * @param chars Array of unicode characters to be encoded as UTF-8
+ * @param bytes byte array to hold the result
+ * @param off offset into the byte array to start writing
+ * @see #lengthAsUtf8(char[])
+ * @see #decodeAsUtf8(byte[], int, int)
+ * @see #isValidUtf8()
+ */
+ /* DAN200 START */
+ //public static void encodeToUtf8(char[] chars, byte[] bytes, int off) {
+ private static void encodeToUtf8(char[] chars, byte[] bytes, int off) {
+ /* DAN200 END */
+ final int n = chars.length;
+ char c;
+ for ( int i=0, j=off; i
+ * If a table is needed, the one of the type-checking functions can be used such as
+ * {@link #istable()},
+ * {@link #checktable()}, or
+ * {@link #opttable(LuaTable)}
+ *
+ * The main table operations are defined on {@link LuaValue}
+ * for getting and setting values with and without metatag processing:
+ *
+ * To iterate over key-value pairs from Java, use
+ *
+ * As with other types, {@link LuaTable} instances should be constructed via one of the table constructor
+ * methods on {@link LuaValue}:
+ *
+ * Provided for compatibility, not a scalable operation.
+ * @return value for maxn
+ */
+ public int maxn() {
+ int n = 0;
+ for ( int i=0; i
+ * A LuaThread is typically created in response to a scripted call to
+ * {@code coroutine.create()}
+ *
+ * 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 a call to {@link #setGlobals(LuaValue)}
+ * at some point during globals initialization.
+ * See {@link BaseLib} for additional documentation and example code.
+ *
+ * The utility classes {@link JsePlatform} and {@link JmePlatform}
+ * see to it that this initialization is done properly.
+ * For this reason it is highly recommended to use one of these classes
+ * when initializing globals.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * @see LuaValue
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see CoroutineLib
+ */
+public class LuaThread extends LuaValue {
+
+ public static LuaValue s_metatable;
+
+ public static int coroutine_count = 0;
+
+ /** Interval at which to check for lua threads that are no longer referenced.
+ * This can be changed by Java startup code if desired.
+ */
+ static long thread_orphan_check_interval = 30000;
+
+ private static final int STATUS_INITIAL = 0;
+ private static final int STATUS_SUSPENDED = 1;
+ private static final int STATUS_RUNNING = 2;
+ private static final int STATUS_NORMAL = 3;
+ private static final int STATUS_DEAD = 4;
+ private static final String[] STATUS_NAMES = {
+ "suspended",
+ "suspended",
+ "running",
+ "normal",
+ "dead",};
+
+ private LuaValue env;
+ private final State state;
+
+ /** Field to hold state of error condition during debug hook function calls. */
+ public LuaValue err;
+
+ final CallStack callstack = new CallStack();
+
+ public static final int MAX_CALLSTACK = 256;
+
+ private static final LuaThread main_thread = new LuaThread();
+
+ // state of running thread including call stack
+ private static LuaThread running_thread = main_thread;
+
+ /** Interval to check for LuaThread dereferencing. */
+ public static int GC_INTERVAL = 30000;
+
+ /** Thread-local used by DebugLib to store debugging state. */
+ public Object debugState;
+
+ /* DAN200 START */
+ private Vector children = new Vector();
+ /* DAN200 END */
+
+ /** Private constructor for main thread only */
+ private LuaThread() {
+ state = new State(this, null);
+ state.status = STATUS_RUNNING;
+ }
+
+ /**
+ * Create a LuaThread around a function and environment
+ * @param func The function to execute
+ * @param env The environment to apply to the thread
+ */
+ public LuaThread(LuaValue func, LuaValue env) {
+ LuaValue.assert_(func != null, "function cannot be null");
+ this.env = env;
+ state = new State(this, func);
+ }
+
+ 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 LuaValue getfenv() {
+ return env;
+ }
+
+ public void setfenv(LuaValue env) {
+ this.env = env;
+ }
+
+ public String getStatus() {
+ return STATUS_NAMES[state.status];
+ }
+
+ /**
+ * Get the currently running thread.
+ * @return {@link LuaThread} that is currenly running
+ */
+ public static LuaThread getRunning() {
+ return running_thread;
+ }
+
+ /**
+ * Test if this is the main thread
+ * @return true if this is the main thread
+ */
+ public static boolean isMainThread(LuaThread r) {
+ return r == main_thread;
+ }
+
+ /**
+ * Set the globals of the current thread.
+ *
+ * This must be done once before any other code executes.
+ * @param globals The global variables for the main ghread.
+ */
+ public static void setGlobals(LuaValue globals) {
+ running_thread.env = globals;
+ }
+
+ /** Get the current thread's environment
+ * @return {@link LuaValue} containing the global variables of the current thread.
+ */
+ public static LuaValue getGlobals() {
+ LuaValue e = running_thread.env;
+ return e!=null? e: LuaValue.error("LuaThread.setGlobals() not initialized");
+ }
+
+ /**
+ * Callback used at the beginning of a call to prepare for possible getfenv/setfenv calls
+ * @param function Function being called
+ * @return CallStack which is used to signal the return or a tail-call recursion
+ * @see DebugLib
+ */
+ public static final CallStack onCall(LuaFunction function) {
+ CallStack cs = running_thread.callstack;
+ cs.onCall(function);
+ return cs;
+ }
+
+ /**
+ * Get the function called as a specific location on the stack.
+ * @param level 1 for the function calling this one, 2 for the next one.
+ * @return LuaFunction on the call stack, or null if outside of range of active stack
+ */
+ public static final LuaFunction getCallstackFunction(int level) {
+ return running_thread.callstack.getFunction(level);
+ }
+
+ /**
+ * Replace the error function of the currently running thread.
+ * @param errfunc the new error function to use.
+ * @return the previous error function.
+ */
+ public static LuaValue setErrorFunc(LuaValue errfunc) {
+ LuaValue prev = running_thread.err;
+ running_thread.err = errfunc;
+ return prev;
+ }
+
+ /** Yield the current thread with arguments
+ *
+ * @param args The arguments to send as return values to {@link #resume(Varargs)}
+ * @return {@link Varargs} provided as arguments to {@link #resume(Varargs)}
+ */
+ public static Varargs yield(Varargs args) {
+ State s = running_thread.state;
+ if (s.function == null)
+ throw new LuaError("cannot yield main thread");
+ return s.lua_yield(args);
+ }
+
+ /** Start or resume this thread
+ *
+ * @param args The arguments to send as return values to {@link #yield(Varargs)}
+ * @return {@link Varargs} provided as arguments to {@link #yield(Varargs)}
+ */
+ public Varargs resume(Varargs args) {
+ if (this.state.status > STATUS_SUSPENDED)
+ return LuaValue.varargsOf(LuaValue.FALSE,
+ LuaValue.valueOf("cannot resume "+LuaThread.STATUS_NAMES[this.state.status]+" coroutine"));
+ return state.lua_resume(this, args);
+ }
+
+ /* DAN200 START */
+ public void addChild( LuaThread thread ) {
+ this.children.addElement( new WeakReference( thread ) );
+ }
+
+ public Varargs abandon() {
+ if( this.state.status > STATUS_SUSPENDED ) {
+ return LuaValue.varargsOf( LuaValue.FALSE, LuaValue.valueOf( "cannot abandon " + STATUS_NAMES[this.state.status] + " coroutine" ) );
+ } else {
+ this.state.lua_abandon( this );
+
+ Enumeration it = this.children.elements();
+ while( it.hasMoreElements() ) {
+ WeakReference ref = (WeakReference)it.nextElement();
+ LuaThread thread = (LuaThread)ref.get();
+ if(thread != null && !thread.getStatus().equals("dead")) {
+ thread.abandon();
+ }
+ }
+
+ this.children.removeAllElements();
+ return LuaValue.varargsOf( new LuaValue[] { LuaValue.TRUE } );
+ }
+ }
+ /* DAN200 END */
+
+ static class State implements Runnable {
+ final WeakReference lua_thread;
+ final LuaValue function;
+ Varargs args = LuaValue.NONE;
+ Varargs result = LuaValue.NONE;
+ String error = null;
+ int status = LuaThread.STATUS_INITIAL;
+ /* DAN200 START */
+ boolean abandoned = false;
+ /* DAN200 END */
+
+ State(LuaThread lua_thread, LuaValue function) {
+ this.lua_thread = new WeakReference(lua_thread);
+ this.function = function;
+ }
+
+ public synchronized void run() {
+ 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;
+ this.notify();
+ }
+ }
+
+ synchronized Varargs lua_resume(LuaThread new_thread, Varargs args) {
+ LuaThread previous_thread = LuaThread.running_thread;
+ try {
+ LuaThread.running_thread = new_thread;
+ this.args = args;
+ if (this.status == STATUS_INITIAL) {
+ this.status = STATUS_RUNNING;
+ new Thread(this, "Coroutine-"+(++coroutine_count)).start();
+ } else {
+ this.notify();
+ }
+ previous_thread.state.status = STATUS_NORMAL;
+ this.status = STATUS_RUNNING;
+ this.wait();
+ 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 {
+ running_thread = previous_thread;
+ running_thread.state.status =STATUS_RUNNING;
+ this.args = LuaValue.NONE;
+ this.result = LuaValue.NONE;
+ this.error = null;
+ }
+ }
+
+ synchronized Varargs lua_yield(Varargs args) {
+ try {
+ this.result = args;
+ this.status = STATUS_SUSPENDED;
+ this.notify();
+ do {
+ this.wait(thread_orphan_check_interval);
+ /* DAN200 START */
+ //if (this.lua_thread.get() == null) {
+ if( this.abandoned || this.lua_thread.get() == null ) {
+ /* DAN200 END */
+ 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;
+ }
+ }
+
+ /* DAN200 START */
+ synchronized void lua_abandon(LuaThread thread) {
+ LuaThread current = LuaThread.running_thread;
+
+ try {
+ current.state.status = STATUS_NORMAL;
+ this.abandoned = true;
+ if(this.status == STATUS_INITIAL) {
+ this.status = STATUS_DEAD;
+ } else {
+ this.notify();
+ this.wait();
+ }
+ } catch (InterruptedException var7) {
+ this.status = STATUS_DEAD;
+ } finally {
+ current.state.status = STATUS_RUNNING;
+ this.args = LuaValue.NONE;
+ this.result = LuaValue.NONE;
+ this.error = null;
+ }
+ }
+ /* DAN200 END */
+ }
+
+ public static class CallStack {
+ final LuaFunction[] functions = new LuaFunction[MAX_CALLSTACK];
+ int calls = 0;
+
+ /**
+ * Method to indicate the start of a call
+ * @see DebugLib
+ */
+ final void onCall(LuaFunction function) {
+ functions[calls++] = function;
+ if (DebugLib.DEBUG_ENABLED)
+ DebugLib.debugOnCall(running_thread, calls, function);
+ }
+
+ /**
+ * Method to signal the end of a call
+ * @see DebugLib
+ */
+ public final void onReturn() {
+ functions[--calls] = null;
+ if (DebugLib.DEBUG_ENABLED)
+ DebugLib.debugOnReturn(running_thread, calls);
+ }
+
+ /**
+ * Get number of calls in stack
+ * @return number of calls in current call stack
+ * @see DebugLib
+ */
+ public final int getCallstackDepth() {
+ return calls;
+ }
+
+ /**
+ * Get the function at a particular level of the stack.
+ * @param level # of levels back from the top of the stack.
+ * @return LuaFunction, or null if beyond the stack limits.
+ */
+ LuaFunction getFunction(int level) {
+ return level>0 && level<=calls? functions[calls-level]: null;
+ }
+ }
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/LuaUserdata.java b/luaj-2.0.3/src/core/org/luaj/vm2/LuaUserdata.java
new file mode 100644
index 0000000000..cf2b7b2873
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/LuaUserdata.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+* 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;
+
+
+public class LuaUserdata extends LuaValue {
+
+ public final Object m_instance;
+ public LuaValue m_metatable;
+
+ public LuaUserdata(Object obj) {
+ m_instance = obj;
+ }
+
+ public LuaUserdata(Object obj, LuaValue metatable) {
+ m_instance = obj;
+ m_metatable = metatable;
+ }
+
+ public String tojstring() {
+ return String.valueOf(m_instance);
+ }
+
+ public int type() {
+ return LuaValue.TUSERDATA;
+ }
+
+ public String typename() {
+ return "userdata";
+ }
+
+ public int hashCode() {
+ return m_instance.hashCode();
+ }
+
+ public Object userdata() {
+ return m_instance;
+ }
+
+ public boolean isuserdata() { return true; }
+ public boolean isuserdata(Class c) { return c.isAssignableFrom(m_instance.getClass()); }
+ public Object touserdata() { return m_instance; }
+ public Object touserdata(Class c) { return c.isAssignableFrom(m_instance.getClass())? m_instance: null; }
+ public Object optuserdata(Object defval) { return m_instance; }
+ public Object optuserdata(Class c, Object defval) {
+ if (!c.isAssignableFrom(m_instance.getClass()))
+ typerror(c.getName());
+ return m_instance;
+ }
+
+ public LuaValue getmetatable() {
+ return m_metatable;
+ }
+
+ public LuaValue setmetatable(LuaValue metatable) {
+ this.m_metatable = metatable;
+ return this;
+ }
+
+ public Object checkuserdata() {
+ return m_instance;
+ }
+
+ public Object checkuserdata(Class c) {
+ if ( c.isAssignableFrom(m_instance.getClass()) )
+ return m_instance;
+ return typerror(c.getName());
+ }
+
+ public LuaValue get( LuaValue key ) {
+ return m_metatable!=null? gettable(this,key): NIL;
+ }
+
+ public void set( LuaValue key, LuaValue value ) {
+ if ( m_metatable==null || ! settable(this,key,value) )
+ error( "cannot set "+key+" for userdata" );
+ }
+
+ public boolean equals( Object val ) {
+ if ( this == val )
+ return true;
+ if ( ! (val instanceof LuaUserdata) )
+ return false;
+ LuaUserdata u = (LuaUserdata) val;
+ return m_instance.equals(u.m_instance);
+ }
+
+ // equality w/ metatable processing
+ public LuaValue eq( LuaValue val ) { return eq_b(val)? TRUE: FALSE; }
+ public boolean eq_b( LuaValue val ) {
+ if ( val.raweq(this) ) return true;
+ if ( m_metatable == null || !val.isuserdata() ) return false;
+ LuaValue valmt = val.getmetatable();
+ return valmt!=null && LuaValue.eqmtcall(this, m_metatable, val, valmt);
+ }
+
+ // equality w/o metatable processing
+ public boolean raweq( LuaValue val ) { return val.raweq(this); }
+ public boolean raweq( LuaUserdata val ) {
+ return this == val || (m_metatable == val.m_metatable && m_instance.equals(val.m_instance));
+ }
+
+ // __eq metatag processing
+ public boolean eqmt( LuaValue val ) {
+ return m_metatable!=null && val.isuserdata()? LuaValue.eqmtcall(this, m_metatable, val, val.getmetatable()): false;
+ }
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/LuaValue.java b/luaj-2.0.3/src/core/org/luaj/vm2/LuaValue.java
new file mode 100644
index 0000000000..76907b7540
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/LuaValue.java
@@ -0,0 +1,3648 @@
+/*******************************************************************************
+* Copyright (c) 2009-2011 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;
+
+
+/**
+ * Base class for all concrete lua type values.
+ *
+ * Establishes base implementations for all the operations on lua types.
+ * This allows Java clients to deal essentially with one type for all Java values, namely {@link LuaValue}.
+ *
+ * Constructors are provided as static methods for common Java types, such as
+ * {@link LuaValue#valueOf(int)} or {@link LuaValue#valueOf(String)}
+ * to allow for instance pooling.
+ *
+ * Constants are defined for the lua values
+ * {@link #NIL}, {@link #TRUE}, and {@link #FALSE}.
+ * A constant {@link #NONE} is defined which is a {@link Varargs} list having no values.
+ *
+ * Operations are performed on values directly via their Java methods.
+ * For example, the following code divides two numbers:
+ *
+ * Field access and function calls are similar, with common overloads to simplify Java usage:
+ *
+ * To supply variable arguments or get multiple return values, use
+ * {@link invoke(Varargs)} or {@link invokemethod(LuaValue, Varargs)} methods:
+ *
+ * To load and run a script, {@link LoadState} is used:
+ *
+ * although {@code require} could also be used:
+ *
+ * In general a {@link LuaError} may be thrown on any operation when the
+ * types supplied to any operation are illegal from a lua perspective.
+ * Examples could be attempting to concatenate a NIL value, or attempting arithmetic
+ * on values that are not number.
+ *
+ * There are several methods for preinitializing tables, such as:
+ *
+ * Predefined constants exist for the standard lua type constants
+ * {@link TNIL}, {@link TBOOLEAN}, {@link TLIGHTUSERDATA}, {@link TNUMBER}, {@link TSTRING},
+ * {@link TTABLE}, {@link TFUNCTION}, {@link TUSERDATA}, {@link TTHREAD},
+ * and extended lua type constants
+ * {@link TINT}, {@link TNONE}, {@link TVALUE}
+ *
+ * Predefined constants exist for all strings used as metatags:
+ * {@link INDEX}, {@link NEWINDEX}, {@link CALL}, {@link MODE}, {@link METATABLE},
+ * {@link ADD}, {@link SUB}, {@link DIV}, {@link MUL}, {@link POW},
+ * {@link MOD}, {@link UNM}, {@link LEN}, {@link EQ}, {@link LT},
+ * {@link LE}, {@link TOSTRING}, and {@link CONCAT}.
+ *
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see LoadState
+ * @see Varargs
+ */
+abstract
+public class LuaValue extends Varargs {
+
+
+ /** Type enumeration constant for lua numbers that are ints, for compatibility with lua 5.1 number patch only */
+ public static final int TINT = (-2);
+
+ /** Type enumeration constant for lua values that have no type, for example weak table entries */
+ public static final int TNONE = (-1);
+
+ /** Type enumeration constant for lua nil */
+ public static final int TNIL = 0;
+
+ /** Type enumeration constant for lua booleans */
+ public static final int TBOOLEAN = 1;
+
+ /** Type enumeration constant for lua light userdata, for compatibility with C-based lua only */
+ public static final int TLIGHTUSERDATA = 2;
+
+ /** Type enumeration constant for lua numbers */
+ public static final int TNUMBER = 3;
+
+ /** Type enumeration constant for lua strings */
+ public static final int TSTRING = 4;
+
+ /** Type enumeration constant for lua tables */
+ public static final int TTABLE = 5;
+
+ /** Type enumeration constant for lua functions */
+ public static final int TFUNCTION = 6;
+
+ /** Type enumeration constant for lua userdatas */
+ public static final int TUSERDATA = 7;
+
+ /** Type enumeration constant for lua threads */
+ public static final int TTHREAD = 8;
+
+ /** Type enumeration constant for unknown values, for compatibility with C-based lua only */
+ public static final int TVALUE = 9;
+
+ /** String array constant containing names of each of the lua value types
+ * @see #type()
+ * @see #typename()
+ */
+ public static final String[] TYPE_NAMES = {
+ "nil",
+ "boolean",
+ "lightuserdata",
+ "number",
+ "string",
+ "table",
+ "function",
+ "userdata",
+ "thread",
+ "value",
+ };
+
+ /** LuaValue constant corresponding to lua {@code nil} */
+ public static final LuaValue NIL = LuaNil._NIL;
+
+ /** LuaBoolean constant corresponding to lua {@code true} */
+ public static final LuaBoolean TRUE = LuaBoolean._TRUE;
+
+ /** LuaBoolean constant corresponding to lua {@code false} */
+ public static final LuaBoolean FALSE = LuaBoolean._FALSE;
+
+ /** LuaValue constant corresponding to a {@link Varargs} list of no values */
+ public static final LuaValue NONE = None._NONE;
+
+ /** LuaValue number constant equal to 0 */
+ public static final LuaNumber ZERO = LuaInteger.valueOf(0);
+
+ /** LuaValue number constant equal to 1 */
+ public static final LuaNumber ONE = LuaInteger.valueOf(1);
+
+ /** LuaValue number constant equal to -1 */
+ public static final LuaNumber MINUSONE = LuaInteger.valueOf(-1);
+
+ /** LuaValue array constant with no values */
+ public static final LuaValue[] NOVALS = {};
+
+
+ /** LuaString constant with value "__index" for use as metatag */
+ public static final LuaString INDEX = valueOf("__index");
+
+ /** LuaString constant with value "__newindex" for use as metatag */
+ public static final LuaString NEWINDEX = valueOf("__newindex");
+
+ /** LuaString constant with value "__call" for use as metatag */
+ public static final LuaString CALL = valueOf("__call");
+
+ /** LuaString constant with value "__mode" for use as metatag */
+ public static final LuaString MODE = valueOf("__mode");
+
+ /** LuaString constant with value "__metatable" for use as metatag */
+ public static final LuaString METATABLE = valueOf("__metatable");
+
+ /** LuaString constant with value "__add" for use as metatag */
+ public static final LuaString ADD = valueOf("__add");
+
+ /** LuaString constant with value "__sub" for use as metatag */
+ public static final LuaString SUB = valueOf("__sub");
+
+ /** LuaString constant with value "__div" for use as metatag */
+ public static final LuaString DIV = valueOf("__div");
+
+ /** LuaString constant with value "__mul" for use as metatag */
+ public static final LuaString MUL = valueOf("__mul");
+
+ /** LuaString constant with value "__pow" for use as metatag */
+ public static final LuaString POW = valueOf("__pow");
+
+ /** LuaString constant with value "__mod" for use as metatag */
+ public static final LuaString MOD = valueOf("__mod");
+
+ /** LuaString constant with value "__unm" for use as metatag */
+ public static final LuaString UNM = valueOf("__unm");
+
+ /** LuaString constant with value "__len" for use as metatag */
+ public static final LuaString LEN = valueOf("__len");
+
+ /** LuaString constant with value "__eq" for use as metatag */
+ public static final LuaString EQ = valueOf("__eq");
+
+ /** LuaString constant with value "__lt" for use as metatag */
+ public static final LuaString LT = valueOf("__lt");
+
+ /** LuaString constant with value "__le" for use as metatag */
+ public static final LuaString LE = valueOf("__le");
+
+ /** LuaString constant with value "__tostring" for use as metatag */
+ public static final LuaString TOSTRING = valueOf("__tostring");
+
+ /** LuaString constant with value "__concat" for use as metatag */
+ public static final LuaString CONCAT = valueOf("__concat");
+
+ /** LuaString constant with value "" */
+ public static final LuaString EMPTYSTRING = valueOf("");
+
+ /** Limit on lua stack size */
+ private static int MAXSTACK = 250;
+
+ /** Array of {@link NIL} values to optimize filling stacks using System.arraycopy().
+ * Must not be modified.
+ */
+ public static final LuaValue[] NILS = new LuaValue[MAXSTACK];
+ static {
+ for ( int i=0; i
+ * No attempt to convert from string will be made by this call.
+ * @return true if this is a {@code LuaInteger},
+ * otherwise false
+ * @see #isint()
+ * @see #isnumber()
+ * @see #tonumber()
+ * @see #TNUMBER
+ */
+ public boolean isinttype() { return false; }
+
+ /** Check if {@code this} is a {@code number} and is representable by java long
+ * without rounding or truncation
+ * @return true if this is a {@code number}
+ * meaning derives from {@link LuaNumber}
+ * or derives from {@link LuaString} and is convertible to a number,
+ * and can be represented by long,
+ * otherwise false
+ * @see #tonumber()
+ * @see #checklong()
+ * @see #optlong(long)
+ * @see #TNUMBER
+ */
+ public boolean islong() { return false; }
+
+ /** Check if {@code this} is {@code nil}
+ * @return true if this is {@code nil}, otherwise false
+ * @see #NIL
+ * @see #NONE
+ * @see #checknotnil()
+ * @see #optvalue(LuaValue)
+ * @see Varargs#isnoneornil(int)
+ * @see #TNIL
+ * @see #TNONE
+ */
+ public boolean isnil() { return false; }
+
+ /** Check if {@code this} is a {@code number}
+ * @return true if this is a {@code number},
+ * meaning derives from {@link LuaNumber}
+ * or derives from {@link LuaString} and is convertible to a number,
+ * otherwise false
+ * @see #tonumber()
+ * @see #checknumber()
+ * @see #optnumber(LuaNumber)
+ * @see #TNUMBER
+ */
+ public boolean isnumber() { return false; } // may convert from string
+
+ /** Check if {@code this} is a {@code string}
+ * @return true if this is a {@code string},
+ * meaning derives from {@link LuaString} or {@link LuaNumber},
+ * otherwise false
+ * @see #tostring()
+ * @see #checkstring()
+ * @see #optstring(LuaString)
+ * @see #TSTRING
+ */
+ public boolean isstring() { return false; }
+
+ /** Check if {@code this} is a {@code thread}
+ * @return true if this is a {@code thread}, otherwise false
+ * @see #checkthread()
+ * @see #optthread(LuaThread)
+ * @see #TTHREAD
+ */
+ public boolean isthread() { return false; }
+
+ /** Check if {@code this} is a {@code table}
+ * @return true if this is a {@code table}, otherwise false
+ * @see #checktable()
+ * @see #opttable(LuaTable)
+ * @see #TTABLE
+ */
+ public boolean istable() { return false; }
+
+ /** Check if {@code this} is a {@code userdata}
+ * @return true if this is a {@code userdata}, otherwise false
+ * @see #isuserdata(Class)
+ * @see #touserdata()
+ * @see #checkuserdata()
+ * @see #optuserdata(Object)
+ * @see #TUSERDATA
+ */
+ public boolean isuserdata() { return false; }
+
+ /** Check if {@code this} is a {@code userdata} of type {@code c}
+ * @param c Class to test instance against
+ * @return true if this is a {@code userdata}
+ * and the instance is assignable to {@code c},
+ * otherwise false
+ * @see #isuserdata()
+ * @see #touserdata(Class)
+ * @see #checkuserdata(Class)
+ * @see #optuserdata(Object,Class)
+ * @see #TUSERDATA
+ */
+ public boolean isuserdata(Class c) { return false; }
+
+ /** Convert to boolean false if {@link #NIL} or {@link FALSE}, true if anything else
+ * @return Value cast to byte if number or string convertible to number, otherwise 0
+ * @see #optboolean(boolean)
+ * @see #checkboolean()
+ * @see #isboolean()
+ * @see TBOOLEAN
+ */
+ public boolean toboolean() { return true; }
+
+ /** Convert to byte if numeric, or 0 if not.
+ * @return Value cast to byte if number or string convertible to number, otherwise 0
+ * @see #toint()
+ * @see #todouble()
+ * @see #optbyte(byte)
+ * @see #checknumber()
+ * @see #isnumber()
+ * @see TNUMBER
+ */
+ public byte tobyte() { return 0; }
+
+ /** Convert to char if numeric, or 0 if not.
+ * @return Value cast to char if number or string convertible to number, otherwise 0
+ * @see #toint()
+ * @see #todouble()
+ * @see #optchar(char)
+ * @see #checknumber()
+ * @see #isnumber()
+ * @see TNUMBER
+ */
+ public char tochar() { return 0; }
+
+ /** Convert to double if numeric, or 0 if not.
+ * @return Value cast to double if number or string convertible to number, otherwise 0
+ * @see #toint()
+ * @see #tobyte()
+ * @see #tochar()
+ * @see #toshort()
+ * @see #tolong()
+ * @see #tofloat()
+ * @see #optdouble(double)
+ * @see #checknumber()
+ * @see #isnumber()
+ * @see TNUMBER
+ */
+ public double todouble() { return 0; }
+
+ /** Convert to float if numeric, or 0 if not.
+ * @return Value cast to float if number or string convertible to number, otherwise 0
+ * @see #toint()
+ * @see #todouble()
+ * @see #optfloat(float)
+ * @see #checknumber()
+ * @see #isnumber()
+ * @see TNUMBER
+ */
+ public float tofloat() { return 0; }
+
+ /** Convert to int if numeric, or 0 if not.
+ * @return Value cast to int if number or string convertible to number, otherwise 0
+ * @see #tobyte()
+ * @see #tochar()
+ * @see #toshort()
+ * @see #tolong()
+ * @see #tofloat()
+ * @see #todouble()
+ * @see #optint(int)
+ * @see #checknumber()
+ * @see #isnumber()
+ * @see TNUMBER
+ */
+ public int toint() { return 0; }
+
+ /** Convert to long if numeric, or 0 if not.
+ * @return Value cast to long if number or string convertible to number, otherwise 0
+ * @see #isint()
+ * @see #isinttype()
+ * @see #toint()
+ * @see #todouble()
+ * @see #optlong(long)
+ * @see #checknumber()
+ * @see #isnumber()
+ * @see TNUMBER
+ */
+ public long tolong() { return 0; }
+
+ /** Convert to short if numeric, or 0 if not.
+ * @return Value cast to short if number or string convertible to number, otherwise 0
+ * @see #toint()
+ * @see #todouble()
+ * @see #optshort(short)
+ * @see #checknumber()
+ * @see #isnumber()
+ * @see TNUMBER
+ */
+ public short toshort() { return 0; }
+
+ /** Convert to human readable String for any type.
+ * @return String for use by human readers based on type.
+ * @see #tostring()
+ * @see #optjstring(String)
+ * @see #checkjstring()
+ * @see #isstring()
+ * @see TSTRING
+ */
+ public String tojstring() { return typename() + ": " + Integer.toHexString(hashCode()); }
+
+ /** Convert to userdata instance, or null.
+ * @return userdata instance if userdata, or null if not {@link LuaUserdata}
+ * @see #optuserdata(Object)
+ * @see #checkuserdata()
+ * @see #isuserdata()
+ * @see #TUSERDATA
+ */
+ public Object touserdata() { return null; }
+
+ /** Convert to userdata instance if specific type, or null.
+ * @return userdata instance if is a userdata whose instance derives from {@code c},
+ * or null if not {@link LuaUserdata}
+ * @see #optuserdata(Class,Object)
+ * @see #checkuserdata(Class)
+ * @see #isuserdata(Class)
+ * @see #TUSERDATA
+ */
+ public Object touserdata(Class c) { return null; }
+
+ /**
+ * Convert the value to a human readable string using {@link #tojstring()}
+ * @return String value intended to be human readible.
+ * @see #tostring()
+ * @see #tojstring()
+ * @see #optstring(LuaString)
+ * @see #checkstring()
+ * @see #toString()
+ */
+ public String toString() { return tojstring(); }
+
+ /** Conditionally convert to lua number without throwing errors.
+ *
+ * In lua all numbers are strings, but not all strings are numbers.
+ * This function will return
+ * the {@link LuaValue} {@code this} if it is a number
+ * or a string convertible to a number,
+ * and {@link NIL} for all other cases.
+ *
+ * This allows values to be tested for their "numeric-ness" without
+ * the penalty of throwing exceptions,
+ * nor the cost of converting the type and creating storage for it.
+ * @return {@code this} if it is a {@link LuaNumber}
+ * or {@link LuaString} that can be converted to a number,
+ * otherwise {@link #NIL}
+ * @see #tostring()
+ * @see #optnumber(LuaNumber)
+ * @see #checknumber()
+ * @see #toint()
+ * @see #todouble()
+ */
+ public LuaValue tonumber() { return NIL; }
+
+ /** Conditionally convert to lua string without throwing errors.
+ *
+ * In lua all numbers are strings, so this function will return
+ * the {@link LuaValue} {@code this} if it is a string or number,
+ * and {@link NIL} for all other cases.
+ *
+ * This allows values to be tested for their "string-ness" without
+ * the penalty of throwing exceptions.
+ * @return {@code this} if it is a {@link LuaString} or {@link LuaNumber},
+ * otherwise {@link NIL}
+ * @see #tonumber()
+ * @see #tojstring()
+ * @see #optstring(LuaString)
+ * @see #checkstring()
+ * @see #toString()
+ */
+ public LuaValue tostring() { return NIL; }
+
+ /** Check that optional argument is a boolean and return its boolean value
+ * @param defval boolean value to return if {@code this} is nil or none
+ * @return {@code this} cast to boolean if a {@LuaBoolean},
+ * {@code defval} if nil or none,
+ * throws {@link LuaError} otherwise
+ * @throws LuaError if was not a boolean or nil or none.
+ * @see #checkboolean()
+ * @see #isboolean()
+ * @see #TBOOLEAN
+ */
+ public boolean optboolean(boolean defval) { argerror("boolean"); return false; }
+
+ /** Check that optional argument is a closure and return as {@link LuaClosure}
+ *
+ * A {@link LuaClosure} is a {@LuaFunction} that executes lua byteccode.
+ * @param defval {@link LuaClosure} to return if {@code this} is nil or none
+ * @return {@code this} cast to {@link LuaClosure} if a function,
+ * {@code defval} if nil or none,
+ * throws {@link LuaError} otherwise
+ * @throws LuaError if was not a closure or nil or none.
+ * @see #checkclosure()
+ * @see #isclosure()
+ * @see #TFUNCTION
+ */
+ public LuaClosure optclosure(LuaClosure defval) { argerror("closure"); return null; }
+
+ /** Check that optional argument is a number or string convertible to number and return as double
+ * @param defval double to return if {@code this} is nil or none
+ * @return {@code this} cast to double if numeric,
+ * {@code defval} if nil or none,
+ * throws {@link LuaError} otherwise
+ * @throws LuaError if was not numeric or nil or none.
+ * @see #optint(int)
+ * @see #optinteger(LuaInteger)
+ * @see #checkdouble()
+ * @see #todouble()
+ * @see #tonumber()
+ * @see #isnumber()
+ * @see #TNUMBER
+ */
+ public double optdouble(double defval) { argerror("double"); return 0; }
+
+ /** Check that optional argument is a function and return as {@link LuaFunction}
+ *
+ * A {@link LuaFunction} may either be a Java function that implements
+ * functionality directly in Java,
+ * or a {@link LuaClosure}
+ * which is a {@link LuaFunction} that executes lua bytecode.
+ * @param defval {@link LuaFunction} to return if {@code this} is nil or none
+ * @return {@code this} cast to {@link LuaFunction} if a function,
+ * {@code defval} if nil or none,
+ * throws {@link LuaError} otherwise
+ * @throws LuaError if was not a function or nil or none.
+ * @see #checkfunction()
+ * @see #isfunction()
+ * @see #TFUNCTION
+ */
+ public LuaFunction optfunction(LuaFunction defval) { argerror("function"); return null; }
+
+ /** Check that optional argument is a number or string convertible to number and return as int
+ * @param defval int to return if {@code this} is nil or none
+ * @return {@code this} cast to int if numeric,
+ * {@code defval} if nil or none,
+ * throws {@link LuaError} otherwise
+ * @throws LuaError if was not numeric or nil or none.
+ * @see #optdouble(double)
+ * @see #optlong(long)
+ * @see #optinteger(LuaInteger)
+ * @see #checkint()
+ * @see #toint()
+ * @see #tonumber()
+ * @see #isnumber()
+ * @see #TNUMBER
+ */
+ public int optint(int defval) { argerror("int"); return 0; }
+
+ /** Check that optional argument is a number or string convertible to number and return as {@link LuaInteger}
+ * @param defval {@link LuaInteger} to return if {@code this} is nil or none
+ * @return {@code this} converted and wrapped in {@link LuaInteger} if numeric,
+ * {@code defval} if nil or none,
+ * throws {@link LuaError} otherwise
+ * @throws LuaError if was not numeric or nil or none.
+ * @see #optdouble(double)
+ * @see #optint(int)
+ * @see #checkint()
+ * @see #toint()
+ * @see #tonumber()
+ * @see #isnumber()
+ * @see #TNUMBER
+ */
+ public LuaInteger optinteger(LuaInteger defval) { argerror("integer"); return null; }
+
+ /** Check that optional argument is a number or string convertible to number and return as long
+ * @param defval long to return if {@code this} is nil or none
+ * @return {@code this} cast to long if numeric,
+ * {@code defval} if nil or none,
+ * throws {@link LuaError} otherwise
+ * @throws LuaError if was not numeric or nil or none.
+ * @see #optdouble(double)
+ * @see #optint(int)
+ * @see #checkint()
+ * @see #toint()
+ * @see #tonumber()
+ * @see #isnumber()
+ * @see #TNUMBER
+ */
+ public long optlong(long defval) { argerror("long"); return 0; }
+
+ /** Check that optional argument is a number or string convertible to number and return as {@link LuaNumber}
+ * @param defval {@link LuaNumber} to return if {@code this} is nil or none
+ * @return {@code this} cast to {@link LuaNumber} if numeric,
+ * {@code defval} if nil or none,
+ * throws {@link LuaError} otherwise
+ * @throws LuaError if was not numeric or nil or none.
+ * @see #optdouble(double)
+ * @see #optlong(long)
+ * @see #optint(int)
+ * @see #checkint()
+ * @see #toint()
+ * @see #tonumber()
+ * @see #isnumber()
+ * @see #TNUMBER
+ */
+ public LuaNumber optnumber(LuaNumber defval) { argerror("number"); return null; }
+
+ /** Check that optional argument is a string or number and return as Java String
+ * @param defval {@link LuaString} to return if {@code this} is nil or none
+ * @return {@code this} converted to String if a string or number,
+ * {@code defval} if nil or none,
+ * throws {@link LuaError} if some other type
+ * @throws LuaError if was not a string or number or nil or none.
+ * @see #tojstring()
+ * @see #optstring(LuaString)
+ * @see #checkjstring()
+ * @see #toString()
+ * @see #TSTRING
+ */
+ public String optjstring(String defval) { argerror("String"); return null; }
+
+ /** Check that optional argument is a string or number and return as {@link LuaString}
+ * @param defval {@link LuaString} to return if {@code this} is nil or none
+ * @return {@code this} converted to {@link LuaString} if a string or number,
+ * {@code defval} if nil or none,
+ * throws {@link LuaError} if some other type
+ * @throws LuaError if was not a string or number or nil or none.
+ * @see #tojstring()
+ * @see #optjstring(String)
+ * @see #checkstring()
+ * @see #toString()
+ * @see #TSTRING
+ */
+ public LuaString optstring(LuaString defval) { argerror("string"); return null; }
+
+ /** Check that optional argument is a table and return as {@link LuaTable}
+ * @param defval {@link LuaTable} to return if {@code this} is nil or none
+ * @return {@code this} cast to {@link LuaTable} if a table,
+ * {@code defval} if nil or none,
+ * throws {@link LuaError} if some other type
+ * @throws LuaError if was not a table or nil or none.
+ * @see #checktable()
+ * @see #istable()
+ * @see #TTABLE
+ */
+ public LuaTable opttable(LuaTable defval) { argerror("table"); return null; }
+
+ /** Check that optional argument is a thread and return as {@link LuaThread}
+ * @param defval {@link LuaThread} to return if {@code this} is nil or none
+ * @return {@code this} cast to {@link LuaTable} if a thread,
+ * {@code defval} if nil or none,
+ * throws {@link LuaError} if some other type
+ * @throws LuaError if was not a thread or nil or none.
+ * @see #checkthread()
+ * @see #isthread()
+ * @see #TTHREAD
+ */
+ public LuaThread optthread(LuaThread defval) { argerror("thread"); return null; }
+
+ /** Check that optional argument is a userdata and return the Object instance
+ * @param defval Object to return if {@code this} is nil or none
+ * @return Object instance of the userdata if a {@link LuaUserdata},
+ * {@code defval} if nil or none,
+ * throws {@link LuaError} if some other type
+ * @throws LuaError if was not a userdata or nil or none.
+ * @see #checkuserdata()
+ * @see #isuserdata()
+ * @see #optuserdata(Class, Object)
+ * @see #TUSERDATA
+ */
+ public Object optuserdata(Object defval) { argerror("object"); return null; }
+
+ /** Check that optional argument is a userdata whose instance is of a type
+ * and return the Object instance
+ * @param c Class to test userdata instance against
+ * @param defval Object to return if {@code this} is nil or none
+ * @return Object instance of the userdata if a {@link LuaUserdata} and instance is assignable to {@code c},
+ * {@code defval} if nil or none,
+ * throws {@link LuaError} if some other type
+ * @throws LuaError if was not a userdata whose instance is assignable to {@code c} or nil or none.
+ * @see #checkuserdata(Class)
+ * @see #isuserdata(Class)
+ * @see #optuserdata(Object)
+ * @see #TUSERDATA
+ */
+ public Object optuserdata(Class c, Object defval) { argerror(c.getName()); return null; }
+
+ /** Perform argument check that this is not nil or none.
+ * @param defval {@link LuaValue} to return if {@code this} is nil or none
+ * @return {@code this} if not nil or none, else {@code defval}
+ * @see #NIL
+ * @see #NONE
+ * @see #isnil()
+ * @see Varargs#isnoneornil(int)
+ * @see #TNIL
+ * @see #TNONE
+ */
+ public LuaValue optvalue(LuaValue defval) { return this; }
+
+
+ /** Check that the value is a {@link LuaBoolean},
+ * or throw {@link LuaError} if not
+ * @return boolean value for {@code this} if it is a {@link LuaBoolean}
+ * @throws LuaError if not a {@link LuaBoolean}
+ * @see #optboolean(boolean)
+ * @see #TBOOLEAN
+ */
+ public boolean checkboolean() { argerror("boolean"); return false; }
+
+ /** Check that the value is a {@link LuaClosure} ,
+ * or throw {@link LuaError} if not
+ *
+ * {@link LuaClosure} is a subclass of {@LuaFunction} that interprets lua bytecode.
+ * @return {@code this} cast as {@link LuaClosure}
+ * @throws LuaError if not a {@link LuaClosure}
+ * @see #checkfunction()
+ * @see #optclosure(LuaClosure)
+ * @see #isclosure()
+ * @see #TFUNCTION
+ */
+ public LuaClosure checkclosure() { argerror("closure"); return null; }
+
+ /** Check that the value is numeric and return the value as a double,
+ * or throw {@link LuaError} if not numeric
+ *
+ * Values that are {@link LuaNumber} and values that are {@link LuaString}
+ * that can be converted to a number will be converted to double.
+ * @return value cast to a double if numeric
+ * @throws LuaError if not a {@link LuaNumber} or is a {@link LuaString} that can't be converted to number
+ * @see #checkint()
+ * @see #checkinteger()
+ * @see #checklong()
+ * @see #optdouble(double)
+ * @see #TNUMBER
+ */
+ public double checkdouble() { argerror("double"); return 0; }
+
+ /** Check that the value is a function , or throw {@link LuaError} if not
+ *
+ * A function is considered anything whose {@link type()} returns {@link TFUNCTION}.
+ * In practice it will be either a built-in Java function, typically deriving from
+ * {@link LuaFunction} or a {@link LuaClosure} which represents lua source compiled
+ * into lua bytecode.
+ * @return {@code this} if if a lua function or closure
+ * @throws LuaError if not a function
+ * @see #checkclosure()
+ */
+ public LuaValue checkfunction() { argerror("function"); return null; }
+
+ /** Check that the value is numeric, and convert and cast value to int, or throw {@link LuaError} if not numeric
+ *
+ * Values that are {@link LuaNumber} will be cast to int and may lose precision.
+ * Values that are {@link LuaString} that can be converted to a number will be converted,
+ * then cast to int, so may also lose precision.
+ * @return value cast to a int if numeric
+ * @throws LuaError if not a {@link LuaNumber} or is a {@link LuaString} that can't be converted to number
+ * @see #checkinteger()
+ * @see #checklong()
+ * @see #checkdouble()
+ * @see #optint(int)
+ * @see #TNUMBER
+ */
+ public int checkint() { argerror("int"); return 0; }
+
+ /** Check that the value is numeric, and convert and cast value to int, or throw {@link LuaError} if not numeric
+ *
+ * Values that are {@link LuaNumber} will be cast to int and may lose precision.
+ * Values that are {@link LuaString} that can be converted to a number will be converted,
+ * then cast to int, so may also lose precision.
+ * @return value cast to a int and wrapped in {@link LuaInteger} if numeric
+ * @throws LuaError if not a {@link LuaNumber} or is a {@link LuaString} that can't be converted to number
+ * @see #checkint()
+ * @see #checklong()
+ * @see #checkdouble()
+ * @see #optinteger(LuaInteger)
+ * @see #TNUMBER
+ */
+ public LuaInteger checkinteger() { argerror("integer"); return null; }
+
+ /** Check that the value is numeric, and convert and cast value to long, or throw {@link LuaError} if not numeric
+ *
+ * Values that are {@link LuaNumber} will be cast to long and may lose precision.
+ * Values that are {@link LuaString} that can be converted to a number will be converted,
+ * then cast to long, so may also lose precision.
+ * @return value cast to a long if numeric
+ * @throws LuaError if not a {@link LuaNumber} or is a {@link LuaString} that can't be converted to number
+ * @see #checkint()
+ * @see #checkinteger()
+ * @see #checkdouble()
+ * @see #optlong(long)
+ * @see #TNUMBER
+ */
+ public long checklong() { argerror("long"); return 0; }
+
+ /** Check that the value is numeric, and return as a LuaNumber if so, or throw {@link LuaError}
+ *
+ * Values that are {@link LuaString} that can be converted to a number will be converted and returned.
+ * @return value as a {@link LuaNumber} if numeric
+ * @throws LuaError if not a {@link LuaNumber} or is a {@link LuaString} that can't be converted to number
+ * @see #checkint()
+ * @see #checkinteger()
+ * @see #checkdouble()
+ * @see #checklong()
+ * @see #optnumber(LuaNumber)
+ * @see #TNUMBER
+ */
+ public LuaNumber checknumber() { argerror("number"); return null; }
+
+ /** Check that the value is numeric, and return as a LuaNumber if so, or throw {@link LuaError}
+ *
+ * Values that are {@link LuaString} that can be converted to a number will be converted and returned.
+ * @param msg String message to supply if conversion fails
+ * @return value as a {@link LuaNumber} if numeric
+ * @throws LuaError if not a {@link LuaNumber} or is a {@link LuaString} that can't be converted to number
+ * @see #checkint()
+ * @see #checkinteger()
+ * @see #checkdouble()
+ * @see #checklong()
+ * @see #optnumber(LuaNumber)
+ * @see #TNUMBER
+ */
+ public LuaNumber checknumber(String msg) { throw new LuaError(msg); }
+
+ /** Convert this value to a Java String.
+ *
+ * The string representations here will roughly match what is produced by the
+ * C lua distribution, however hash codes have no relationship,
+ * and there may be differences in number formatting.
+ * @return String representation of the value
+ * @see #checkstring()
+ * @see #optjstring(String)
+ * @see #tojstring()
+ * @see #isstring
+ * @see #TSTRING
+ */
+ public String checkjstring() { argerror("string"); return null; }
+
+ /** Check that this is a lua string, or throw {@link LuaError} if it is not.
+ *
+ * In lua all numbers are strings, so this will succeed for
+ * anything that derives from {@link LuaString} or {@link LuaNumber}.
+ * Numbers will be converted to {@link LuaString}.
+ *
+ * @return {@link LuaString} representation of the value if it is a {@link LuaString} or {@link LuaNumber}
+ * @throws LuaError if {@code this} is not a {@link LuaTable}
+ * @see #checkjstring()
+ * @see #optstring(LuaString)
+ * @see #tostring()
+ * @see #isstring()
+ * @see #TSTRING
+ */
+ public LuaString checkstring() { argerror("string"); return null; }
+
+ /** Check that this is a {@link LuaTable}, or throw {@link LuaError} if it is not
+ * @return {@code this} if it is a {@link LuaTable}
+ * @throws LuaError if {@code this} is not a {@link LuaTable}
+ * @see #istable()
+ * @see #opttable(LuaTable)
+ * @see #TTABLE
+ */
+ public LuaTable checktable() { argerror("table"); return null; }
+
+ /** Check that this is a {@link LuaThread}, or throw {@link LuaError} if it is not
+ * @return {@code this} if it is a {@link LuaThread}
+ * @throws LuaError if {@code this} is not a {@link LuaThread}
+ * @see #isthread()
+ * @see #optthread(LuaThread)
+ * @see #TTHREAD
+ */
+ public LuaThread checkthread() { argerror("thread"); return null; }
+
+ /** Check that this is a {@link LuaUserdata}, or throw {@link LuaError} if it is not
+ * @return {@code this} if it is a {@link LuaUserdata}
+ * @throws LuaError if {@code this} is not a {@link LuaUserdata}
+ * @see #isuserdata()
+ * @see #optuserdata(Object)
+ * @see #checkuserdata(Class)
+ * @see #TUSERDATA
+ */
+ public Object checkuserdata() { argerror("userdata"); return null; }
+
+ /** Check that this is a {@link LuaUserdata}, or throw {@link LuaError} if it is not
+ * @return {@code this} if it is a {@link LuaUserdata}
+ * @throws LuaError if {@code this} is not a {@link LuaUserdata}
+ * @see #isuserdata(Class)
+ * @see #optuserdata(Class, Object)
+ * @see #checkuserdata()
+ * @see #TUSERDATA
+ */
+ public Object checkuserdata(Class c) { argerror("userdata"); return null; }
+
+ /** Check that this is not the value {@link NIL}, or throw {@link LuaError} if it is
+ * @return {@code this} if it is not {@link NIL}
+ * @throws LuaError if {@code this} is {@link NIL}
+ * @see #optvalue(LuaValue)
+ */
+ public LuaValue checknotnil() { return this; }
+
+ /** Check that this is a valid key in a table index operation, or throw {@link LuaError} if not
+ * @return {@code this} if valid as a table key
+ * @throws LuaError if not valid as a table key
+ * @see #isnil()
+ * @see #isinttype()
+ */
+ public LuaValue checkvalidkey() { return this; }
+
+ /**
+ * Throw a {@link LuaError} with a particular message
+ * @param message String providing message details
+ * @throws LuaError in all cases
+ */
+ public static LuaValue error(String message) { throw new LuaError(message); }
+
+ /**
+ * Assert a condition is true, or throw a {@link LuaError} if not
+ * @param b condition to test
+ * @return returns no value when b is true, throws error not return if b is false
+ * @throws LuaError if b is not true
+ */
+ public static void assert_(boolean b,String msg) { if(!b) throw new LuaError(msg); }
+
+ /**
+ * Throw a {@link LuaError} indicating an invalid argument was supplied to a function
+ * @param expected String naming the type that was expected
+ * @throws LuaError in all cases
+ */
+ protected LuaValue argerror(String expected) { throw new LuaError("bad argument: "+expected+" expected, got "+typename()); }
+
+ /**
+ * Throw a {@link LuaError} indicating an invalid argument was supplied to a function
+ * @param iarg index of the argument that was invalid, first index is 1
+ * @param msg String providing information about the invalid argument
+ * @throws LuaError in all cases
+ */
+ public static LuaValue argerror(int iarg,String msg) { throw new LuaError("bad argument #"+iarg+": "+msg); }
+
+ /**
+ * Throw a {@link LuaError} indicating an invalid type was supplied to a function
+ * @param expected String naming the type that was expected
+ * @throws LuaError in all cases
+ */
+ protected LuaValue typerror(String expected) { throw new LuaError(expected+" expected, got "+typename()); }
+
+ /**
+ * Throw a {@link LuaError} indicating an operation is not implemented
+ * @throws LuaError in all cases
+ */
+ protected LuaValue unimplemented(String fun) { throw new LuaError("'"+fun+"' not implemented for "+typename()); }
+
+ /**
+ * Throw a {@link LuaError} indicating an illegal operation occurred,
+ * typically involved in managing weak references
+ * @throws LuaError in all cases
+ */
+ protected LuaValue illegal(String op,String typename) { throw new LuaError("illegal operation '"+op+"' for "+typename); }
+
+ /**
+ * Throw a {@link LuaError} based on the len operator,
+ * typically due to an invalid operand type
+ * @throws LuaError in all cases
+ */
+ protected LuaValue lenerror() { throw new LuaError("attempt to get length of "+typename()); }
+
+ /**
+ * Throw a {@link LuaError} based on an arithmetic error such as add, or pow,
+ * typically due to an invalid operand type
+ * @throws LuaError in all cases
+ */
+ protected LuaValue aritherror() { throw new LuaError("attempt to perform arithmetic on "+typename()); }
+
+ /**
+ * Throw a {@link LuaError} based on an arithmetic error such as add, or pow,
+ * typically due to an invalid operand type
+ * @param fun String description of the function that was attempted
+ * @throws LuaError in all cases
+ */
+ protected LuaValue aritherror(String fun) { throw new LuaError("attempt to perform arithmetic '"+fun+"' on "+typename()); }
+
+ /**
+ * Throw a {@link LuaError} based on a comparison error such as greater-than or less-than,
+ * typically due to an invalid operand type
+ * @param rhs String description of what was on the right-hand-side of the comparison that resulted in the error.
+ * @throws LuaError in all cases
+ */
+ protected LuaValue compareerror(String rhs) { throw new LuaError("attempt to compare "+typename()+" with "+rhs); }
+
+ /**
+ * Throw a {@link LuaError} based on a comparison error such as greater-than or less-than,
+ * typically due to an invalid operand type
+ * @param rhs Right-hand-side of the comparison that resulted in the error.
+ * @throws LuaError in all cases
+ */
+ protected LuaValue compareerror(LuaValue rhs) { throw new LuaError("attempt to compare "+typename()+" with "+rhs.typename()); }
+
+ /** Get a value in a table including metatag processing using {@link INDEX}.
+ * @param key the key to look up, must not be {@link NIL} or null
+ * @return {@link LuaValue} for that key, or {@link NIL} if not found and no metatag
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link INDEX} metatag,
+ * or key is {@link NIL}
+ * @see #get(int)
+ * @see #get(String)
+ * @see #rawget(LuaValue)
+ */
+ public LuaValue get( LuaValue key ) { return gettable(this,key); }
+
+ /** Get a value in a table including metatag processing using {@link INDEX}.
+ * @param key the key to look up
+ * @return {@link LuaValue} for that key, or {@link NIL} if not found
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link INDEX} metatag
+ * @see #get(LuaValue)
+ * @see #rawget(int)
+ */
+ public LuaValue get( int key ) { return get(LuaInteger.valueOf(key)); }
+
+ /** Get a value in a table including metatag processing using {@link INDEX}.
+ * @param key the key to look up, must not be null
+ * @return {@link LuaValue} for that key, or {@link NIL} if not found
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link INDEX} metatag
+ * @see #get(LuaValue)
+ * @see #rawget(String)
+ */
+ public LuaValue get( String key ) { return get(valueOf(key)); }
+
+ /** Set a value in a table without metatag processing using {@link NEWINDEX}.
+ * @param key the key to use, must not be {@link NIL} or null
+ * @param value the value to use, can be {@link NIL}, must not be null
+ * @throws LuaError if {@code this} is not a table,
+ * or key is {@link NIL},
+ * or there is no {@link NEWINDEX} metatag
+ */
+ public void set( LuaValue key, LuaValue value ) { settable(this, key, value); }
+
+ /** Set a value in a table without metatag processing using {@link NEWINDEX}.
+ * @param key the key to use
+ * @param value the value to use, can be {@link NIL}, must not be null
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link NEWINDEX} metatag
+ */
+ public void set( int key, LuaValue value ) { set(LuaInteger.valueOf(key), value ); }
+
+ /** Set a value in a table without metatag processing using {@link NEWINDEX}.
+ * @param key the key to use
+ * @param value the value to use, must not be null
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link NEWINDEX} metatag
+ */
+ public void set( int key, String value ) { set(key, valueOf(value) ); }
+
+ /** Set a value in a table without metatag processing using {@link NEWINDEX}.
+ * @param key the key to use, must not be {@link NIL} or null
+ * @param value the value to use, can be {@link NIL}, must not be null
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link NEWINDEX} metatag
+ */
+ public void set( String key, LuaValue value ) { set(valueOf(key), value ); }
+
+ /** Set a value in a table without metatag processing using {@link NEWINDEX}.
+ * @param key the key to use, must not be null
+ * @param value the value to use
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link NEWINDEX} metatag
+ */
+ public void set( String key, double value ) { set(valueOf(key), valueOf(value) ); }
+
+ /** Set a value in a table without metatag processing using {@link NEWINDEX}.
+ * @param key the key to use, must not be null
+ * @param value the value to use
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link NEWINDEX} metatag
+ */
+ public void set( String key, int value ) { set(valueOf(key), valueOf(value) ); }
+
+ /** Set a value in a table without metatag processing using {@link NEWINDEX}.
+ * @param key the key to use, must not be null
+ * @param value the value to use, must not be null
+ * @throws LuaError if {@code this} is not a table,
+ * or there is no {@link NEWINDEX} metatag
+ */
+ public void set( String key, String value ) { set(valueOf(key), valueOf(value) ); }
+
+ /** Get a value in a table without metatag processing.
+ * @param key the key to look up, must not be {@link NIL} or null
+ * @return {@link LuaValue} for that key, or {@link NIL} if not found
+ * @throws LuaError if {@code this} is not a table, or key is {@link NIL}
+ */
+ public LuaValue rawget( LuaValue key ) { return unimplemented("rawget"); }
+
+ /** Get a value in a table without metatag processing.
+ * @param key the key to look up
+ * @return {@link LuaValue} for that key, or {@link NIL} if not found
+ * @throws LuaError if {@code this} is not a table
+ */
+ public LuaValue rawget( int key ) { return rawget(valueOf(key)); }
+
+ /** Get a value in a table without metatag processing.
+ * @param key the key to look up, must not be null
+ * @return {@link LuaValue} for that key, or {@link NIL} if not found
+ * @throws LuaError if {@code this} is not a table
+ */
+ public LuaValue rawget( String key ) { return rawget(valueOf(key)); }
+
+ /** Set a value in a table without metatag processing.
+ * @param key the key to use, must not be {@link NIL} or null
+ * @param value the value to use, can be {@link NIL}, must not be null
+ * @throws LuaError if {@code this} is not a table, or key is {@link NIL}
+ */
+ public void rawset( LuaValue key, LuaValue value ) { unimplemented("rawset"); }
+
+ /** Set a value in a table without metatag processing.
+ * @param key the key to use
+ * @param value the value to use, can be {@link NIL}, must not be null
+ * @throws LuaError if {@code this} is not a table
+ */
+ public void rawset( int key, LuaValue value ) { rawset(valueOf(key),value); }
+
+ /** Set a value in a table without metatag processing.
+ * @param key the key to use
+ * @param value the value to use, can be {@link NIL}, must not be null
+ * @throws LuaError if {@code this} is not a table
+ */
+ public void rawset( int key, String value ) { rawset(key,valueOf(value)); }
+
+ /** Set a value in a table without metatag processing.
+ * @param key the key to use, must not be null
+ * @param value the value to use, can be {@link NIL}, must not be null
+ * @throws LuaError if {@code this} is not a table
+ */
+ public void rawset( String key, LuaValue value ) { rawset(valueOf(key),value); }
+
+ /** Set a value in a table without metatag processing.
+ * @param key the key to use, must not be null
+ * @param value the value to use
+ * @throws LuaError if {@code this} is not a table
+ */
+ public void rawset( String key, double value ) { rawset(valueOf(key),valueOf(value)); }
+
+ /** Set a value in a table without metatag processing.
+ * @param key the key to use, must not be null
+ * @param value the value to use
+ * @throws LuaError if {@code this} is not a table
+ */
+ public void rawset( String key, int value ) { rawset(valueOf(key),valueOf(value)); }
+
+ /** Set a value in a table without metatag processing.
+ * @param key the key to use, must not be null
+ * @param value the value to use, must not be null
+ * @throws LuaError if {@code this} is not a table
+ */
+ public void rawset( String key, String value ) { rawset(valueOf(key),valueOf(value)); }
+
+ /** Set list values in a table without invoking metatag processing
+ *
+ * Primarily used internally in response to a SETLIST bytecode.
+ * @param key0 the first key to set in the table
+ * @param values the list of values to set
+ * @throws LuaError if this is not a table.
+ */
+ public void rawsetlist( int key0, Varargs values ) { for ( int i=0, n=values.narg(); i
+ * To iterate over all key-value pairs in a table you can use
+ *
+ * To iterate over integer keys in a table you can use
+ *
+ * For {@link LuaTable} and {@link LuaUserdata} instances,
+ * the metatable returned is this instance metatable.
+ * For all other types, the class metatable value will be returned.
+ * @return metatable, or null if it there is none
+ * @see LuaBoolean#s_metatable
+ * @see LuaNumber#s_metatable
+ * @see LuaNil#s_metatable
+ * @see LuaFunction#s_metatable
+ * @see LuaThread#s_metatable
+ */
+ public LuaValue getmetatable() { return null; };
+
+ /**
+ * Set the metatable for this {@link LuaValue}
+ *
+ * For {@link LuaTable} and {@link LuaUserdata} instances, the metatable is per instance.
+ * For all other types, there is one metatable per type that can be set directly from java
+ * @param metatable {@link LuaValue} instance to serve as the metatable, or null to reset it.
+ * @return {@code this} to allow chaining of Java function calls
+ * @see LuaBoolean#s_metatable
+ * @see LuaNumber#s_metatable
+ * @see LuaNil#s_metatable
+ * @see LuaFunction#s_metatable
+ * @see LuaThread#s_metatable
+ */
+ public LuaValue setmetatable(LuaValue metatable) { return argerror("table"); }
+
+ /**
+ * Get the environemnt for an instance.
+ * @return {@link LuaValue} currently set as the instances environent.
+ */
+ public LuaValue getfenv() { typerror("function or thread"); return null; }
+
+ /**
+ * Set the environment on an object.
+ *
+ * Typically the environment is created once per application via a platform
+ * helper method such as {@link org.luaj.vm2.lib.jse.JsePlatform#standardGlobals()}
+ * However, any object can serve as an environment if it contains suitable metatag
+ * values to implement {@link #get(LuaValue)} to provide the environment values.
+ * @param env {@link LuaValue} (typically a {@link LuaTable}) containing the environment.
+ * @see org.luaj.vm2.lib.jme.JmePlatform
+ * @see org.luaj.vm2.lib.jse.JsePlatform
+ */
+ public void setfenv(LuaValue env) { typerror("function or thread"); }
+
+ /** Call {@link this} with 0 arguments, including metatag processing,
+ * and return only the first return value.
+ *
+ * If {@code this} is a {@link LuaFunction}, call it,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
+ *
+ * To call {@link this} as a method call, use {@link #method(LuaValue)} instead.
+ *
+ * @return First return value {@code (this())}, or {@link NIL} if there were none.
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call(LuaValue)
+ * @see #call(LuaValue,LuaValue)
+ * @see #call(LuaValue, LuaValue, LuaValue)
+ * @see #invoke()
+ * @see #method(String)
+ * @see #method(LuaValue)
+ */
+ public LuaValue call() { return callmt().call(this); }
+
+ /** Call {@link this} with 1 argument, including metatag processing,
+ * and return only the first return value.
+ *
+ * If {@code this} is a {@link LuaFunction}, call it,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
+ *
+ * To call {@link this} as a method call, use {@link #method(LuaValue)} instead.
+ *
+ * @param arg First argument to supply to the called function
+ * @return First return value {@code (this(arg))}, or {@link NIL} if there were none.
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call()
+ * @see #call(LuaValue,LuaValue)
+ * @see #call(LuaValue, LuaValue, LuaValue)
+ * @see #invoke(LuaValue)
+ * @see #method(String,LuaValue)
+ * @see #method(LuaValue,LuaValue)
+ */
+ public LuaValue call(LuaValue arg) { return callmt().call(this,arg); }
+
+ /** Call {@link this} with 2 arguments, including metatag processing,
+ * and return only the first return value.
+ *
+ * If {@code this} is a {@link LuaFunction}, call it,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
+ *
+ * To call {@link this} as a method call, use {@link #method(LuaValue)} instead.
+ *
+ * @param arg1 First argument to supply to the called function
+ * @param arg2 Second argument to supply to the called function
+ * @return First return value {@code (this(arg1,arg2))}, or {@link NIL} if there were none.
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call()
+ * @see #call(LuaValue)
+ * @see #call(LuaValue, LuaValue, LuaValue)
+ * @see #invoke(LuaValue,LuaValue)
+ * @see #method(String,LuaValue,LuaValue)
+ * @see #method(LuaValue,LuaValue,LuaValue)
+ */
+ public LuaValue call(LuaValue arg1, LuaValue arg2) { return callmt().call(this,arg1,arg2); }
+
+ /** Call {@link this} with 3 arguments, including metatag processing,
+ * and return only the first return value.
+ *
+ * If {@code this} is a {@link LuaFunction}, call it,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
+ *
+ * To call {@link this} as a method call, use {@link #method(LuaValue)} instead.
+ *
+ * @param arg1 First argument to supply to the called function
+ * @param arg2 Second argument to supply to the called function
+ * @param arg3 Second argument to supply to the called function
+ * @return First return value {@code (this(arg1,arg2,arg3))}, or {@link NIL} if there were none.
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call()
+ * @see #call(LuaValue)
+ * @see #call(LuaValue, LuaValue)
+ * @see #invoke(LuaValue,LuaValue, LuaValue)
+ * @see #invokemethod(String,Varargs)
+ * @see #invokemethod(LuaValue,Varargs)
+ */
+ public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) { return callmt().invoke(new LuaValue[]{this,arg1,arg2,arg3}).arg1(); }
+
+ /** Call named method on {@link this} with 0 arguments, including metatag processing,
+ * and return only the first return value.
+ *
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@link this} as an additional first argument.
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
+ *
+ * To call {@link this} as a plain call, use {@link #call()} instead.
+ *
+ * @param name Name of the method to look up for invocation
+ * @return All values returned from {@code this:name()} as a {@link Varargs} instance
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call()
+ * @see #invoke()
+ * @see #method(LuaValue)
+ * @see #method(String,LuaValue)
+ * @see #method(String,LuaValue,LuaValue)
+ */
+ public LuaValue method(String name) { return this.get(name).call(this); }
+
+ /** Call named method on {@link this} with 0 arguments, including metatag processing,
+ * and return only the first return value.
+ *
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@link this} as an additional first argument,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
+ *
+ * To call {@link this} as a plain call, use {@link #call()} instead.
+ *
+ * @param name Name of the method to look up for invocation
+ * @return All values returned from {@code this:name()} as a {@link Varargs} instance
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call()
+ * @see #invoke()
+ * @see #method(String)
+ * @see #method(LuaValue,LuaValue)
+ * @see #method(LuaValue,LuaValue,LuaValue)
+ */
+ public LuaValue method(LuaValue name) { return this.get(name).call(this); }
+
+ /** Call named method on {@link this} with 1 argument, including metatag processing,
+ * and return only the first return value.
+ *
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@link this} as an additional first argument,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
+ *
+ * To call {@link this} as a plain call, use {@link #call(LuaValue)} instead.
+ *
+ * @param name Name of the method to look up for invocation
+ * @param arg Argument to supply to the method
+ * @return All values returned from {@code this:name(arg)} as a {@link Varargs} instance
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call(LuaValue)
+ * @see #invoke(LuaValue)
+ * @see #method(LuaValue,LuaValue)
+ * @see #method(String)
+ * @see #method(String,LuaValue,LuaValue)
+ */
+ public LuaValue method(String name, LuaValue arg) { return this.get(name).call(this,arg); }
+
+ /** Call named method on {@link this} with 1 argument, including metatag processing,
+ * and return only the first return value.
+ *
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@link this} as an additional first argument,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
+ *
+ * To call {@link this} as a plain call, use {@link #call(LuaValue)} instead.
+ *
+ * @param name Name of the method to look up for invocation
+ * @param arg Argument to supply to the method
+ * @return All values returned from {@code this:name(arg)} as a {@link Varargs} instance
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call(LuaValue)
+ * @see #invoke(LuaValue)
+ * @see #method(String,LuaValue)
+ * @see #method(LuaValue)
+ * @see #method(LuaValue,LuaValue,LuaValue)
+ */
+ public LuaValue method(LuaValue name, LuaValue arg) { return this.get(name).call(this,arg); }
+
+ /** Call named method on {@link this} with 2 arguments, including metatag processing,
+ * and return only the first return value.
+ *
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@link this} as an additional first argument,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
+ *
+ * To call {@link this} as a plain call, use {@link #call(LuaValue,LuaValue)} instead.
+ *
+ * @param name Name of the method to look up for invocation
+ * @param arg1 First argument to supply to the method
+ * @param arg2 Second argument to supply to the method
+ * @return All values returned from {@code this:name(arg1,arg2)} as a {@link Varargs} instance
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call(LuaValue,LuaValue)
+ * @see #invoke(LuaValue,Varargs)
+ * @see #method(String,LuaValue)
+ * @see #method(LuaValue,LuaValue,LuaValue)
+ */
+ public LuaValue method(String name, LuaValue arg1, LuaValue arg2) { return this.get(name).call(this,arg1,arg2); }
+
+ /** Call named method on {@link this} with 2 arguments, including metatag processing,
+ * and return only the first return value.
+ *
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@link this} as an additional first argument,
+ * and return only its first return value, dropping any others.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * If the return value is a {@link Varargs}, only the 1st value will be returned.
+ * To get multiple values, use {@link #invoke()} instead.
+ *
+ * To call {@link this} as a plain call, use {@link #call(LuaValue,LuaValue)} instead.
+ *
+ * @param name Name of the method to look up for invocation
+ * @param arg1 First argument to supply to the method
+ * @param arg2 Second argument to supply to the method
+ * @return All values returned from {@code this:name(arg1,arg2)} as a {@link Varargs} instance
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call(LuaValue,LuaValue)
+ * @see #invoke(LuaValue,Varargs)
+ * @see #method(LuaValue,LuaValue)
+ * @see #method(String,LuaValue,LuaValue)
+ */
+ public LuaValue method(LuaValue name, LuaValue arg1, LuaValue arg2) { return this.get(name).call(this,arg1,arg2); }
+
+ /** Call {@link this} with 0 arguments, including metatag processing,
+ * and retain all return values in a {@link Varargs}.
+ *
+ * If {@code this} is a {@link LuaFunction}, call it, and return all values.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * To get a particular return value, us {@link Varargs#arg(int)}
+ *
+ * To call {@link this} as a method call, use {@link #invokemethod(LuaValue)} instead.
+ *
+ * @return All return values as a {@link Varargs} instance.
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call()
+ * @see #invoke(Varargs)
+ * @see #invokemethod(String)
+ * @see #invokemethod(LuaValue)
+ */
+ public Varargs invoke() { return invoke(NONE); }
+
+ /** Call {@link this} with variable arguments, including metatag processing,
+ * and retain all return values in a {@link Varargs}.
+ *
+ * If {@code this} is a {@link LuaFunction}, call it, and return all values.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * To get a particular return value, us {@link Varargs#arg(int)}
+ *
+ * To call {@link this} as a method call, use {@link #invokemethod(LuaValue)} instead.
+ *
+ * @param args Varargs containing the arguments to supply to the called function
+ * @return All return values as a {@link Varargs} instance.
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #varargsOf(LuaValue[])
+ * @see #call(LuaValue)
+ * @see #invoke()
+ * @see #invoke(LuaValue,Varargs)
+ * @see #invokemethod(String,Varargs)
+ * @see #invokemethod(LuaValue,Varargs)
+ */
+ public Varargs invoke(Varargs args) { return callmt().invoke(this,args); }
+
+ /** Call {@link this} with variable arguments, including metatag processing,
+ * and retain all return values in a {@link Varargs}.
+ *
+ * If {@code this} is a {@link LuaFunction}, call it, and return all values.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * To get a particular return value, us {@link Varargs#arg(int)}
+ *
+ * To call {@link this} as a method call, use {@link #invokemethod(LuaValue,Varargs)} instead.
+ *
+ * @param arg The first argument to supply to the called function
+ * @param varargs Varargs containing the remaining arguments to supply to the called function
+ * @return All return values as a {@link Varargs} instance.
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #varargsOf(LuaValue[])
+ * @see #call(LuaValue,LuaValue)
+ * @see #invoke(LuaValue,Varargs)
+ * @see #invokemethod(String,Varargs)
+ * @see #invokemethod(LuaValue,Varargs)
+ */
+ public Varargs invoke(LuaValue arg,Varargs varargs) { return invoke(varargsOf(arg,varargs)); }
+
+ /** Call {@link this} with variable arguments, including metatag processing,
+ * and retain all return values in a {@link Varargs}.
+ *
+ * If {@code this} is a {@link LuaFunction}, call it, and return all values.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * To get a particular return value, us {@link Varargs#arg(int)}
+ *
+ * To call {@link this} as a method call, use {@link #invokemethod(LuaValue,Varargs)} instead.
+ *
+ * @param arg1 The first argument to supply to the called function
+ * @param arg2 The second argument to supply to the called function
+ * @param varargs Varargs containing the remaining arguments to supply to the called function
+ * @return All return values as a {@link Varargs} instance.
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #varargsOf(LuaValue[])
+ * @see #call(LuaValue,LuaValue,LuaValue)
+ * @see #invoke(LuaValue,LuaValue,Varargs)
+ * @see #invokemethod(String,Varargs)
+ * @see #invokemethod(LuaValue,Varargs)
+ */
+ public Varargs invoke(LuaValue arg1,LuaValue arg2,Varargs varargs) { return invoke(varargsOf(arg1,arg2,varargs)); }
+
+ /** Call {@link this} with variable arguments, including metatag processing,
+ * and retain all return values in a {@link Varargs}.
+ *
+ * If {@code this} is a {@link LuaFunction}, call it, and return all values.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * To get a particular return value, us {@link Varargs#arg(int)}
+ *
+ * To call {@link this} as a method call, use {@link #invokemethod(LuaValue,Varargs)} instead.
+ *
+ * @param args Array of arguments to supply to the called function
+ * @return All return values as a {@link Varargs} instance.
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #varargsOf(LuaValue[])
+ * @see #call(LuaValue,LuaValue,LuaValue)
+ * @see #invoke(LuaValue,LuaValue,Varargs)
+ * @see #invokemethod(String,LuaValue[])
+ * @see #invokemethod(LuaValue,LuaValue[])
+ */
+ public Varargs invoke(LuaValue[] args) { return invoke(varargsOf(args)); }
+
+ /** Call {@link this} with variable arguments, including metatag processing,
+ * and retain all return values in a {@link Varargs}.
+ *
+ * If {@code this} is a {@link LuaFunction}, call it, and return all values.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * To get a particular return value, us {@link Varargs#arg(int)}
+ *
+ * To call {@link this} as a method call, use {@link #invokemethod(LuaValue,Varargs)} instead.
+ *
+ * @param args Array of arguments to supply to the called function
+ * @param varargs Varargs containing additional arguments to supply to the called function
+ * @return All return values as a {@link Varargs} instance.
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #varargsOf(LuaValue[])
+ * @see #call(LuaValue,LuaValue,LuaValue)
+ * @see #invoke(LuaValue,LuaValue,Varargs)
+ * @see #invokemethod(String,LuaValue[])
+ * @see #invokemethod(LuaValue,LuaValue[])
+ * @see #invokemethod(String,Varargs)
+ * @see #invokemethod(LuaValue,Varargs)
+ */
+ public Varargs invoke(LuaValue[] args,Varargs varargs) { return invoke(varargsOf(args,varargs)); }
+
+ /** Call named method on {@link this} with 0 arguments, including metatag processing,
+ * and retain all return values in a {@link Varargs}.
+ *
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@link this} as an additional first argument,
+ * and return all return values as a {@link Varargs} instance.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * To get a particular return value, us {@link Varargs#arg(int)}
+ *
+ * To call {@link this} as a plain call, use {@link #invoke()} instead.
+ *
+ * @param name Name of the method to look up for invocation
+ * @return All values returned from {@code this:name()} as a {@link Varargs} instance
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call()
+ * @see #invoke()
+ * @see #method(String)
+ * @see #invokemethod(LuaValue)
+ * @see #invokemethod(String,LuaValue)
+ */
+ public Varargs invokemethod(String name) { return get(name).invoke(this); }
+
+ /** Call named method on {@link this} with 0 arguments, including metatag processing,
+ * and retain all return values in a {@link Varargs}.
+ *
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@link this} as an additional first argument,
+ * and return all return values as a {@link Varargs} instance.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * To get a particular return value, us {@link Varargs#arg(int)}
+ *
+ * To call {@link this} as a plain call, use {@link #invoke()} instead.
+ *
+ * @param name Name of the method to look up for invocation
+ * @return All values returned from {@code this:name()} as a {@link Varargs} instance
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call()
+ * @see #invoke()
+ * @see #method(LuaValue)
+ * @see #invokemethod(String)
+ * @see #invokemethod(LuaValue,LuaValue)
+ */
+ public Varargs invokemethod(LuaValue name) { return get(name).invoke(this); }
+
+ /** Call named method on {@link this} with 1 argument, including metatag processing,
+ * and retain all return values in a {@link Varargs}.
+ *
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@link this} as an additional first argument,
+ * and return all return values as a {@link Varargs} instance.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * To get a particular return value, us {@link Varargs#arg(int)}
+ *
+ * To call {@link this} as a plain call, use {@link #invoke(Varargs)} instead.
+ *
+ * @param name Name of the method to look up for invocation
+ * @param args {@link Varargs} containing arguments to supply to the called function after {@code this}
+ * @return All values returned from {@code this:name(args)} as a {@link Varargs} instance
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call()
+ * @see #invoke(Varargs)
+ * @see #method(String)
+ * @see #invokemethod(LuaValue,Varargs)
+ * @see #invokemethod(String,LuaValue[])
+ */
+ public Varargs invokemethod(String name, Varargs args) { return get(name).invoke(varargsOf(this,args)); }
+
+ /** Call named method on {@link this} with variable arguments, including metatag processing,
+ * and retain all return values in a {@link Varargs}.
+ *
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@link this} as an additional first argument,
+ * and return all return values as a {@link Varargs} instance.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * To get a particular return value, us {@link Varargs#arg(int)}
+ *
+ * To call {@link this} as a plain call, use {@link #invoke(Varargs)} instead.
+ *
+ * @param name Name of the method to look up for invocation
+ * @param args {@link Varargs} containing arguments to supply to the called function after {@code this}
+ * @return All values returned from {@code this:name(args)} as a {@link Varargs} instance
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call()
+ * @see #invoke(Varargs)
+ * @see #method(String)
+ * @see #invokemethod(String,Varargs)
+ * @see #invokemethod(LuaValue,LuaValue[])
+ */
+ public Varargs invokemethod(LuaValue name, Varargs args) { return get(name).invoke(varargsOf(this,args)); }
+
+ /** Call named method on {@link this} with 1 argument, including metatag processing,
+ * and retain all return values in a {@link Varargs}.
+ *
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@link this} as an additional first argument,
+ * and return all return values as a {@link Varargs} instance.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * To get a particular return value, us {@link Varargs#arg(int)}
+ *
+ * To call {@link this} as a plain call, use {@link #invoke(Varargs)} instead.
+ *
+ * @param name Name of the method to look up for invocation
+ * @param args Array of {@link LuaValue} containing arguments to supply to the called function after {@code this}
+ * @return All values returned from {@code this:name(args)} as a {@link Varargs} instance
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call()
+ * @see #invoke(Varargs)
+ * @see #method(String)
+ * @see #invokemethod(LuaValue,LuaValue[])
+ * @see #invokemethod(String,Varargs)
+ * @see LuaValue#varargsOf(LuaValue[])
+ */
+ public Varargs invokemethod(String name, LuaValue[] args) { return get(name).invoke(varargsOf(this,varargsOf(args))); }
+
+ /** Call named method on {@link this} with variable arguments, including metatag processing,
+ * and retain all return values in a {@link Varargs}.
+ *
+ * Look up {@code this[name]} and if it is a {@link LuaFunction},
+ * call it inserting {@link this} as an additional first argument,
+ * and return all return values as a {@link Varargs} instance.
+ * Otherwise, look for the {@link CALL} metatag and call that.
+ *
+ * To get a particular return value, us {@link Varargs#arg(int)}
+ *
+ * To call {@link this} as a plain call, use {@link #invoke(Varargs)} instead.
+ *
+ * @param name Name of the method to look up for invocation
+ * @param args Array of {@link LuaValue} containing arguments to supply to the called function after {@code this}
+ * @return All values returned from {@code this:name(args)} as a {@link Varargs} instance
+ * @throws LuaError if not a function and {@link CALL} is not defined,
+ * or the invoked function throws a {@link LuaError}
+ * or the invoked closure throw a lua {@code error}
+ * @see #call()
+ * @see #invoke(Varargs)
+ * @see #method(String)
+ * @see #invokemethod(String,LuaValue[])
+ * @see #invokemethod(LuaValue,Varargs)
+ * @see LuaValue#varargsOf(LuaValue[])
+ */
+ public Varargs invokemethod(LuaValue name, LuaValue[] args) { return get(name).invoke(varargsOf(this,varargsOf(args))); }
+
+ /**
+ * Get the metatag value for the {@link CALL} metatag, if it exists.
+ * @return {@link LuaValue} value if metatag is defined
+ * @throws LuaError if {@link CALL} metatag is not defined.
+ */
+ protected LuaValue callmt() {
+ return checkmetatag(CALL, "attempt to call ");
+ }
+
+ /** Unary not: return inverse boolean value {@code (~this)} as defined by lua not operator
+ * @return {@link TRUE} if {@link NIL} or {@link FALSE}, otherwise {@link FALSE}
+ */
+ public LuaValue not() { return FALSE; }
+
+ /** Unary minus: return negative value {@code (-this)} as defined by lua unary minus operator
+ * @return boolean inverse as {@link LuaBoolean} if boolean or nil,
+ * numeric inverse as {@LuaNumber} if numeric,
+ * or metatag processing result if {@link UNM} metatag is defined
+ * @throws LuaError if {@code this} is not a table or string, and has no {@link UNM} metatag
+ */
+ public LuaValue neg() { return checkmetatag(UNM, "attempt to perform arithmetic on ").call(this); }
+
+ /** Length operator: return lua length of object {@code (#this)} including metatag processing as java int
+ * @return length as defined by the lua # operator
+ * or metatag processing result
+ * @throws LuaError if {@code this} is not a table or string, and has no {@link LEN} metatag
+ */
+ public LuaValue len() { return checkmetatag(LEN, "attempt to get length of ").call(this); }
+
+ /** Length operator: return lua length of object {@code (#this)} including metatag processing as java int
+ * @return length as defined by the lua # operator
+ * or metatag processing result converted to java int using {@link #toint()}
+ * @throws LuaError if {@code this} is not a table or string, and has no {@link LEN} metatag
+ */
+ public int length() { return len().toint(); }
+
+ /** Implementation of lua 5.0 getn() function.
+ * @return value of getn() as defined in lua 5.0 spec if {@code this} is a {@link LuaTable}
+ * @throws LuaError if {@code this} is not a {@link LuaTable}
+ */
+ public LuaValue getn() { return typerror("getn"); }
+
+ // object equality, used for key comparison
+ public boolean equals(Object obj) { return this == obj; }
+
+ /** Equals: Perform equality comparison with another value
+ * including metatag processing using {@link EQ}.
+ * @param val The value to compare with.
+ * @return {@link TRUE} if values are comparable and {@code (this == rhs)},
+ * {@link FALSE} if comparable but not equal,
+ * {@link LuaValue} if metatag processing occurs.
+ * @see #eq_b(LuaValue)
+ * @see #raweq(LuaValue)
+ * @see #neq(LuaValue)
+ * @see #eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
+ * @see #EQ
+ */
+ public LuaValue eq( LuaValue val ) { return this == val? TRUE: FALSE; }
+
+ /** Equals: Perform equality comparison with another value
+ * including metatag processing using {@link EQ},
+ * and return java boolean
+ * @param val The value to compare with.
+ * @return true if values are comparable and {@code (this == rhs)},
+ * false if comparable but not equal,
+ * result converted to java boolean if metatag processing occurs.
+ * @see #eq(LuaValue)
+ * @see #raweq(LuaValue)
+ * @see #neq_b(LuaValue)
+ * @see #eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
+ * @see #EQ
+ */
+ public boolean eq_b( LuaValue val ) { return this == val; }
+
+ /** Notquals: Perform inequality comparison with another value
+ * including metatag processing using {@link EQ}.
+ * @param val The value to compare with.
+ * @return {@link TRUE} if values are comparable and {@code (this != rhs)},
+ * {@link FALSE} if comparable but equal,
+ * inverse of {@link LuaValue} converted to {@link LuaBoolean} if metatag processing occurs.
+ * @see #eq(LuaValue)
+ * @see #raweq(LuaValue)
+ * @see #eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
+ * @see #EQ
+ */
+ public LuaValue neq( LuaValue val ) { return eq_b(val)? FALSE: TRUE; }
+
+ /** Notquals: Perform inequality comparison with another value
+ * including metatag processing using {@link EQ}.
+ * @param val The value to compare with.
+ * @return true if values are comparable and {@code (this != rhs)},
+ * false if comparable but equal,
+ * inverse of result converted to boolean if metatag processing occurs.
+ * @see #eq_b(LuaValue)
+ * @see #raweq(LuaValue)
+ * @see #eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue)
+ * @see #EQ
+ */
+ public boolean neq_b( LuaValue val ) { return !eq_b(val); }
+
+ /** Equals: Perform direct equality comparison with another value
+ * without metatag processing.
+ * @param val The value to compare with.
+ * @return true if {@code (this == rhs)}, false otherwise
+ * @see #eq(LuaValue)
+ * @see #raweq(LuaUserdata)
+ * @see #raweq(LuaString)
+ * @see #raweq(double)
+ * @see #raweq(int)
+ * @see #EQ
+ */
+ public boolean raweq( LuaValue val ) { return this == val; }
+
+ /** Equals: Perform direct equality comparison with a {@link LuaUserdata} value
+ * without metatag processing.
+ * @param val The {@link LuaUserdata} to compare with.
+ * @return true if {@code this} is userdata
+ * and their metatables are the same using ==
+ * and their instances are equal using {@link #equals(Object)},
+ * otherwise false
+ * @see #eq(LuaValue)
+ * @see #raweq(LuaValue)
+ */
+ public boolean raweq( LuaUserdata val ) { return false; }
+
+ /** Equals: Perform direct equality comparison with a {@link LuaString} value
+ * without metatag processing.
+ * @param val The {@link LuaString} to compare with.
+ * @return true if {@code this} is a {@link LuaString}
+ * and their byte sequences match,
+ * otherwise false
+ */
+ public boolean raweq( LuaString val ) { return false; }
+
+ /** Equals: Perform direct equality comparison with a double value
+ * without metatag processing.
+ * @param val The double value to compare with.
+ * @return true if {@code this} is a {@link LuaNumber}
+ * whose value equals val,
+ * otherwise false
+ */
+ public boolean raweq( double val ) { return false; }
+
+ /** Equals: Perform direct equality comparison with a int value
+ * without metatag processing.
+ * @param val The double value to compare with.
+ * @return true if {@code this} is a {@link LuaNumber}
+ * whose value equals val,
+ * otherwise false
+ */
+ public boolean raweq( int val ) { return false; }
+
+ /** Perform equality testing metatag processing
+ * @param lhs left-hand-side of equality expression
+ * @param lhsmt metatag value for left-hand-side
+ * @param rhs right-hand-side of equality expression
+ * @param rhsmt metatag value for right-hand-side
+ * @return true if metatag processing result is not {@link NIL} or {@link FALSE}
+ * @throws LuaError if metatag was not defined for either operand
+ * @see #equals(Object)
+ * @see #eq(LuaValue)
+ * @see #raweq(LuaValue)
+ * @see #EQ
+ */
+ public static final boolean eqmtcall(LuaValue lhs, LuaValue lhsmt, LuaValue rhs, LuaValue rhsmt) {
+ LuaValue h = lhsmt.rawget(EQ);
+ return h.isnil() || h!=rhsmt.rawget(EQ)? false: h.call(lhs,rhs).toboolean();
+ }
+
+ /** Add: Perform numeric add operation with another value
+ * including metatag processing.
+ *
+ * Each operand must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param rhs The right-hand-side value to perform the add with
+ * @return value of {@code (this + rhs)} if both are numeric,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if either operand is not a number or string convertible to number,
+ * and neither has the {@link ADD} metatag defined
+ * @see #arithmt(LuaValue, LuaValue)
+ */
+ public LuaValue add( LuaValue rhs ) { return arithmt(ADD,rhs); }
+
+ /** Add: Perform numeric add operation with another value
+ * of double type with metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param rhs The right-hand-side value to perform the add with
+ * @return value of {@code (this + rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #add(LuaValue)
+ */
+ public LuaValue add(double rhs) { return arithmtwith(ADD,rhs); }
+
+ /** Add: Perform numeric add operation with another value
+ * of int type with metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param rhs The right-hand-side value to perform the add with
+ * @return value of {@code (this + rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #add(LuaValue)
+ */
+ public LuaValue add(int rhs) { return add((double)rhs); }
+
+ /** Subtract: Perform numeric subtract operation with another value
+ * of unknown type,
+ * including metatag processing.
+ *
+ * Each operand must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param rhs The right-hand-side value to perform the subtract with
+ * @return value of {@code (this - rhs)} if both are numeric,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if either operand is not a number or string convertible to number,
+ * and neither has the {@link SUB} metatag defined
+ * @see #arithmt(LuaValue, LuaValue)
+ */
+ public LuaValue sub( LuaValue rhs ) { return arithmt(SUB,rhs); }
+
+ /** Subtract: Perform numeric subtract operation with another value
+ * of double type with metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param rhs The right-hand-side value to perform the subtract with
+ * @return value of {@code (this - rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #sub(LuaValue)
+ */
+ public LuaValue sub( double rhs ) { return aritherror("sub"); }
+
+ /** Subtract: Perform numeric subtract operation with another value
+ * of int type with metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param rhs The right-hand-side value to perform the subtract with
+ * @return value of {@code (this - rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #sub(LuaValue)
+ */
+ public LuaValue sub( int rhs ) { return aritherror("sub"); }
+
+ /** Reverse-subtract: Perform numeric subtract operation from an int value
+ * with metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param lhs The left-hand-side value from which to perform the subtraction
+ * @return value of {@code (lhs - this)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #sub(LuaValue)
+ * @see #sub(double)
+ * @see #sub(int)
+ */
+ public LuaValue subFrom(double lhs) { return arithmtwith(SUB,lhs); }
+
+ /** Reverse-subtract: Perform numeric subtract operation from a double value
+ * without metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * For metatag processing {@link #sub(LuaValue)} must be used
+ *
+ * @param lhs The left-hand-side value from which to perform the subtraction
+ * @return value of {@code (lhs - this)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #sub(LuaValue)
+ * @see #sub(double)
+ * @see #sub(int)
+ */
+ public LuaValue subFrom(int lhs) { return subFrom((double)lhs); }
+
+ /** Multiply: Perform numeric multiply operation with another value
+ * of unknown type,
+ * including metatag processing.
+ *
+ * Each operand must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param rhs The right-hand-side value to perform the multiply with
+ * @return value of {@code (this * rhs)} if both are numeric,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if either operand is not a number or string convertible to number,
+ * and neither has the {@link MUL} metatag defined
+ * @see #arithmt(LuaValue, LuaValue)
+ */
+ public LuaValue mul( LuaValue rhs ) { return arithmt(MUL,rhs); }
+
+ /** Multiply: Perform numeric multiply operation with another value
+ * of double type with metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param rhs The right-hand-side value to perform the multiply with
+ * @return value of {@code (this * rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #mul(LuaValue)
+ */
+ public LuaValue mul(double rhs) { return arithmtwith(MUL,rhs); }
+
+ /** Multiply: Perform numeric multiply operation with another value
+ * of int type with metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param rhs The right-hand-side value to perform the multiply with
+ * @return value of {@code (this * rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #mul(LuaValue)
+ */
+ public LuaValue mul(int rhs) { return mul((double)rhs); }
+
+ /** Raise to power: Raise this value to a power
+ * including metatag processing.
+ *
+ * Each operand must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param rhs The power to raise this value to
+ * @return value of {@code (this ^ rhs)} if both are numeric,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if either operand is not a number or string convertible to number,
+ * and neither has the {@link POW} metatag defined
+ * @see #arithmt(LuaValue, LuaValue)
+ */
+ public LuaValue pow( LuaValue rhs ) { return arithmt(POW,rhs); }
+
+ /** Raise to power: Raise this value to a power
+ * of double type with metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param rhs The power to raise this value to
+ * @return value of {@code (this ^ rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #pow(LuaValue)
+ */
+ public LuaValue pow( double rhs ) { return aritherror("pow"); }
+
+ /** Raise to power: Raise this value to a power
+ * of int type with metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param rhs The power to raise this value to
+ * @return value of {@code (this ^ rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #pow(LuaValue)
+ */
+ public LuaValue pow( int rhs ) { return aritherror("pow"); }
+
+ /** Reverse-raise to power: Raise another value of double type to this power
+ * with metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param lhs The left-hand-side value which will be raised to this power
+ * @return value of {@code (lhs ^ this)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #pow(LuaValue)
+ * @see #pow(double)
+ * @see #pow(int)
+ */
+ public LuaValue powWith(double lhs) { return arithmtwith(POW,lhs); }
+
+ /** Reverse-raise to power: Raise another value of double type to this power
+ * with metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param lhs The left-hand-side value which will be raised to this power
+ * @return value of {@code (lhs ^ this)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #pow(LuaValue)
+ * @see #pow(double)
+ * @see #pow(int)
+ */
+ public LuaValue powWith(int lhs) { return powWith((double)lhs); }
+
+ /** Divide: Perform numeric divide operation by another value
+ * of unknown type,
+ * including metatag processing.
+ *
+ * Each operand must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param rhs The right-hand-side value to perform the divulo with
+ * @return value of {@code (this / rhs)} if both are numeric,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if either operand is not a number or string convertible to number,
+ * and neither has the {@link DIV} metatag defined
+ * @see #arithmt(LuaValue, LuaValue)
+ */
+ public LuaValue div( LuaValue rhs ) { return arithmt(DIV,rhs); }
+
+ /** Divide: Perform numeric divide operation by another value
+ * of double type without metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * For metatag processing {@link #div(LuaValue)} must be used
+ *
+ * @param rhs The right-hand-side value to perform the divulo with
+ * @return value of {@code (this / rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #div(LuaValue)
+ */
+ public LuaValue div( double rhs ) { return aritherror("div"); }
+
+ /** Divide: Perform numeric divide operation by another value
+ * of int type without metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * For metatag processing {@link #div(LuaValue)} must be used
+ *
+ * @param rhs The right-hand-side value to perform the divulo with
+ * @return value of {@code (this / rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #div(LuaValue)
+ */
+ public LuaValue div( int rhs ) { return aritherror("div"); }
+
+ /** Reverse-divide: Perform numeric divide operation into another value
+ * with metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param lhs The left-hand-side value which will be divided by this
+ * @return value of {@code (lhs / this)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #div(LuaValue)
+ * @see #div(double)
+ * @see #div(int)
+ */
+ public LuaValue divInto(double lhs) { return arithmtwith(DIV,lhs); }
+
+ /** Modulo: Perform numeric modulo operation with another value
+ * of unknown type,
+ * including metatag processing.
+ *
+ * Each operand must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param rhs The right-hand-side value to perform the modulo with
+ * @return value of {@code (this % rhs)} if both are numeric,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if either operand is not a number or string convertible to number,
+ * and neither has the {@link MOD} metatag defined
+ * @see #arithmt(LuaValue, LuaValue)
+ */
+ public LuaValue mod( LuaValue rhs ) { return arithmt(MOD,rhs); }
+
+ /** Modulo: Perform numeric modulo operation with another value
+ * of double type without metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * For metatag processing {@link #mod(LuaValue)} must be used
+ *
+ * @param rhs The right-hand-side value to perform the modulo with
+ * @return value of {@code (this % rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #mod(LuaValue)
+ */
+ public LuaValue mod( double rhs ) { return aritherror("mod"); }
+
+ /** Modulo: Perform numeric modulo operation with another value
+ * of int type without metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * For metatag processing {@link #mod(LuaValue)} must be used
+ *
+ * @param rhs The right-hand-side value to perform the modulo with
+ * @return value of {@code (this % rhs)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #mod(LuaValue)
+ */
+ public LuaValue mod( int rhs ) { return aritherror("mod"); }
+
+ /** Reverse-modulo: Perform numeric modulo operation from another value
+ * with metatag processing
+ *
+ * {@code this} must derive from {@link LuaNumber}
+ * or derive from {@link LuaString} and be convertible to a number
+ *
+ * @param lhs The left-hand-side value which will be modulo'ed by this
+ * @return value of {@code (lhs % this)} if this is numeric
+ * @throws LuaError if {@code this} is not a number or string convertible to number
+ * @see #mod(LuaValue)
+ * @see #mod(double)
+ * @see #mod(int)
+ */
+ public LuaValue modFrom(double lhs) { return arithmtwith(MOD,lhs); }
+
+ /** Perform metatag processing for arithmetic operations.
+ *
+ * Finds the supplied metatag value for {@code this} or {@code op2} and invokes it,
+ * or throws {@link LuaError} if neither is defined.
+ * @param tag The metatag to look up
+ * @param op2 The other operand value to perform the operation with
+ * @return {@link LuaValue} resulting from metatag processing
+ * @throws LuaError if metatag was not defined for either operand
+ * @see #add(LuaValue)
+ * @see #sub(LuaValue)
+ * @see #mul(LuaValue)
+ * @see #pow(LuaValue)
+ * @see #div(LuaValue)
+ * @see #mod(LuaValue)
+ * @see #ADD
+ * @see #SUB
+ * @see #MUL
+ * @see #POW
+ * @see #DIV
+ * @see #MOD
+ */
+ protected LuaValue arithmt(LuaValue tag, LuaValue op2) {
+ LuaValue h = this.metatag(tag);
+ if ( h.isnil() ) {
+ h = op2.metatag(tag);
+ if ( h.isnil() )
+ error( "attempt to perform arithmetic "+tag+" on "+typename()+" and "+op2.typename() );
+ }
+ return h.call( this, op2 );
+ }
+
+ /** Perform metatag processing for arithmetic operations when the left-hand-side is a number.
+ *
+ * Finds the supplied metatag value for {@code this} and invokes it,
+ * or throws {@link LuaError} if neither is defined.
+ * @param tag The metatag to look up
+ * @param op1 The value of the left-hand-side to perform the operation with
+ * @return {@link LuaValue} resulting from metatag processing
+ * @throws LuaError if metatag was not defined for either operand
+ * @see #add(LuaValue)
+ * @see #sub(LuaValue)
+ * @see #mul(LuaValue)
+ * @see #pow(LuaValue)
+ * @see #div(LuaValue)
+ * @see #mod(LuaValue)
+ * @see #ADD
+ * @see #SUB
+ * @see #MUL
+ * @see #POW
+ * @see #DIV
+ * @see #MOD
+ */
+ protected LuaValue arithmtwith(LuaValue tag, double op1) {
+ LuaValue h = metatag(tag);
+ if ( h.isnil() )
+ error( "attempt to perform arithmetic "+tag+" on number and "+typename() );
+ return h.call( LuaValue.valueOf(op1), this );
+ }
+
+ /** Less than: Perform numeric or string comparison with another value
+ * of unknown type,
+ * including metatag processing, and returning {@link LuaValue}.
+ *
+ * To be comparable, both operands must derive from {@link LuaString}
+ * or both must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return {@link TRUE} if {@code (this < rhs)}, {@link FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if either both operands are not a strings or both are not numbers
+ * and no {@link LT} metatag is defined.
+ * @see #gteq_b(LuaValue)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public LuaValue lt( LuaValue rhs ) { return comparemt(LT,rhs); }
+
+ /** Less than: Perform numeric comparison with another value
+ * of double type,
+ * including metatag processing, and returning {@link LuaValue}.
+ *
+ * To be comparable, this must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return {@link TRUE} if {@code (this < rhs)}, {@link FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if this is not a number
+ * and no {@link LT} metatag is defined.
+ * @see #gteq_b(double)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public LuaValue lt( double rhs ) { return compareerror("number"); }
+
+ /** Less than: Perform numeric comparison with another value
+ * of int type,
+ * including metatag processing, and returning {@link LuaValue}.
+ *
+ * To be comparable, this must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return {@link TRUE} if {@code (this < rhs)}, {@link FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if this is not a number
+ * and no {@link LT} metatag is defined.
+ * @see #gteq_b(int)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public LuaValue lt( int rhs ) { return compareerror("number"); }
+
+ /** Less than: Perform numeric or string comparison with another value
+ * of unknown type, including metatag processing,
+ * and returning java boolean.
+ *
+ * To be comparable, both operands must derive from {@link LuaString}
+ * or both must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return true if {@code (this < rhs)}, false if not,
+ * and boolean interpreation of result if metatag processing occurs.
+ * @throws LuaError if either both operands are not a strings or both are not numbers
+ * and no {@link LT} metatag is defined.
+ * @see #gteq(LuaValue)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public boolean lt_b( LuaValue rhs ) { return comparemt(LT,rhs).toboolean(); }
+
+ /** Less than: Perform numeric comparison with another value
+ * of int type,
+ * including metatag processing,
+ * and returning java boolean.
+ *
+ * To be comparable, this must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return true if {@code (this < rhs)}, false if not,
+ * and boolean interpreation of result if metatag processing occurs.
+ * @throws LuaError if this is not a number
+ * and no {@link LT} metatag is defined.
+ * @see #gteq(int)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public boolean lt_b( int rhs ) { compareerror("number"); return false; }
+
+ /** Less than: Perform numeric or string comparison with another value
+ * of unknown type, including metatag processing,
+ * and returning java boolean.
+ *
+ * To be comparable, both operands must derive from {@link LuaString}
+ * or both must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return true if {@code (this < rhs)}, false if not,
+ * and boolean interpreation of result if metatag processing occurs.
+ * @throws LuaError if either both operands are not a strings or both are not numbers
+ * and no {@link LT} metatag is defined.
+ * @see #gteq(LuaValue)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public boolean lt_b( double rhs ) { compareerror("number"); return false; }
+
+ /** Less than or equals: Perform numeric or string comparison with another value
+ * of unknown type,
+ * including metatag processing, and returning {@link LuaValue}.
+ *
+ * To be comparable, both operands must derive from {@link LuaString}
+ * or both must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return {@link TRUE} if {@code (this <= rhs)}, {@link FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if either both operands are not a strings or both are not numbers
+ * and no {@link LE} metatag is defined.
+ * @see #gteq_b(LuaValue)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public LuaValue lteq( LuaValue rhs ) { return comparemt(LE,rhs); }
+
+ /** Less than or equals: Perform numeric comparison with another value
+ * of double type,
+ * including metatag processing, and returning {@link LuaValue}.
+ *
+ * To be comparable, this must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return {@link TRUE} if {@code (this <= rhs)}, {@link FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if this is not a number
+ * and no {@link LE} metatag is defined.
+ * @see #gteq_b(double)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public LuaValue lteq( double rhs ) { return compareerror("number"); }
+
+ /** Less than or equals: Perform numeric comparison with another value
+ * of int type,
+ * including metatag processing, and returning {@link LuaValue}.
+ *
+ * To be comparable, this must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return {@link TRUE} if {@code (this <= rhs)}, {@link FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if this is not a number
+ * and no {@link LE} metatag is defined.
+ * @see #gteq_b(int)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public LuaValue lteq( int rhs ) { return compareerror("number"); }
+
+ /** Less than or equals: Perform numeric or string comparison with another value
+ * of unknown type, including metatag processing,
+ * and returning java boolean.
+ *
+ * To be comparable, both operands must derive from {@link LuaString}
+ * or both must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return true if {@code (this <= rhs)}, false if not,
+ * and boolean interpreation of result if metatag processing occurs.
+ * @throws LuaError if either both operands are not a strings or both are not numbers
+ * and no {@link LE} metatag is defined.
+ * @see #gteq(LuaValue)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public boolean lteq_b( LuaValue rhs ) { return comparemt(LE,rhs).toboolean(); }
+
+ /** Less than or equals: Perform numeric comparison with another value
+ * of int type,
+ * including metatag processing,
+ * and returning java boolean.
+ *
+ * To be comparable, this must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return true if {@code (this <= rhs)}, false if not,
+ * and boolean interpreation of result if metatag processing occurs.
+ * @throws LuaError if this is not a number
+ * and no {@link LE} metatag is defined.
+ * @see #gteq(int)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public boolean lteq_b( int rhs ) { compareerror("number"); return false; }
+
+ /** Less than or equals: Perform numeric comparison with another value
+ * of double type,
+ * including metatag processing,
+ * and returning java boolean.
+ *
+ * To be comparable, this must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return true if {@code (this <= rhs)}, false if not,
+ * and boolean interpreation of result if metatag processing occurs.
+ * @throws LuaError if this is not a number
+ * and no {@link LE} metatag is defined.
+ * @see #gteq(double)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public boolean lteq_b( double rhs ) { compareerror("number"); return false; }
+
+ /** Greater than: Perform numeric or string comparison with another value
+ * of unknown type,
+ * including metatag processing, and returning {@link LuaValue}.
+ *
+ * To be comparable, both operands must derive from {@link LuaString}
+ * or both must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return {@link TRUE} if {@code (this > rhs)}, {@link FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if either both operands are not a strings or both are not numbers
+ * and no {@link LE} metatag is defined.
+ * @see #gteq_b(LuaValue)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public LuaValue gt( LuaValue rhs ) { return rhs.comparemt(LE,this); }
+
+ /** Greater than: Perform numeric comparison with another value
+ * of double type,
+ * including metatag processing, and returning {@link LuaValue}.
+ *
+ * To be comparable, this must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return {@link TRUE} if {@code (this > rhs)}, {@link FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if this is not a number
+ * and no {@link LE} metatag is defined.
+ * @see #gteq_b(double)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public LuaValue gt( double rhs ) { return compareerror("number"); }
+
+ /** Greater than: Perform numeric comparison with another value
+ * of int type,
+ * including metatag processing, and returning {@link LuaValue}.
+ *
+ * To be comparable, this must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return {@link TRUE} if {@code (this > rhs)}, {@link FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if this is not a number
+ * and no {@link LE} metatag is defined.
+ * @see #gteq_b(int)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public LuaValue gt( int rhs ) { return compareerror("number"); }
+
+ /** Greater than: Perform numeric or string comparison with another value
+ * of unknown type, including metatag processing,
+ * and returning java boolean.
+ *
+ * To be comparable, both operands must derive from {@link LuaString}
+ * or both must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return true if {@code (this > rhs)}, false if not,
+ * and boolean interpreation of result if metatag processing occurs.
+ * @throws LuaError if either both operands are not a strings or both are not numbers
+ * and no {@link LE} metatag is defined.
+ * @see #gteq(LuaValue)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public boolean gt_b( LuaValue rhs ) { return rhs.comparemt(LE,this).toboolean(); }
+
+ /** Greater than: Perform numeric comparison with another value
+ * of int type,
+ * including metatag processing,
+ * and returning java boolean.
+ *
+ * To be comparable, this must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return true if {@code (this > rhs)}, false if not,
+ * and boolean interpreation of result if metatag processing occurs.
+ * @throws LuaError if this is not a number
+ * and no {@link LE} metatag is defined.
+ * @see #gteq(int)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public boolean gt_b( int rhs ) { compareerror("number"); return false; }
+
+ /** Greater than: Perform numeric or string comparison with another value
+ * of unknown type, including metatag processing,
+ * and returning java boolean.
+ *
+ * To be comparable, both operands must derive from {@link LuaString}
+ * or both must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return true if {@code (this > rhs)}, false if not,
+ * and boolean interpreation of result if metatag processing occurs.
+ * @throws LuaError if either both operands are not a strings or both are not numbers
+ * and no {@link LE} metatag is defined.
+ * @see #gteq(LuaValue)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public boolean gt_b( double rhs ) { compareerror("number"); return false; }
+
+ /** Greater than or equals: Perform numeric or string comparison with another value
+ * of unknown type,
+ * including metatag processing, and returning {@link LuaValue}.
+ *
+ * To be comparable, both operands must derive from {@link LuaString}
+ * or both must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return {@link TRUE} if {@code (this >= rhs)}, {@link FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if either both operands are not a strings or both are not numbers
+ * and no {@link LT} metatag is defined.
+ * @see #gteq_b(LuaValue)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public LuaValue gteq( LuaValue rhs ) { return rhs.comparemt(LT,this); }
+
+ /** Greater than or equals: Perform numeric comparison with another value
+ * of double type,
+ * including metatag processing, and returning {@link LuaValue}.
+ *
+ * To be comparable, this must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return {@link TRUE} if {@code (this >= rhs)}, {@link FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if this is not a number
+ * and no {@link LT} metatag is defined.
+ * @see #gteq_b(double)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public LuaValue gteq( double rhs ) { return compareerror("number"); }
+
+ /** Greater than or equals: Perform numeric comparison with another value
+ * of int type,
+ * including metatag processing, and returning {@link LuaValue}.
+ *
+ * To be comparable, this must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return {@link TRUE} if {@code (this >= rhs)}, {@link FALSE} if not,
+ * or {@link LuaValue} if metatag processing occurs
+ * @throws LuaError if this is not a number
+ * and no {@link LT} metatag is defined.
+ * @see #gteq_b(int)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public LuaValue gteq( int rhs ) { return valueOf(todouble() >= rhs); }
+
+ /** Greater than or equals: Perform numeric or string comparison with another value
+ * of unknown type, including metatag processing,
+ * and returning java boolean.
+ *
+ * To be comparable, both operands must derive from {@link LuaString}
+ * or both must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return true if {@code (this >= rhs)}, false if not,
+ * and boolean interpreation of result if metatag processing occurs.
+ * @throws LuaError if either both operands are not a strings or both are not numbers
+ * and no {@link LT} metatag is defined.
+ * @see #gteq(LuaValue)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public boolean gteq_b( LuaValue rhs ) { return rhs.comparemt(LT,this).toboolean(); }
+
+ /** Greater than or equals: Perform numeric comparison with another value
+ * of int type,
+ * including metatag processing,
+ * and returning java boolean.
+ *
+ * To be comparable, this must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return true if {@code (this >= rhs)}, false if not,
+ * and boolean interpreation of result if metatag processing occurs.
+ * @throws LuaError if this is not a number
+ * and no {@link LT} metatag is defined.
+ * @see #gteq(int)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public boolean gteq_b( int rhs ) { compareerror("number"); return false; }
+
+ /** Greater than or equals: Perform numeric comparison with another value
+ * of double type,
+ * including metatag processing,
+ * and returning java boolean.
+ *
+ * To be comparable, this must derive from {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @return true if {@code (this >= rhs)}, false if not,
+ * and boolean interpreation of result if metatag processing occurs.
+ * @throws LuaError if this is not a number
+ * and no {@link LT} metatag is defined.
+ * @see #gteq(double)
+ * @see #comparemt(LuaValue, LuaValue)
+ */
+ public boolean gteq_b( double rhs ) { compareerror("number"); return false; }
+
+ /** Perform metatag processing for comparison operations.
+ *
+ * Finds the supplied metatag value and invokes it,
+ * or throws {@link LuaError} if none applies.
+ * @param tag The metatag to look up
+ * @param rhs The right-hand-side value to perform the operation with
+ * @return {@link LuaValue} resulting from metatag processing
+ * @throws LuaError if metatag was not defined for either operand,
+ * or if the operands are not the same type,
+ * or the metatag values for the two operands are different.
+ * @see #gt(LuaValue)
+ * @see #gteq(LuaValue)
+ * @see #lt(LuaValue)
+ * @see #lteq(LuaValue)
+ */
+ public LuaValue comparemt( LuaValue tag, LuaValue op1 ) {
+ if ( type() == op1.type() ) {
+ LuaValue h = metatag(tag);
+ if ( !h.isnil() && h == op1.metatag(tag) )
+ return h.call(this, op1);
+ }
+ return error("attempt to compare "+tag+" on "+typename()+" and "+op1.typename());
+ }
+
+ /** Perform string comparison with another value
+ * of any type
+ * using string comparison based on byte values.
+ *
+ * Only strings can be compared, meaning
+ * each operand must derive from {@link LuaString}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @returns int < 0 for {@code (this < rhs)}, int > 0 for {@code (this > rhs)}, or 0 when same string.
+ * @throws LuaError if either operand is not a string
+ */
+ public int strcmp( LuaValue rhs ) { error("attempt to compare "+typename()); return 0; }
+
+ /** Perform string comparison with another value
+ * known to be a {@link LuaString}
+ * using string comparison based on byte values.
+ *
+ * Only strings can be compared, meaning
+ * each operand must derive from {@link LuaString}.
+ *
+ * @param rhs The right-hand-side value to perform the comparison with
+ * @returns int < 0 for {@code (this < rhs)}, int > 0 for {@code (this > rhs)}, or 0 when same string.
+ * @throws LuaError if this is not a string
+ */
+ public int strcmp( LuaString rhs ) { error("attempt to compare "+typename()); return 0; }
+
+ /** Concatenate another value onto this value and return the result
+ * using rules of lua string concatenation including metatag processing.
+ *
+ * Only strings and numbers as represented can be concatenated, meaning
+ * each operand must derive from {@link LuaString} or {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side value to perform the operation with
+ * @returns {@link LuaValue} resulting from concatenation of {@code (this .. rhs)}
+ * @throws LuaError if either operand is not of an appropriate type,
+ * such as nil or a table
+ */
+ public LuaValue concat(LuaValue rhs) { return this.concatmt(rhs); }
+
+ /** Reverse-concatenation: concatenate this value onto another value
+ * whose type is unknwon
+ * and return the result using rules of lua string concatenation including
+ * metatag processing.
+ *
+ * Only strings and numbers as represented can be concatenated, meaning
+ * each operand must derive from {@link LuaString} or {@link LuaNumber}.
+ *
+ * @param lhs The left-hand-side value onto which this will be concatenated
+ * @returns {@link LuaValue} resulting from concatenation of {@code (lhs .. this)}
+ * @throws LuaError if either operand is not of an appropriate type,
+ * such as nil or a table
+ * @see #concat(LuaValue)
+ */
+ public LuaValue concatTo(LuaValue lhs) { return lhs.concatmt(this); }
+
+ /** Reverse-concatenation: concatenate this value onto another value
+ * known to be a {@link LuaNumber}
+ * and return the result using rules of lua string concatenation including
+ * metatag processing.
+ *
+ * Only strings and numbers as represented can be concatenated, meaning
+ * each operand must derive from {@link LuaString} or {@link LuaNumber}.
+ *
+ * @param lhs The left-hand-side value onto which this will be concatenated
+ * @returns {@link LuaValue} resulting from concatenation of {@code (lhs .. this)}
+ * @throws LuaError if either operand is not of an appropriate type,
+ * such as nil or a table
+ * @see #concat(LuaValue)
+ */
+ public LuaValue concatTo(LuaNumber lhs) { return lhs.concatmt(this); }
+
+ /** Reverse-concatenation: concatenate this value onto another value
+ * known to be a {@link LuaString}
+ * and return the result using rules of lua string concatenation including
+ * metatag processing.
+ *
+ * Only strings and numbers as represented can be concatenated, meaning
+ * each operand must derive from {@link LuaString} or {@link LuaNumber}.
+ *
+ * @param lhs The left-hand-side value onto which this will be concatenated
+ * @returns {@link LuaValue} resulting from concatenation of {@code (lhs .. this)}
+ * @throws LuaError if either operand is not of an appropriate type,
+ * such as nil or a table
+ * @see #concat(LuaValue)
+ */
+ public LuaValue concatTo(LuaString lhs) { return lhs.concatmt(this); }
+
+ /** Convert the value to a {@link Buffer} for more efficient concatenation of
+ * multiple strings.
+ * @return Buffer instance containing the string or number
+ */
+ public Buffer buffer() { return new Buffer(this); }
+
+ /** Concatenate a {@link Buffer} onto this value and return the result
+ * using rules of lua string concatenation including metatag processing.
+ *
+ * Only strings and numbers as represented can be concatenated, meaning
+ * each operand must derive from {@link LuaString} or {@link LuaNumber}.
+ *
+ * @param rhs The right-hand-side {@link Buffer} to perform the operation with
+ * @return LuaString resulting from concatenation of {@code (this .. rhs)}
+ * @throws LuaError if either operand is not of an appropriate type,
+ * such as nil or a table
+ */
+ public Buffer concat(Buffer rhs) { return rhs.concatTo(this); }
+
+ /** Perform metatag processing for concatenation operations.
+ *
+ * Finds the {@link CONCAT} metatag value and invokes it,
+ * or throws {@link LuaError} if it doesn't exist.
+ * @param rhs The right-hand-side value to perform the operation with
+ * @return {@link LuaValue} resulting from metatag processing for {@link CONCAT} metatag.
+ * @throws LuaError if metatag was not defined for either operand
+ */
+ public LuaValue concatmt(LuaValue rhs) {
+ LuaValue h=metatag(CONCAT);
+ if ( h.isnil() && (h=rhs.metatag(CONCAT)).isnil())
+ error("attempt to concatenate "+typename()+" and "+rhs.typename());
+ return h.call(this,rhs);
+ }
+
+ /** Perform boolean {@code and} with another operand, based on lua rules for boolean evaluation.
+ * This returns either {@code this} or {@code rhs} depending on the boolean value for {@code this}.
+ *
+ * @param rhs The right-hand-side value to perform the operation with
+ * @return {@code this} if {@code this.toboolean()} is false, {@code rhs} otherwise.
+ */
+ public LuaValue and( LuaValue rhs ) { return this.toboolean()? rhs: this; }
+
+ /** Perform boolean {@code or} with another operand, based on lua rules for boolean evaluation.
+ * This returns either {@code this} or {@code rhs} depending on the boolean value for {@code this}.
+ *
+ * @param rhs The right-hand-side value to perform the operation with
+ * @return {@code this} if {@code this.toboolean()} is true, {@code rhs} otherwise.
+ */
+ public LuaValue or( LuaValue rhs ) { return this.toboolean()? this: rhs; }
+
+ /** Perform end-condition test in for-loop processing.
+ *
+ * Used in lua-bytecode to Java-bytecode conversion.
+ *
+ * @param limit the numerical limit to complete the for loop
+ * @param step the numberical step size to use.
+ * @return true if limit has not been reached, false otherwise.
+ */
+ public boolean testfor_b(LuaValue limit, LuaValue step) { return step.gt_b(0)? lteq_b(limit): gteq_b(limit); }
+
+ /**
+ * Convert this value to a string if it is a {@link LuaString} or {@link LuaNumber},
+ * or throw a {@link LuaError} if it is not
+ * @return {@link LuaString} corresponding to the value if a string or number
+ * @throws LuaError if not a string or number
+ */
+ public LuaString strvalue() { typerror("strValue"); return null; }
+
+ /** Return the key part of this value if it is a weak table entry, or {@link NIL} if it was weak and is no longer referenced.
+ * @return {@link LuaValue} key, or {@link NIL} if it was weak and is no longer referenced.
+ * @see WeakTable
+ */
+ public LuaValue strongkey() { return strongvalue(); }
+
+ /** Return this value as a strong reference, or {@link NIL} if it was weak and is no longer referenced.
+ * @return {@link LuaValue} referred to, or {@link NIL} if it was weak and is no longer referenced.
+ * @see WeakTable
+ */
+ public LuaValue strongvalue() { return this; }
+
+ /** Test if this is a weak reference and its value no longer is referenced.
+ * @return true if this is a weak reference whose value no longer is referenced
+ * @see WeakTable
+ */
+ public boolean isweaknil() { return false; }
+
+ /** Convert java boolean to a {@link LuaValue}.
+ *
+ * @param b boolean value to convert
+ * @return {@link TRUE} if not or {@link FALSE} if false
+ */
+ public static LuaBoolean valueOf(boolean b) { return b? LuaValue.TRUE: FALSE; };
+
+ /** Convert java int to a {@link LuaValue}.
+ *
+ * @param i int value to convert
+ * @return {@link LuaInteger} instance, possibly pooled, whose value is i
+ */
+ public static LuaInteger valueOf(int i) { return LuaInteger.valueOf(i); }
+
+ /** Convert java double to a {@link LuaValue}.
+ * This may return a {@link LuaInteger} or {@link LuaDouble} depending
+ * on the value supplied.
+ *
+ * @param d double value to convert
+ * @return {@link LuaNumber} instance, possibly pooled, whose value is d
+ */
+ public static LuaNumber valueOf(double d) { return LuaDouble.valueOf(d); };
+
+ /** Convert java string to a {@link LuaValue}.
+ *
+ * @param s String value to convert
+ * @return {@link LuaString} instance, possibly pooled, whose value is s
+ */
+ public static LuaString valueOf(String s) { return LuaString.valueOf(s); }
+
+ /** Convert bytes in an array to a {@link LuaValue}.
+ *
+ * @param bytes byte array to convert
+ * @return {@link LuaString} instance, possibly pooled, whose bytes are those in the supplied array
+ */
+ public static LuaString valueOf(byte[] bytes) { return LuaString.valueOf(bytes); }
+
+ /** Convert bytes in an array to a {@link LuaValue}.
+ *
+ * @param bytes byte array to convert
+ * @param off offset into the byte array, starting at 0
+ * @param len number of bytes to include in the {@link LuaString}
+ * @return {@link LuaString} instance, possibly pooled, whose bytes are those in the supplied array
+ */
+ public static LuaString valueOf(byte[] bytes, int off, int len) {
+ return LuaString.valueOf(bytes,off,len);
+ }
+
+ /** Construct an empty {@link LuaTable}.
+ * @return new {@link LuaTable} instance with no values and no metatable.
+ */
+ public static LuaTable tableOf() { return new LuaTable(); }
+
+ /** Construct a {@link LuaTable} initialized with supplied array values.
+ * @param varargs {@link Varargs} containing the values to use in initialization
+ * @param firstarg the index of the first argument to use from the varargs, 1 being the first.
+ * @return new {@link LuaTable} instance with sequential elements coming from the varargs.
+ */
+ public static LuaTable tableOf(Varargs varargs, int firstarg) { return new LuaTable(varargs,firstarg); }
+
+ /** Construct an empty {@link LuaTable} preallocated to hold array and hashed elements
+ * @param narray Number of array elements to preallocate
+ * @param nhash Number of hash elements to preallocate
+ * @return new {@link LuaTable} instance with no values and no metatable, but preallocated for array and hashed elements.
+ */
+ public static LuaTable tableOf(int narray, int nhash) { return new LuaTable(narray, nhash); }
+
+ /** Construct a {@link LuaTable} initialized with supplied array values.
+ * @param unnamedValues array of {@link LuaValue} containing the values to use in initialization
+ * @return new {@link LuaTable} instance with sequential elements coming from the array.
+ */
+ public static LuaTable listOf(LuaValue[] unnamedValues) { return new LuaTable(null,unnamedValues,null); }
+
+ /** Construct a {@link LuaTable} initialized with supplied array values.
+ * @param unnamedValues array of {@link LuaValue} containing the first values to use in initialization
+ * @param lastarg {@link Varargs} containing additional values to use in initialization
+ * to be put after the last unnamedValues element
+ * @return new {@link LuaTable} instance with sequential elements coming from the array and varargs.
+ */
+ public static LuaTable listOf(LuaValue[] unnamedValues,Varargs lastarg) { return new LuaTable(null,unnamedValues,lastarg); }
+
+ /** Construct a {@link LuaTable} initialized with supplied named values.
+ * @param namedValues array of {@link LuaValue} containing the keys and values to use in initialization
+ * in order {@code {key-a, value-a, key-b, value-b, ...} }
+ * @return new {@link LuaTable} instance with non-sequential keys coming from the supplied array.
+ */
+ public static LuaTable tableOf(LuaValue[] namedValues) { return new LuaTable(namedValues,null,null); }
+
+ /** Construct a {@link LuaTable} initialized with supplied named values and sequential elements.
+ * The named values will be assigned first, and the sequential elements will be assigned later,
+ * possibly overwriting named values at the same slot if there are conflicts.
+ * @param namedValues array of {@link LuaValue} containing the keys and values to use in initialization
+ * in order {@code {key-a, value-a, key-b, value-b, ...} }
+ * @param unnamedValues array of {@link LuaValue} containing the sequenctial elements to use in initialization
+ * in order {@code {value-1, value-2, ...} }, or null if there are none
+ * @return new {@link LuaTable} instance with named and sequential values supplied.
+ */
+ public static LuaTable tableOf(LuaValue[] namedValues, LuaValue[] unnamedValues) {return new LuaTable(namedValues,unnamedValues,null); }
+
+ /** Construct a {@link LuaTable} initialized with supplied named values and sequential elements in an array part and as varargs.
+ * The named values will be assigned first, and the sequential elements will be assigned later,
+ * possibly overwriting named values at the same slot if there are conflicts.
+ * @param namedValues array of {@link LuaValue} containing the keys and values to use in initialization
+ * in order {@code {key-a, value-a, key-b, value-b, ...} }
+ * @param unnamedValues array of {@link LuaValue} containing the first sequenctial elements to use in initialization
+ * in order {@code {value-1, value-2, ...} }, or null if there are none
+ * @param lastarg {@link Varargs} containing additional values to use in the sequential part of the initialization,
+ * to be put after the last unnamedValues element
+ * @return new {@link LuaTable} instance with named and sequential values supplied.
+ */
+ public static LuaTable tableOf(LuaValue[] namedValues, LuaValue[] unnamedValues, Varargs lastarg) {return new LuaTable(namedValues,unnamedValues,lastarg); }
+
+ /** Construct a LuaUserdata for an object.
+ *
+ * @param o The java instance to be wrapped as userdata
+ * @return {@link LuaUserdata} value wrapping the java instance.
+ */
+ public static LuaUserdata userdataOf(Object o) { return new LuaUserdata(o); }
+
+ /** Construct a LuaUserdata for an object with a user supplied metatable.
+ *
+ * @param o The java instance to be wrapped as userdata
+ * @param metatable The metatble to associate with the userdata instance.
+ * @return {@link LuaUserdata} value wrapping the java instance.
+ */
+ public static LuaUserdata userdataOf(Object o,LuaValue metatable) { return new LuaUserdata(o,metatable); }
+
+ /** Constant limiting metatag loop processing */
+ private static final int MAXTAGLOOP = 100;
+
+ /**
+ * Return value for field reference including metatag processing, or {@link LuaValue#NIL} if it doesn't exist.
+ * @param t {@link LuaValue} on which field is being referenced, typically a table or something with the metatag {@link LuaValue#INDEX} defined
+ * @param key {@link LuaValue} naming the field to reference
+ * @return {@link LuaValue} for the {@code key} if it exists, or {@link LuaValue#NIL}
+ * @throws LuaError if there is a loop in metatag processing
+ */
+ /** get value from metatable operations, or NIL if not defined by metatables */
+ protected static LuaValue gettable(LuaValue t, LuaValue key) {
+ LuaValue tm;
+ int loop = 0;
+ do {
+ if (t.istable()) {
+ LuaValue res = t.rawget(key);
+ if ((!res.isnil()) || (tm = t.metatag(INDEX)).isnil())
+ return res;
+ } else if ((tm = t.metatag(INDEX)).isnil())
+ t.indexerror();
+ if (tm.isfunction())
+ return tm.call(t, key);
+ t = tm;
+ }
+ while ( ++loop < MAXTAGLOOP );
+ error("loop in gettable");
+ return NIL;
+ }
+
+ /**
+ * Perform field assignment including metatag processing.
+ * @param t {@link LuaValue} on which value is being set, typically a table or something with the metatag {@link LuaValue#NEWINDEX} defined
+ * @param key {@link LuaValue} naming the field to assign
+ * @param value {@link LuaValue} the new value to assign to {@code key}
+ * @throws LuaError if there is a loop in metatag processing
+ * @return true if assignment or metatag processing succeeded, false otherwise
+ */
+ protected static boolean settable(LuaValue t, LuaValue key, LuaValue value) {
+ LuaValue tm;
+ int loop = 0;
+ do {
+ if (t.istable()) {
+ if ((!t.rawget(key).isnil()) || (tm = t.metatag(NEWINDEX)).isnil()) {
+ t.rawset(key, value);
+ return true;
+ }
+ } else if ((tm = t.metatag(NEWINDEX)).isnil())
+ t.typerror("index");
+ if (tm.isfunction()) {
+ tm.call(t, key, value);
+ return true;
+ }
+ t = tm;
+ }
+ while ( ++loop < MAXTAGLOOP );
+ error("loop in settable");
+ return false;
+ }
+
+ /**
+ * Get particular metatag, or return {@link LuaValue#NIL} if it doesn't exist
+ * @param tag Metatag name to look up, typically a string such as
+ * {@link LuaValue#INDEX} or {@link LuaValue#NEWINDEX}
+ * @param reason Description of error when tag lookup fails.
+ * @return {@link LuaValue} for tag {@code reason}, or {@link LuaValue#NIL}
+ */
+ public LuaValue metatag(LuaValue tag) {
+ LuaValue mt = getmetatable();
+ if ( mt == null )
+ return NIL;
+ return mt.rawget(tag);
+ }
+
+ /**
+ * Get particular metatag, or throw {@link LuaError} if it doesn't exist
+ * @param tag Metatag name to look up, typically a string such as
+ * {@link LuaValue#INDEX} or {@link LuaValue#NEWINDEX}
+ * @param reason Description of error when tag lookup fails.
+ * @return {@link LuaValue} that can be called
+ * @throws LuaError when the lookup fails.
+ */
+ protected LuaValue checkmetatag(LuaValue tag, String reason) {
+ LuaValue h = this.metatag(tag);
+ if ( h.isnil() )
+ throw new LuaError(reason+typename());
+ return h;
+ }
+
+ /** Throw {@link LuaError} indicating index was attempted on illegal type
+ * @throws LuaError when called.
+ */
+ private void indexerror() {
+ error( "attempt to index ? (a "+typename()+" value)" );
+ }
+
+ /** Construct a {@link Varargs} around an array of {@link LuaValue}s.
+ *
+ * @param v The array of {@link LuaValue}s
+ * @param more {@link Varargs} contain values to include at the end
+ * @return {@link Varargs} wrapping the supplied values.
+ * @see LuaValue#varargsOf(LuaValue, Varargs)
+ * @see LuaValue#varargsOf(LuaValue[], int, int)
+ */
+ public static Varargs varargsOf(final LuaValue[] v) {
+ switch ( v.length ) {
+ case 0: return NONE;
+ case 1: return v[0];
+ case 2: return new PairVarargs(v[0],v[1]);
+ default: return new ArrayVarargs(v,NONE);
+ }
+ }
+
+ /** Construct a {@link Varargs} around an array of {@link LuaValue}s.
+ *
+ * @param v The array of {@link LuaValue}s
+ * @param more {@link Varargs} contain values to include at the end
+ * @return {@link Varargs} wrapping the supplied values.
+ * @see LuaValue#varargsOf(LuaValue[])
+ * @see LuaValue#varargsOf(LuaValue[], int, int, Varargs)
+ */
+ public static Varargs varargsOf(final LuaValue[] v,Varargs r) {
+ switch ( v.length ) {
+ case 0: return r;
+ case 1: return new PairVarargs(v[0],r);
+ default: return new ArrayVarargs(v,r);
+ }
+ }
+
+ /** Construct a {@link Varargs} around an array of {@link LuaValue}s.
+ *
+ * @param v The array of {@link LuaValue}s
+ * @param offset number of initial values to skip in the array
+ * @param length number of values to include from the array
+ * @return {@link Varargs} wrapping the supplied values.
+ * @see LuaValue#varargsOf(LuaValue[])
+ * @see LuaValue#varargsOf(LuaValue[], int, int, Varargs)
+ */
+ public static Varargs varargsOf(final LuaValue[] v, final int offset, final int length) {
+ switch ( length ) {
+ case 0: return NONE;
+ case 1: return v[offset];
+ case 2: return new PairVarargs(v[offset+0],v[offset+1]);
+ default: return new ArrayPartVarargs(v,offset,length);
+ }
+ }
+
+ /** Construct a {@link Varargs} around an array of {@link LuaValue}s.
+ *
+ * @param v The array of {@link LuaValue}s
+ * @param offset number of initial values to skip in the array
+ * @param length number of values to include from the array
+ * @param more {@link Varargs} contain values to include at the end
+ * @return {@link Varargs} wrapping the supplied values.
+ * @see LuaValue#varargsOf(LuaValue[], Varargs)
+ * @see LuaValue#varargsOf(LuaValue[], int, int)
+ */
+ public static Varargs varargsOf(final LuaValue[] v, final int offset, final int length,Varargs more) {
+ switch ( length ) {
+ case 0: return more;
+ case 1: return new PairVarargs(v[offset],more);
+ default: return new ArrayPartVarargs(v,offset,length,more);
+ }
+ }
+
+ /** Construct a {@link Varargs} around a set of 2 or more {@link LuaValue}s.
+ *
+ * This can be used to wrap exactly 2 values, or a list consisting of 1 initial value
+ * followed by another variable list of remaining values.
+ *
+ * @param v1 First {@link LuaValue} in the {@link Varargs}
+ * @param v2 {@link LuaValue} supplying the 2rd value,
+ * or {@link Varargs}s supplying all values beyond the first
+ * @return {@link Varargs} wrapping the supplied values.
+ */
+ public static Varargs varargsOf(LuaValue v, Varargs r) {
+ switch ( r.narg() ) {
+ case 0: return v;
+ default: return new PairVarargs(v,r);
+ }
+ }
+
+ /** Construct a {@link Varargs} around a set of 3 or more {@link LuaValue}s.
+ *
+ * This can be used to wrap exactly 3 values, or a list consisting of 2 initial values
+ * followed by another variable list of remaining values.
+ *
+ * @param v1 First {@link LuaValue} in the {@link Varargs}
+ * @param v2 Second {@link LuaValue} in the {@link Varargs}
+ * @param v3 {@link LuaValue} supplying the 3rd value,
+ * or {@link Varargs}s supplying all values beyond the second
+ * @return {@link Varargs} wrapping the supplied values.
+ */
+ public static Varargs varargsOf(LuaValue v1,LuaValue v2,Varargs v3) {
+ switch ( v3.narg() ) {
+ case 0: return new PairVarargs(v1,v2);
+ default: return new ArrayVarargs(new LuaValue[] {v1,v2},v3);
+ }
+ }
+
+ /** Construct a {@link TailcallVarargs} around a function and arguments.
+ *
+ * The tail call is not yet called or processing until the client invokes
+ * {@link TailcallVarargs#eval()} which performs the tail call processing.
+ *
+ * This method is typically not used directly by client code.
+ * Instead use one of the function invocation methods.
+ *
+ * @param func {@link LuaValue} to be called as a tail call
+ * @param args {@link Varargs} containing the arguments to the call
+ * @return {@link TailcallVarargs} to be used in tailcall oprocessing.
+ * @see LuaValue#call()
+ * @see LuaValue#invoke()
+ * @see LuaValue#method(LuaValue)
+ * @see LuaValue#invokemethod(LuaValue)
+ */
+ public static Varargs tailcallOf(LuaValue func, Varargs args) {
+ return new TailcallVarargs(func, args);
+ }
+
+ /**
+ * Callback used during tail call processing to invoke the function once.
+ *
+ * This may return a {@link TailcallVarargs} to be evaluated by the client.
+ *
+ * This should not be called directly, instead use on of the call invocation functions.
+ *
+ * @param args the arguments to the call invocation.
+ * @return Varargs the return values, possible a TailcallVarargs.
+ * @see LuaValue#call()
+ * @see LuaValue#invoke()
+ * @see LuaValue#method(LuaValue)
+ * @see LuaValue#invokemethod(LuaValue)
+ */
+ public Varargs onInvoke(Varargs args) {
+ return invoke(args);
+ }
+
+ /** Varargs implemenation with no values.
+ *
+ * This is an internal class not intended to be used directly.
+ * Instead use the predefined constant {@link LuaValue#NONE}
+ *
+ * @see LuaValue#NONE
+ */
+ private static final class None extends LuaNil {
+ static None _NONE = new None();
+ public LuaValue arg(int i) { return NIL; }
+ public int narg() { return 0; }
+ public LuaValue arg1() { return NIL; }
+ public String tojstring() { return "none"; }
+ }
+
+ /** Varargs implemenation backed by an array of LuaValues
+ *
+ * This is an internal class not intended to be used directly.
+ * Instead use the corresponding static methods on LuaValue.
+ *
+ * @see LuaValue#varargsOf(LuaValue[])
+ * @see LuaValue#varargsOf(LuaValue[], Varargs)
+ */
+ static final class ArrayVarargs extends Varargs {
+ private final LuaValue[] v;
+ private final Varargs r;
+ /** Construct a Varargs from an array of LuaValue.
+ *
+ * This is an internal class not intended to be used directly.
+ * Instead use the corresponding static methods on LuaValue.
+ *
+ * @see LuaValue#varargsOf(LuaValue[])
+ * @see LuaValue#varargsOf(LuaValue[], Varargs)
+ */
+ ArrayVarargs(LuaValue[] v, Varargs r) {
+ this.v = v;
+ this.r = r ;
+ }
+ public LuaValue arg(int i) {
+ return i >=1 && i<=v.length? v[i - 1]: r.arg(i-v.length);
+ }
+ public int narg() {
+ return v.length+r.narg();
+ }
+ public LuaValue arg1() { return v.length>0? v[0]: r.arg1(); }
+ }
+
+ /** Varargs implemenation backed by an array of LuaValues
+ *
+ * This is an internal class not intended to be used directly.
+ * Instead use the corresponding static methods on LuaValue.
+ *
+ * @see LuaValue#varargsOf(LuaValue[], int, int)
+ * @see LuaValue#varargsOf(LuaValue[], int, int, Varargs)
+ */
+ static final class ArrayPartVarargs extends Varargs {
+ private final int offset;
+ private final LuaValue[] v;
+ private final int length;
+ private final Varargs more;
+ /** Construct a Varargs from an array of LuaValue.
+ *
+ * This is an internal class not intended to be used directly.
+ * Instead use the corresponding static methods on LuaValue.
+ *
+ * @see LuaValue#varargsOf(LuaValue[], int, int)
+ */
+ ArrayPartVarargs(LuaValue[] v, int offset, int length) {
+ this.v = v;
+ this.offset = offset;
+ this.length = length;
+ this.more = NONE;
+ }
+ /** Construct a Varargs from an array of LuaValue and additional arguments.
+ *
+ * This is an internal class not intended to be used directly.
+ * Instead use the corresponding static method on LuaValue.
+ *
+ * @see LuaValue#varargsOf(LuaValue[], int, int, Varargs)
+ */
+ public ArrayPartVarargs(LuaValue[] v, int offset, int length, Varargs more) {
+ this.v = v;
+ this.offset = offset;
+ this.length = length;
+ this.more = more;
+ }
+ public LuaValue arg(int i) {
+ return i>=1&&i<=length? v[i+offset-1]: more.arg(i-length);
+ }
+ public int narg() {
+ return length + more.narg();
+ }
+ public LuaValue arg1() {
+ return length>0? v[offset]: more.arg1();
+ }
+ }
+
+ /** Varargs implemenation backed by two values.
+ *
+ * This is an internal class not intended to be used directly.
+ * Instead use the corresponding static method on LuaValue.
+ *
+ * @see LuaValue#varargsOf(LuaValue, Varargs)
+ */
+ static final class PairVarargs extends Varargs {
+ private final LuaValue v1;
+ private final Varargs v2;
+ /** Construct a Varargs from an two LuaValue.
+ *
+ * This is an internal class not intended to be used directly.
+ * Instead use the corresponding static method on LuaValue.
+ *
+ * @see LuaValue#varargsOf(LuaValue, Varargs)
+ */
+ PairVarargs(LuaValue v1, Varargs v2) {
+ this.v1 = v1;
+ this.v2 = v2;
+ }
+ public LuaValue arg(int i) {
+ return i==1? v1: v2.arg(i-1);
+ }
+ public int narg() {
+ return 1+v2.narg();
+ }
+ public LuaValue arg1() {
+ return v1;
+ }
+ }
+
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/OrphanedThread.java b/luaj-2.0.3/src/core/org/luaj/vm2/OrphanedThread.java
new file mode 100644
index 0000000000..668217be3e
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/OrphanedThread.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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;
+
+/**
+ * {@link java.lang.Error} sublcass that indicates a lua thread that is no
+ * longer referenced has been detected.
+ *
+ * The java thread in which this is thrown should correspond to a
+ * {@link LuaThread} being used as a coroutine that could not possibly be
+ * resumed again because there are no more references to the LuaThread with
+ * which it is associated. Rather than locking up resources forever, this error
+ * is thrown, and should fall through all the way to the thread's {@link Thread.run}() method.
+ *
+ * Java code mixed with the luaj vm should not catch this error because it may
+ * occur when the coroutine is not running, so any processing done during error
+ * handling could break the thread-safety of the application because other lua
+ * processing could be going on in a different thread.
+ */
+public class OrphanedThread extends Error {
+
+ public OrphanedThread() {
+ super("orphaned thread");
+ }
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/Print.java b/luaj-2.0.3/src/core/org/luaj/vm2/Print.java
new file mode 100644
index 0000000000..72c2f8f92b
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/Print.java
@@ -0,0 +1,417 @@
+/*******************************************************************************
+* 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 java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+/**
+ * Debug helper class to pretty-print lua bytecodes.
+ * @see Prototype
+ * @see LuaClosure
+ */
+public class Print extends Lua {
+
+ /** opcode names */
+ private static final String STRING_FOR_NULL = "null";
+ public static PrintStream ps = System.out;
+
+ public static final String[] OPNAMES = {
+ "MOVE",
+ "LOADK",
+ "LOADBOOL",
+ "LOADNIL",
+ "GETUPVAL",
+ "GETGLOBAL",
+ "GETTABLE",
+ "SETGLOBAL",
+ "SETUPVAL",
+ "SETTABLE",
+ "NEWTABLE",
+ "SELF",
+ "ADD",
+ "SUB",
+ "MUL",
+ "DIV",
+ "MOD",
+ "POW",
+ "UNM",
+ "NOT",
+ "LEN",
+ "CONCAT",
+ "JMP",
+ "EQ",
+ "LT",
+ "LE",
+ "TEST",
+ "TESTSET",
+ "CALL",
+ "TAILCALL",
+ "RETURN",
+ "FORLOOP",
+ "FORPREP",
+ "TFORLOOP",
+ "SETLIST",
+ "CLOSE",
+ "CLOSURE",
+ "VARARG",
+ null,
+ };
+
+
+ static void printString(PrintStream ps, final LuaString s) {
+
+ ps.print('"');
+ for (int i = 0, n = s.m_length; i < n; i++) {
+ int c = s.m_bytes[s.m_offset+i];
+ if ( c >= ' ' && c <= '~' && c != '\"' && c != '\\' )
+ ps.print((char) c);
+ else {
+ switch (c) {
+ case '"':
+ ps.print("\\\"");
+ break;
+ case '\\':
+ ps.print("\\\\");
+ break;
+ case 0x0007: /* bell */
+ ps.print("\\a");
+ break;
+ case '\b': /* backspace */
+ ps.print("\\b");
+ break;
+ case '\f': /* form feed */
+ ps.print("\\f");
+ break;
+ case '\t': /* tab */
+ ps.print("\\t");
+ break;
+ case '\r': /* carriage return */
+ ps.print("\\r");
+ break;
+ case '\n': /* newline */
+ ps.print("\\n");
+ break;
+ case 0x000B: /* vertical tab */
+ ps.print("\\v");
+ break;
+ default:
+ ps.print('\\');
+ ps.print(Integer.toString(1000 + 0xff&c).substring(1));
+ break;
+ }
+ }
+ }
+ ps.print('"');
+ }
+
+ static void printValue( PrintStream ps, LuaValue v ) {
+ switch ( v.type() ) {
+ case LuaValue.TSTRING: printString( ps, (LuaString) v ); break;
+ default: ps.print( v.tojstring() );
+
+ }
+ }
+
+ static void printConstant(PrintStream ps, Prototype f, int i) {
+ printValue( ps, f.k[i] );
+ }
+
+ /**
+ * Print the code in a prototype
+ * @param f the {@link Prototype}
+ */
+ public static void printCode(Prototype f) {
+ int[] code = f.code;
+ int pc, n = code.length;
+ for (pc = 0; pc < n; pc++) {
+ printOpCode(f, pc);
+ ps.println();
+ }
+ }
+
+ /**
+ * Print an opcode in a prototype
+ * @param f the {@link Prototype}
+ * @param pc the program counter to look up and print
+ */
+ public static void printOpCode(Prototype f, int pc) {
+ printOpCode(ps,f,pc);
+ }
+
+ /**
+ * Print an opcode in a prototype
+ * @param ps the {@link PrintStream} to print to
+ * @param f the {@link Prototype}
+ * @param pc the program counter to look up and print
+ */
+ public static void printOpCode(PrintStream ps, Prototype f, int pc) {
+ int[] code = f.code;
+ int i = code[pc];
+ int o = GET_OPCODE(i);
+ int a = GETARG_A(i);
+ int b = GETARG_B(i);
+ int c = GETARG_C(i);
+ int bx = GETARG_Bx(i);
+ int sbx = GETARG_sBx(i);
+ int line = getline(f, pc);
+ ps.print(" " + (pc + 1) + " ");
+ if (line > 0)
+ ps.print("[" + line + "] ");
+ else
+ ps.print("[-] ");
+ ps.print(OPNAMES[o] + " ");
+ switch (getOpMode(o)) {
+ case iABC:
+ ps.print( a );
+ if (getBMode(o) != OpArgN)
+ ps.print(" "+(ISK(b) ? (-1 - INDEXK(b)) : b));
+ if (getCMode(o) != OpArgN)
+ ps.print(" "+(ISK(c) ? (-1 - INDEXK(c)) : c));
+ break;
+ case iABx:
+ if (getBMode(o) == OpArgK) {
+ ps.print(a + " " + (-1 - bx));
+ } else {
+ ps.print(a + " " + (bx));
+ }
+ break;
+ case iAsBx:
+ if (o == OP_JMP)
+ ps.print( sbx );
+ else
+ ps.print(a + " " + sbx);
+ break;
+ }
+ switch (o) {
+ case OP_LOADK:
+ ps.print(" ; ");
+ printConstant(ps, f, bx);
+ break;
+ case OP_GETUPVAL:
+ case OP_SETUPVAL:
+ ps.print(" ; ");
+ if ( f.upvalues.length > b )
+ printValue(ps, f.upvalues[b]);
+ else
+ ps.print( "-" );
+ break;
+ case OP_GETGLOBAL:
+ case OP_SETGLOBAL:
+ ps.print(" ; ");
+ printConstant( ps, f, bx );
+ break;
+ case OP_GETTABLE:
+ case OP_SELF:
+ if (ISK(c)) {
+ ps.print(" ; ");
+ printConstant(ps, f, INDEXK(c));
+ }
+ break;
+ case OP_SETTABLE:
+ case OP_ADD:
+ case OP_SUB:
+ case OP_MUL:
+ case OP_DIV:
+ case OP_POW:
+ case OP_EQ:
+ case OP_LT:
+ case OP_LE:
+ if (ISK(b) || ISK(c)) {
+ ps.print(" ; ");
+ if (ISK(b))
+ printConstant(ps, f, INDEXK(b));
+ else
+ ps.print("-");
+ ps.print(" ");
+ if (ISK(c))
+ printConstant(ps, f, INDEXK(c));
+ else
+ ps.print("-");
+ }
+ break;
+ case OP_JMP:
+ case OP_FORLOOP:
+ case OP_FORPREP:
+ ps.print(" ; to " + (sbx + pc + 2));
+ break;
+ case OP_CLOSURE:
+ ps.print(" ; " + f.p[bx].getClass().getName());
+ break;
+ case OP_SETLIST:
+ if (c == 0)
+ ps.print(" ; " + ((int) code[++pc]));
+ else
+ ps.print(" ; " + ((int) c));
+ break;
+ case OP_VARARG:
+ ps.print( " ; is_vararg="+ f.is_vararg );
+ break;
+ default:
+ break;
+ }
+ }
+
+ private static int getline(Prototype f, int pc) {
+ return pc>0 && f.lineinfo!=null && pc
+ * See documentatation on {@link LuaClosure} for information on how to load
+ * and execute a {@link Prototype}.
+ * @see LuaClosure
+ */
+
+public class Prototype {
+ /* constants used by the function */
+ public LuaValue[] k;
+ public int[] code;
+ /* functions defined inside the function */
+ public Prototype[] p;
+ /* map from opcodes to source lines */
+ public int[] lineinfo;
+ /* information about local variables */
+ public LocVars[] locvars;
+ /* upvalue names */
+ public LuaString[] upvalues;
+ public LuaString source;
+ public int nups;
+ public int linedefined;
+ public int lastlinedefined;
+ public int numparams;
+ public int is_vararg;
+ public int maxstacksize;
+
+
+ public String toString() {
+ return source + ":" + linedefined+"-"+lastlinedefined;
+ }
+
+ /** Get the name of a local variable.
+ *
+ * @param number the local variable number to look up
+ * @param pc the program counter
+ * @return the name, or null if not found
+ */
+ public LuaString getlocalname(int number, int pc) {
+ int i;
+ for (i = 0; i
+ * The tail call holds the next function and arguments,
+ * and the client a call to {@link #eval()} executes the function
+ * repeatedly until the tail calls are completed.
+ *
+ * Normally, users of luaj need not concern themselves with the
+ * details of this mechanism, as it is built into the core
+ * execution framework.
+ * @see Prototype
+ * @see LuaJC
+ */
+public class TailcallVarargs extends Varargs {
+
+ private LuaValue func;
+ private Varargs args;
+ private Varargs result;
+
+ public TailcallVarargs(LuaValue f, Varargs args) {
+ this.func = f;
+ this.args = args;
+ }
+
+ public TailcallVarargs(LuaValue object, LuaValue methodname, Varargs args) {
+ this.func = object.get(methodname);
+ this.args = LuaValue.varargsOf(object, args);
+ }
+
+ public boolean isTailcall() {
+ return true;
+ }
+
+ public Varargs eval() {
+ while ( result == null ) {
+ Varargs r = func.onInvoke(args);
+ if (r.isTailcall()) {
+ TailcallVarargs t = (TailcallVarargs) r;
+ func = t.func;
+ args = t.args;
+ }
+ else {
+ result = r;
+ func = null;
+ args = null;
+ }
+ }
+ return result;
+ }
+
+ public LuaValue arg( int i ) {
+ if ( result == null )
+ eval();
+ return result.arg(i);
+ }
+
+ public LuaValue arg1() {
+ if (result == null)
+ eval();
+ return result.arg1();
+ }
+
+ public int narg() {
+ if (result == null)
+ eval();
+ return result.narg();
+ }
+}
\ No newline at end of file
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/UpValue.java b/luaj-2.0.3/src/core/org/luaj/vm2/UpValue.java
new file mode 100644
index 0000000000..072dd34841
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/UpValue.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+* Copyright (c) 2009-2011 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;
+
+
+/** Upvalue used with Closure formulation
+ *
+ * @see LuaClosure
+ * @see Prototype
+ */
+public final class UpValue {
+
+ LuaValue[] array; // initially the stack, becomes a holder
+ int index;
+
+ /**
+ * Create an upvalue relative to a stack
+ * @param stack the stack
+ * @param index the index on the stack for the upvalue
+ */
+ public UpValue( LuaValue[] stack, int index) {
+ this.array = stack;
+ this.index = index;
+ }
+
+ /**
+ * Convert this upvalue to a Java String
+ * @return the Java String for this upvalue.
+ * @see LuaValue#tojstring()
+ */
+ public String tojstring() {
+ return array[index].tojstring();
+ }
+
+ /**
+ * Get the value of the upvalue
+ * @return the {@link LuaValue} for this upvalue
+ */
+ public final LuaValue getValue() {
+ return array[index];
+ }
+
+ /**
+ * Set the value of the upvalue
+ * @param the {@link LuaValue} to set it to
+ */
+ public final void setValue( LuaValue value ) {
+ array[index] = value;
+ }
+
+ /**
+ * Close this upvalue so it is no longer on the stack
+ */
+ public final void close() {
+ array = new LuaValue[] { array[index] };
+ index = 0;
+ }
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/Varargs.java b/luaj-2.0.3/src/core/org/luaj/vm2/Varargs.java
new file mode 100644
index 0000000000..340bdd20ca
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/Varargs.java
@@ -0,0 +1,537 @@
+/*******************************************************************************
+* 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;
+
+/**
+ * Class to encapsulate varargs values, either as part of a variable argument list, or multiple return values.
+ *
+ * To construct varargs, use one of the static methods such as
+ * {@code LuaValue.varargsOf(LuaValue,LuaValue)}
+ *
+ *
+ * Any LuaValue can be used as a stand-in for Varargs, for both calls and return values.
+ * When doing so, nargs() will return 1 and arg1() or arg(1) will return this.
+ * This simplifies the case when calling or implementing varargs functions with only
+ * 1 argument or 1 return value.
+ *
+ * Varargs can also be derived from other varargs by appending to the front with a call
+ * such as {@code LuaValue.varargsOf(LuaValue,Varargs)}
+ * or by taking a portion of the args using {@code Varargs.subargs(int start)}
+ *
+ * @see LuaValue#varargsOf(LuaValue[])
+ * @see LuaValue#varargsOf(LuaValue, Varargs)
+ * @see LuaValue#varargsOf(LuaValue[], Varargs)
+ * @see LuaValue#varargsOf(LuaValue, LuaValue, Varargs)
+ * @see LuaValue#varargsOf(LuaValue[], int, int)
+ * @see LuaValue#varargsOf(LuaValue[], int, int, Varargs)
+ * @see LuaValue#subargs(int)
+ */
+public abstract class Varargs {
+
+ /**
+ * Get the n-th argument value (1-based).
+ * @param i the index of the argument to get, 1 is the first argument
+ * @return Value at position i, or LuaValue.NIL if there is none.
+ * @see Varargs#arg1()
+ * @see LuaValue#NIL
+ */
+ abstract public LuaValue arg( int i );
+
+ /**
+ * Get the number of arguments, or 0 if there are none.
+ * @return number of arguments.
+ */
+ abstract public int narg();
+
+ /**
+ * Get the first argument in the list.
+ * @return LuaValue which is first in the list, or LuaValue.NIL if there are no values.
+ * @see Varargs#arg(int)
+ * @see LuaValue#NIL
+ */
+ abstract public LuaValue arg1();
+
+ /**
+ * Evaluate any pending tail call and return result.
+ * @return the evaluated tail call result
+ */
+ public Varargs eval() { return this; }
+
+ /**
+ * Return true if this is a TailcallVarargs
+ * @return true if a tail call, false otherwise
+ */
+ public boolean isTailcall() {
+ return false;
+ }
+
+ // -----------------------------------------------------------------------
+ // utilities to get specific arguments and type-check them.
+ // -----------------------------------------------------------------------
+
+ /** Gets the type of argument {@code i}
+ * @param i the index of the argument to convert, 1 is the first argument
+ * @return int value corresponding to one of the LuaValue integer type values
+ * @see LuaValue.TNIL
+ * @see LuaValue.TBOOLEAN
+ * @see LuaValue.TNUMBER
+ * @see LuaValue.TSTRING
+ * @see LuaValue.TTABLE
+ * @see LuaValue.TFUNCTION
+ * @see LuaValue.TUSERDATA
+ * @see LuaValue.TTHREAD
+ * */
+ public int type(int i) { return arg(i).type(); }
+
+ /** Tests if argument i is nil.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return true if the argument is nil or does not exist, false otherwise
+ * @see LuaValue.TNIL
+ * */
+ public boolean isnil(int i) { return arg(i).isnil(); }
+
+ /** Tests if argument i is a function.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return true if the argument exists and is a function or closure, false otherwise
+ * @see LuaValue.TFUNCTION
+ * */
+ public boolean isfunction(int i) { return arg(i).isfunction(); }
+
+ /** Tests if argument i is a number.
+ * Since anywhere a number is required, a string can be used that
+ * is a number, this will return true for both numbers and
+ * strings that can be interpreted as numbers.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return true if the argument exists and is a number or
+ * string that can be interpreted as a number, false otherwise
+ * @see LuaValue.TNUMBER
+ * @see LuaValue.TSTRING
+ * */
+ public boolean isnumber(int i) { return arg(i).isnumber(); }
+
+ /** Tests if argument i is a string.
+ * Since all lua numbers can be used where strings are used,
+ * this will return true for both strings and numbers.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return true if the argument exists and is a string or number, false otherwise
+ * @see LuaValue.TNUMBER
+ * @see LuaValue.TSTRING
+ * */
+ public boolean isstring(int i) { return arg(i).isstring(); }
+
+ /** Tests if argument i is a table.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return true if the argument exists and is a lua table, false otherwise
+ * @see LuaValue.TTABLE
+ * */
+ public boolean istable(int i) { return arg(i).istable(); }
+
+ /** Tests if argument i is a thread.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return true if the argument exists and is a lua thread, false otherwise
+ * @see LuaValue.TTHREAD
+ * */
+ public boolean isthread(int i) { return arg(i).isthread(); }
+
+ /** Tests if argument i is a userdata.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return true if the argument exists and is a userdata, false otherwise
+ * @see LuaValue.TUSERDATA
+ * */
+ public boolean isuserdata(int i) { return arg(i).isuserdata(); }
+
+ /** Tests if a value exists at argument i.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return true if the argument exists, false otherwise
+ * */
+ public boolean isvalue(int i) { return i>0 && i<=narg(); }
+
+ /** Return argument i as a boolean value, {@code defval} if nil, or throw a LuaError if any other type.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return true if argument i is boolean true, false if it is false, or defval if not supplied or nil
+ * @exception LuaError if the argument is not a lua boolean
+ * */
+ public boolean optboolean(int i, boolean defval) { return arg(i).optboolean(defval); }
+
+ /** Return argument i as a closure, {@code defval} if nil, or throw a LuaError if any other type.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaClosure if argument i is a closure, or defval if not supplied or nil
+ * @exception LuaError if the argument is not a lua closure
+ * */
+ public LuaClosure optclosure(int i, LuaClosure defval) { return arg(i).optclosure(defval); }
+
+ /** Return argument i as a double, {@code defval} if nil, or throw a LuaError if it cannot be converted to one.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return java double value if argument i is a number or string that converts to a number, or defval if not supplied or nil
+ * @exception LuaError if the argument is not a number
+ * */
+ public double optdouble(int i, double defval) { return arg(i).optdouble(defval); }
+
+ /** Return argument i as a function, {@code defval} if nil, or throw a LuaError if an incompatible type.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaValue that can be called if argument i is lua function or closure, or defval if not supplied or nil
+ * @exception LuaError if the argument is not a lua function or closure
+ * */
+ public LuaFunction optfunction(int i, LuaFunction defval) { return arg(i).optfunction(defval); }
+
+ /** Return argument i as a java int value, discarding any fractional part, {@code defval} if nil, or throw a LuaError if not a number.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return int value with fraction discarded and truncated if necessary if argument i is number, or defval if not supplied or nil
+ * @exception LuaError if the argument is not a number
+ * */
+ public int optint(int i, int defval) { return arg(i).optint(defval); }
+
+ /** Return argument i as a java int value, {@code defval} if nil, or throw a LuaError if not a number or is not representable by a java int.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaInteger value that fits in a java int without rounding, or defval if not supplied or nil
+ * @exception LuaError if the argument cannot be represented by a java int value
+ * */
+ public LuaInteger optinteger(int i, LuaInteger defval) { return arg(i).optinteger(defval); }
+
+ /** Return argument i as a java long value, discarding any fractional part, {@code defval} if nil, or throw a LuaError if not a number.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return long value with fraction discarded and truncated if necessary if argument i is number, or defval if not supplied or nil
+ * @exception LuaError if the argument is not a number
+ * */
+ public long optlong(int i, long defval) { return arg(i).optlong(defval); }
+
+ /** Return argument i as a LuaNumber, {@code defval} if nil, or throw a LuaError if not a number or string that can be converted to a number.
+ * @param i the index of the argument to test, 1 is the first argument, or defval if not supplied or nil
+ * @return LuaNumber if argument i is number or can be converted to a number
+ * @exception LuaError if the argument is not a number
+ * */
+ public LuaNumber optnumber(int i, LuaNumber defval) { return arg(i).optnumber(defval); }
+
+ /** Return argument i as a java String if a string or number, {@code defval} if nil, or throw a LuaError if any other type
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return String value if argument i is a string or number, or defval if not supplied or nil
+ * @exception LuaError if the argument is not a string or number
+ * */
+ public String optjstring(int i, String defval) { return arg(i).optjstring(defval); }
+
+ /** Return argument i as a LuaString if a string or number, {@code defval} if nil, or throw a LuaError if any other type
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaString value if argument i is a string or number, or defval if not supplied or nil
+ * @exception LuaError if the argument is not a string or number
+ * */
+ public LuaString optstring(int i, LuaString defval) { return arg(i).optstring(defval); }
+
+ /** Return argument i as a LuaTable if a lua table, {@code defval} if nil, or throw a LuaError if any other type.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaTable value if a table, or defval if not supplied or nil
+ * @exception LuaError if the argument is not a lua table
+ * */
+ public LuaTable opttable(int i, LuaTable defval) { return arg(i).opttable(defval); }
+
+ /** Return argument i as a LuaThread if a lua thread, {@code defval} if nil, or throw a LuaError if any other type.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaThread value if a thread, or defval if not supplied or nil
+ * @exception LuaError if the argument is not a lua thread
+ * */
+ public LuaThread optthread(int i, LuaThread defval) { return arg(i).optthread(defval); }
+
+ /** Return argument i as a java Object if a userdata, {@code defval} if nil, or throw a LuaError if any other type.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return java Object value if argument i is a userdata, or defval if not supplied or nil
+ * @exception LuaError if the argument is not a userdata
+ * */
+ public Object optuserdata(int i, Object defval) { return arg(i).optuserdata(defval); }
+
+ /** Return argument i as a java Object if it is a userdata whose instance Class c or a subclass,
+ * {@code defval} if nil, or throw a LuaError if any other type.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @param c the class to which the userdata instance must be assignable
+ * @return java Object value if argument i is a userdata whose instance Class c or a subclass, or defval if not supplied or nil
+ * @exception LuaError if the argument is not a userdata or from whose instance c is not assignable
+ * */
+ public Object optuserdata(int i, Class c, Object defval) { return arg(i).optuserdata(c,defval); }
+
+ /** Return argument i as a LuaValue if it exists, or {@code defval}.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaValue value if the argument exists, defval if not
+ * @exception LuaError if the argument does not exist.
+ * */
+ public LuaValue optvalue(int i, LuaValue defval) { return i>0 && i<=narg()? arg(i): defval; }
+
+ /** Return argument i as a boolean value, or throw an error if any other type.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return true if argument i is boolean true, false if it is false
+ * @exception LuaError if the argument is not a lua boolean
+ * */
+ public boolean checkboolean(int i) { return arg(i).checkboolean(); }
+
+ /** Return argument i as a closure, or throw an error if any other type.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaClosure if argument i is a closure.
+ * @exception LuaError if the argument is not a lua closure
+ * */
+ public LuaClosure checkclosure(int i) { return arg(i).checkclosure(); }
+
+ /** Return argument i as a double, or throw an error if it cannot be converted to one.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return java double value if argument i is a number or string that converts to a number
+ * @exception LuaError if the argument is not a number
+ * */
+ public double checkdouble(int i) { return arg(i).checknumber().todouble(); }
+
+ /** Return argument i as a function, or throw an error if an incompatible type.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaValue that can be called if argument i is lua function or closure
+ * @exception LuaError if the argument is not a lua function or closure
+ * */
+ public LuaValue checkfunction(int i) { return arg(i).checkfunction(); }
+
+ /** Return argument i as a java int value, discarding any fractional part, or throw an error if not a number.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return int value with fraction discarded and truncated if necessary if argument i is number
+ * @exception LuaError if the argument is not a number
+ * */
+ public int checkint(int i) { return arg(i).checknumber().toint(); }
+
+ /** Return argument i as a java int value, or throw an error if not a number or is not representable by a java int.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaInteger value that fits in a java int without rounding
+ * @exception LuaError if the argument cannot be represented by a java int value
+ * */
+ public LuaInteger checkinteger(int i) { return arg(i).checkinteger(); }
+
+ /** Return argument i as a java long value, discarding any fractional part, or throw an error if not a number.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return long value with fraction discarded and truncated if necessary if argument i is number
+ * @exception LuaError if the argument is not a number
+ * */
+ public long checklong(int i) { return arg(i).checknumber().tolong(); }
+
+ /** Return argument i as a LuaNumber, or throw an error if not a number or string that can be converted to a number.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaNumber if argument i is number or can be converted to a number
+ * @exception LuaError if the argument is not a number
+ * */
+ public LuaNumber checknumber(int i) { return arg(i).checknumber(); }
+
+ /** Return argument i as a java String if a string or number, or throw an error if any other type
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return String value if argument i is a string or number
+ * @exception LuaError if the argument is not a string or number
+ * */
+ public String checkjstring(int i) { return arg(i).checkjstring(); }
+
+ /** Return argument i as a LuaString if a string or number, or throw an error if any other type
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaString value if argument i is a string or number
+ * @exception LuaError if the argument is not a string or number
+ * */
+ public LuaString checkstring(int i) { return arg(i).checkstring(); }
+
+ /** Return argument i as a LuaTable if a lua table, or throw an error if any other type.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaTable value if a table
+ * @exception LuaError if the argument is not a lua table
+ * */
+ public LuaTable checktable(int i) { return arg(i).checktable(); }
+
+ /** Return argument i as a LuaThread if a lua thread, or throw an error if any other type.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaThread value if a thread
+ * @exception LuaError if the argument is not a lua thread
+ * */
+ public LuaThread checkthread(int i) { return arg(i).checkthread(); }
+
+ /** Return argument i as a java Object if a userdata, or throw an error if any other type.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return java Object value if argument i is a userdata
+ * @exception LuaError if the argument is not a userdata
+ * */
+ public Object checkuserdata(int i) { return arg(i).checkuserdata(); }
+
+ /** Return argument i as a java Object if it is a userdata whose instance Class c or a subclass,
+ * or throw an error if any other type.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @param c the class to which the userdata instance must be assignable
+ * @return java Object value if argument i is a userdata whose instance Class c or a subclass
+ * @exception LuaError if the argument is not a userdata or from whose instance c is not assignable
+ * */
+ public Object checkuserdata(int i,Class c) { return arg(i).checkuserdata(c); }
+
+ /** Return argument i as a LuaValue if it exists, or throw an error.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaValue value if the argument exists
+ * @exception LuaError if the argument does not exist.
+ * */
+ public LuaValue checkvalue(int i) { return i<=narg()? arg(i): LuaValue.argerror(i,"value expected"); }
+
+ /** Return argument i as a LuaValue if it is not nil, or throw an error if it is nil.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return LuaValue value if the argument is not nil
+ * @exception LuaError if the argument doesn't exist or evaluates to nil.
+ * */
+ public LuaValue checknotnil(int i) { return arg(i).checknotnil(); }
+
+ /** Return argument i as a LuaValue when a user-supplied assertion passes, or throw an error.
+ * @param test user supplied assertion to test against
+ * @param i the index to report in any error message
+ * @param msg the error message to use when the test fails
+ * @return LuaValue value if the value of {@code test} is {@code true}
+ * @exception LuaError if the the value of {@code test} is {@code false}
+ * */
+ public void argcheck(boolean test, int i, String msg) { if (!test) LuaValue.argerror(i,msg); }
+
+ /** Return true if there is no argument or nil at argument i.
+ * @param i the index of the argument to test, 1 is the first argument
+ * @return true if argument i contains either no argument or nil
+ * */
+ public boolean isnoneornil(int i) {
+ return i>narg() || arg(i).isnil();
+ }
+
+ /** Convert argument {@code i} to java boolean based on lua rules for boolean evaluation.
+ * @param i the index of the argument to convert, 1 is the first argument
+ * @return {@code false} if argument i is nil or false, otherwise {@code true}
+ * */
+ public boolean toboolean(int i) { return arg(i).toboolean(); }
+
+ /** Return argument i as a java byte value, discarding any fractional part and truncating,
+ * or 0 if not a number.
+ * @param i the index of the argument to convert, 1 is the first argument
+ * @return byte value with fraction discarded and truncated if necessary if argument i is number, otherwise 0
+ * */
+ public byte tobyte(int i) { return arg(i).tobyte(); }
+
+ /** Return argument i as a java char value, discarding any fractional part and truncating,
+ * or 0 if not a number.
+ * @param i the index of the argument to convert, 1 is the first argument
+ * @return char value with fraction discarded and truncated if necessary if argument i is number, otherwise 0
+ * */
+ public char tochar(int i) { return arg(i).tochar(); }
+
+ /** Return argument i as a java double value or 0 if not a number.
+ * @param i the index of the argument to convert, 1 is the first argument
+ * @return double value if argument i is number, otherwise 0
+ * */
+ public double todouble(int i) { return arg(i).todouble(); }
+
+ /** Return argument i as a java float value, discarding excess fractional part and truncating,
+ * or 0 if not a number.
+ * @param i the index of the argument to convert, 1 is the first argument
+ * @return float value with excess fraction discarded and truncated if necessary if argument i is number, otherwise 0
+ * */
+ public float tofloat(int i) { return arg(i).tofloat(); }
+
+ /** Return argument i as a java int value, discarding any fractional part and truncating,
+ * or 0 if not a number.
+ * @param i the index of the argument to convert, 1 is the first argument
+ * @return int value with fraction discarded and truncated if necessary if argument i is number, otherwise 0
+ * */
+ public int toint(int i) { return arg(i).toint(); }
+
+ /** Return argument i as a java long value, discarding any fractional part and truncating,
+ * or 0 if not a number.
+ * @param i the index of the argument to convert, 1 is the first argument
+ * @return long value with fraction discarded and truncated if necessary if argument i is number, otherwise 0
+ * */
+ public long tolong(int i) { return arg(i).tolong(); }
+
+ /** Return argument i as a java String based on the type of the argument.
+ * @param i the index of the argument to convert, 1 is the first argument
+ * @return String value representing the type
+ * */
+ public String tojstring(int i) { return arg(i).tojstring(); }
+
+ /** Return argument i as a java short value, discarding any fractional part and truncating,
+ * or 0 if not a number.
+ * @param i the index of the argument to convert, 1 is the first argument
+ * @return short value with fraction discarded and truncated if necessary if argument i is number, otherwise 0
+ * */
+ public short toshort(int i) { return arg(i).toshort(); }
+
+ /** Return argument i as a java Object if a userdata, or null.
+ * @param i the index of the argument to convert, 1 is the first argument
+ * @return java Object value if argument i is a userdata, otherwise null
+ * */
+ public Object touserdata(int i) { return arg(i).touserdata(); }
+
+ /** Return argument i as a java Object if it is a userdata whose instance Class c or a subclass, or null.
+ * @param i the index of the argument to convert, 1 is the first argument
+ * @param c the class to which the userdata instance must be assignable
+ * @return java Object value if argument i is a userdata whose instance Class c or a subclass, otherwise null
+ * */
+ public Object touserdata(int i,Class c) { return arg(i).touserdata(c); }
+
+ /** Convert the list of varargs values to a human readable java String.
+ * @return String value in human readable form such as {1,2}.
+ */
+ public String tojstring() {
+ Buffer sb = new Buffer();
+ sb.append( "(" );
+ for ( int i=1,n=narg(); i<=n; i++ ) {
+ if (i>1) sb.append( "," );
+ sb.append( arg(i).tojstring() );
+ }
+ sb.append( ")" );
+ return sb.tojstring();
+ }
+
+ /** Convert the value or values to a java String using Varargs.tojstring()
+ * @return String value in human readable form.
+ * @see Varargs#tojstring()
+ */
+ public String toString() { return tojstring(); }
+
+ /**
+ * Create a {@code Varargs} instance containing arguments starting at index {@code start}
+ * @param start the index from which to include arguments, where 1 is the first argument.
+ * @return Varargs containing argument { start, start+1, ... , narg-start-1 }
+ */
+ public Varargs subargs(final int start) {
+ int end = narg();
+ switch ( end-start ) {
+ case 0: return arg(start);
+ case 1: return new LuaValue.PairVarargs(arg(start),arg(end));
+ }
+ return end
+ * Normally these are not created directly, but indirectly when changing the mode
+ * of a {@link LuaTable} as lua script executes.
+ *
+ * However, calling the constructors directly when weak tables are required from
+ * Java will reduce overhead.
+ */
+public class WeakTable extends LuaTable {
+ private boolean weakkeys,weakvalues;
+
+ /**
+ * Construct a table with weak keys, weak values, or both
+ * @param weakkeys true to let the table have weak keys
+ * @param weakvalues true to let the table have weak values
+ */
+ public WeakTable(boolean weakkeys, boolean weakvalues) {
+ this(weakkeys, weakvalues, 0, 0);
+ }
+
+ /**
+ * Construct a table with weak keys, weak values, or both, and an initial capacity
+ * @param weakkeys true to let the table have weak keys
+ * @param weakvalues true to let the table have weak values
+ * @param narray capacity of array part
+ * @param nhash capacity of hash part
+ */
+ protected WeakTable(boolean weakkeys, boolean weakvalues, int narray, int nhash) {
+ super(narray, nhash);
+ this.weakkeys = weakkeys;
+ this.weakvalues = weakvalues;
+ }
+
+ /**
+ * Construct a table with weak keys, weak values, or both, and a source of initial data
+ * @param weakkeys true to let the table have weak keys
+ * @param weakvalues true to let the table have weak values
+ * @param source {@link LuaTable} containing the initial elements
+ */
+ protected WeakTable(boolean weakkeys, boolean weakvalues, LuaTable source) {
+ this(weakkeys, weakvalues, source.getArrayLength(), source.getHashLength());
+ Varargs n;
+ LuaValue k = NIL;
+ while ( !(k = ((n = source.next(k)).arg1())).isnil() )
+ rawset(k, n.arg(2));
+ m_metatable = source.m_metatable;
+ }
+
+ public void presize( int narray ) {
+ super.presize(narray);
+ }
+
+ /**
+ * Presize capacity of both array and hash parts.
+ * @param narray capacity of array part
+ * @param nhash capacity of hash part
+ */
+ public void presize(int narray, int nhash) {
+ super.presize(narray, nhash);
+ }
+
+ protected int getArrayLength() {
+ return super.getArrayLength();
+ }
+
+ protected int getHashLength() {
+ return super.getHashLength();
+ }
+
+ protected LuaTable changemode(boolean weakkeys, boolean weakvalues) {
+ this.weakkeys = weakkeys;
+ this.weakvalues = weakvalues;
+ return this;
+ }
+
+ /**
+ * Self-sent message to convert a value to its weak counterpart
+ * @param value value to convert
+ * @return {@link LuaValue} that is a strong or weak reference, depending on type of {@code value}
+ */
+ LuaValue weaken( LuaValue value ) {
+ switch ( value.type() ) {
+ case LuaValue.TFUNCTION:
+ case LuaValue.TTHREAD:
+ case LuaValue.TTABLE:
+ return new WeakValue(value);
+ case LuaValue.TUSERDATA:
+ return new WeakUserdata(value);
+ default:
+ return value;
+ }
+ }
+
+ public void rawset( int key, LuaValue value ) {
+ if ( weakvalues )
+ value = weaken( value );
+ super.rawset(key, value);
+ }
+
+ public void rawset( LuaValue key, LuaValue value ) {
+ if ( weakvalues )
+ value = weaken( value );
+ if ( weakkeys ) {
+ switch ( key.type() ) {
+ case LuaValue.TFUNCTION:
+ case LuaValue.TTHREAD:
+ case LuaValue.TTABLE:
+ case LuaValue.TUSERDATA:
+ key = value = new WeakEntry(this, key, value);
+ break;
+ default:
+ break;
+ }
+ }
+ super.rawset(key, value);
+ }
+
+
+ public LuaValue rawget( int key ) {
+ return super.rawget(key).strongvalue();
+ }
+
+ public LuaValue rawget( LuaValue key ) {
+ return super.rawget(key).strongvalue();
+ }
+
+ /** Get the hash value for a key
+ * key the key to look up
+ * */
+ protected LuaValue hashget(LuaValue key) {
+ if ( hashEntries > 0 ) {
+ int i = hashFindSlot(key);
+ if ( hashEntries == 0 )
+ return NIL;
+ LuaValue v = hashValues[i];
+ return v!=null? v: NIL;
+ }
+ return NIL;
+ }
+
+
+ // override to remove values for weak keys as we search
+ public int hashFindSlot(LuaValue key) {
+ int i = ( key.hashCode() & 0x7FFFFFFF ) % hashKeys.length;
+ LuaValue k;
+ while ( ( k = hashKeys[i] ) != null ) {
+ if ( k.isweaknil() ) {
+ hashClearSlot(i);
+ if ( hashEntries == 0 )
+ return 0;
+ }
+ else {
+ if ( k.raweq(key.strongkey()) )
+ return i;
+ i = ( i + 1 ) % hashKeys.length;
+ }
+ }
+ return i;
+ }
+
+ public int maxn() {
+ return super.maxn();
+ }
+
+
+ /**
+ * Get the next element after a particular key in the table
+ * @return key,value or nil
+ */
+ public Varargs next( LuaValue key ) {
+ while ( true ) {
+ Varargs n = super.next(key);
+ LuaValue k = n.arg1();
+ if ( k.isnil() )
+ return NIL;
+ LuaValue ks = k.strongkey();
+ LuaValue vs = n.arg(2).strongvalue();
+ if ( ks.isnil() || vs.isnil() ) {
+ super.rawset(k, NIL);
+ } else {
+ return varargsOf(ks,vs);
+ }
+ }
+ }
+
+ // ----------------- sort support -----------------------------
+ public void sort(final LuaValue comparator) {
+ super.sort( new TwoArgFunction() {
+ public LuaValue call(LuaValue arg1, LuaValue arg2) {
+ return comparator.call( arg1.strongvalue(), arg2.strongvalue() );
+ }
+ } );
+ }
+
+ /** Internal class to implement weak values.
+ * @see WeakTable
+ */
+ static class WeakValue extends LuaValue {
+ final WeakReference ref;
+
+ protected WeakValue(LuaValue value) {
+ ref = new WeakReference(value);
+ }
+
+ public int type() {
+ illegal("type","weak value");
+ return 0;
+ }
+
+ public String typename() {
+ illegal("typename","weak value");
+ return null;
+ }
+
+ public String toString() {
+ return "weak<"+ref.get()+">";
+ }
+
+ public LuaValue strongvalue() {
+ Object o = ref.get();
+ return o!=null? (LuaValue)o: NIL;
+ }
+
+ public boolean raweq(LuaValue rhs) {
+ Object o = ref.get();
+ return o!=null && rhs.raweq((LuaValue)o);
+ }
+
+ public boolean isweaknil() {
+ return ref.get() == null;
+ }
+ }
+
+ /** Internal class to implement weak userdata values.
+ * @see WeakTable
+ */
+ static final class WeakUserdata extends WeakValue {
+ private final WeakReference ob;
+ private final LuaValue mt;
+
+ private WeakUserdata(LuaValue value) {
+ super(value);
+ ob = new WeakReference(value.touserdata());
+ mt = value.getmetatable();
+ }
+
+ public LuaValue strongvalue() {
+ Object u = ref.get();
+ if ( u != null )
+ return (LuaValue) u;
+ Object o = ob.get();
+ return o!=null? userdataOf(o,mt): NIL;
+ }
+
+ public boolean raweq(LuaValue rhs) {
+ if ( ! rhs.isuserdata() )
+ return false;
+ LuaValue v = (LuaValue) ref.get();
+ if ( v != null && v.raweq(rhs) )
+ return true;
+ return rhs.touserdata() == ob.get();
+ }
+
+ public boolean isweaknil() {
+ return ob.get() == null || ref.get() == null;
+ }
+ }
+
+ /** Internal class to implement weak table entries.
+ * @see WeakTable
+ */
+ static final class WeakEntry extends LuaValue {
+ final LuaValue weakkey;
+ LuaValue weakvalue;
+ final int keyhash;
+
+ private WeakEntry(WeakTable table, LuaValue key, LuaValue weakvalue) {
+ this.weakkey = table.weaken(key);
+ this.keyhash = key.hashCode();
+ this.weakvalue = weakvalue;
+ }
+
+ public LuaValue strongkey() {
+ return weakkey.strongvalue();
+ }
+
+ // when looking up the value, look in the keys metatable
+ public LuaValue strongvalue() {
+ LuaValue key = weakkey.strongvalue();
+ if ( key.isnil() )
+ return weakvalue = NIL;
+ return weakvalue.strongvalue();
+ }
+
+ public int type() {
+ return TNONE;
+ }
+
+ public String typename() {
+ illegal("typename","weak entry");
+ return null;
+ }
+
+ public String toString() {
+ return "weak<"+weakkey.strongvalue()+","+strongvalue()+">";
+ }
+
+ public int hashCode() {
+ return keyhash;
+ }
+
+ public boolean raweq(LuaValue rhs) {
+ //return rhs.raweq(weakkey.strongvalue());
+ return weakkey.raweq(rhs);
+ }
+
+ public boolean isweaknil() {
+ return weakkey.isweaknil() || weakvalue.isweaknil();
+ }
+ }
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/compiler/DumpState.java b/luaj-2.0.3/src/core/org/luaj/vm2/compiler/DumpState.java
new file mode 100644
index 0000000000..f02a944c38
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/compiler/DumpState.java
@@ -0,0 +1,267 @@
+/*******************************************************************************
+* 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.compiler;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.luaj.vm2.LocVars;
+import org.luaj.vm2.Prototype;
+import org.luaj.vm2.LuaString;
+import org.luaj.vm2.LuaValue;
+
+
+public class DumpState {
+
+ /** mark for precompiled code (`
+ * Compiles lua source files into lua bytecode within a {@link Prototype},
+ * loads lua binary files directly into a{@link Prototype},
+ * and optionaly instantiates a {@link LuaClosure} around the result
+ * using a user-supplied environment.
+ *
+ * Implements the {@link LuaCompiler} interface for loading
+ * initialized chunks, which is an interface common to
+ * lua bytecode compiling and java bytecode compiling.
+ *
+ * Teh {@link LuaC} compiler is installed by default by both the
+ * {@link JsePlatform} and {@link JmePlatform} classes,
+ * so in the following example, the default {@link LuaC} compiler
+ * will be used:
+ *
+ * This contains all library functions listed as "basic functions" in the lua documentation for JME.
+ * The functions dofile and loadfile use the
+ * {@link #FINDER} instance to find resource files.
+ * Since JME has no file system by default, {@link BaseLib} implements
+ * {@link ResourceFinder} using {@link Class#getResource(String)},
+ * which is the closest equivalent on JME.
+ * The default loader chain in {@link PackageLib} will use these as well.
+ *
+ * To use basic library functions that include a {@link ResourceFinder} based on
+ * directory lookup, use {@link JseBaseLib} instead.
+ *
+ * Typically, this library is included as part of a call to either
+ * {@link JmePlatform#standardGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * This is a direct port of the corresponding library in C.
+ * @see JseBaseLib
+ * @see ResourceFinder
+ * @see #FINDER
+ * @see LibFunction
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see http://www.lua.org/manual/5.1/manual.html#5.1
+ */
+public class BaseLib extends OneArgFunction implements ResourceFinder {
+
+ public static BaseLib instance;
+
+ public InputStream STDIN = null;
+ public PrintStream STDOUT = System.out;
+ public PrintStream STDERR = System.err;
+
+ /**
+ * Singleton file opener for this Java ClassLoader realm.
+ *
+ * Unless set or changed elsewhere, will be set by the BaseLib that is created.
+ */
+ public static ResourceFinder FINDER;
+
+ private LuaValue next;
+ private LuaValue inext;
+
+ private static final String[] LIB2_KEYS = {
+ "collectgarbage", // ( opt [,arg] ) -> value
+ "error", // ( message [,level] ) -> ERR
+ "setfenv", // (f, table) -> void
+ };
+ private static final String[] LIBV_KEYS = {
+ "assert", // ( v [,message] ) -> v, message | ERR
+ "dofile", // ( filename ) -> result1, ...
+ "getfenv", // ( [f] ) -> env
+ "getmetatable", // ( object ) -> table
+ "load", // ( func [,chunkname] ) -> chunk | nil, msg
+ "loadfile", // ( [filename] ) -> chunk | nil, msg
+ "loadstring", // ( string [,chunkname] ) -> chunk | nil, msg
+ "pcall", // (f, arg1, ...) -> status, result1, ...
+ "xpcall", // (f, err) -> result1, ...
+ "print", // (...) -> void
+ "select", // (f, ...) -> value1, ...
+ "unpack", // (list [,i [,j]]) -> result1, ...
+ "type", // (v) -> value
+ "rawequal", // (v1, v2) -> boolean
+ "rawget", // (table, index) -> value
+ "rawset", // (table, index, value) -> table
+ "setmetatable", // (table, metatable) -> table
+ "tostring", // (e) -> value
+ "tonumber", // (e [,base]) -> value
+ "pairs", // "pairs" (t) -> iter-func, t, nil
+ "ipairs", // "ipairs", // (t) -> iter-func, t, 0
+ "next", // "next" ( table, [index] ) -> next-index, next-value
+ "__inext", // "inext" ( table, [int-index] ) -> next-index, next-value
+ };
+
+ /**
+ * Construct a base libarary instance.
+ */
+ public BaseLib() {
+ instance = this;
+ }
+
+ public LuaValue call(LuaValue arg) {
+ env.set( "_G", env );
+ env.set( "_VERSION", Lua._VERSION );
+ bind( env, BaseLib2.class, LIB2_KEYS );
+ bind( env, BaseLibV.class, LIBV_KEYS );
+
+ // remember next, and inext for use in pairs and ipairs
+ next = env.get("next");
+ inext = env.get("__inext");
+
+ // inject base lib int vararg instances
+ for ( int i=0; i
+ * The coroutine library in luaj has the same behavior as the
+ * coroutine library in C, but is implemented using Java Threads to maintain
+ * the call state between invocations. Therefore it can be yielded from anywhere,
+ * similar to the "Coco" yield-from-anywhere patch available for C-based lua.
+ * However, coroutines that are yielded but never resumed to complete their execution
+ * may not be collected by the garbage collector.
+ *
+ * Typically, this library is included as part of a call to either
+ * {@link JsePlatform#standardGlobals()} or {@link JmePlatform#standardGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * @see LibFunction
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see http://www.lua.org/manual/5.1/manual.html#5.2
+ */
+public class CoroutineLib extends VarArgFunction {
+
+ private static final int INIT = 0;
+ private static final int CREATE = 1;
+ private static final int RESUME = 2;
+ private static final int RUNNING = 3;
+ private static final int STATUS = 4;
+ private static final int YIELD = 5;
+ private static final int WRAP = 6;
+ private static final int WRAPPED = 7;
+
+ public CoroutineLib() {
+ }
+
+ private LuaTable init() {
+ LuaTable t = new LuaTable();
+ bind(t, CoroutineLib.class, new String[] {
+ "create", "resume", "running", "status", "yield", "wrap" },
+ CREATE);
+ env.set("coroutine", t);
+ PackageLib.instance.LOADED.set("coroutine", t);
+ return t;
+ }
+
+ public Varargs invoke(Varargs args) {
+ switch ( opcode ) {
+ case INIT: {
+ return init();
+ }
+ case CREATE: {
+ final LuaValue func = args.checkfunction(1);
+ /* DAN200 START */
+ //return new LuaThread(func, LuaThread.getGlobals() );
+ final LuaThread thread = new LuaThread( func, LuaThread.getGlobals() );
+ LuaThread.getRunning().addChild( thread );
+ return thread;
+ /* DAN200 END */
+ }
+ case RESUME: {
+ final LuaThread t = args.checkthread(1);
+ return t.resume( args.subargs(2) );
+ }
+ case RUNNING: {
+ final LuaThread r = LuaThread.getRunning();
+ return LuaThread.isMainThread(r)? NIL: r;
+ }
+ case STATUS: {
+ return valueOf( args.checkthread(1).getStatus() );
+ }
+ case YIELD: {
+ return LuaThread.yield( args );
+ }
+ case WRAP: {
+ final LuaValue func = args.checkfunction(1);
+ final LuaThread thread = new LuaThread(func, func.getfenv());
+ /* DAN200 START */
+ LuaThread.getRunning().addChild( thread );
+ /* DAN200 END */
+ CoroutineLib cl = new CoroutineLib();
+ cl.setfenv(thread);
+ cl.name = "wrapped";
+ cl.opcode = WRAPPED;
+ return cl;
+ }
+ case WRAPPED: {
+ final LuaThread t = (LuaThread) env;
+ final Varargs result = t.resume( args );
+ if ( result.arg1().toboolean() ) {
+ return result.subargs(2);
+ } else {
+ error( result.arg(2).tojstring() );
+ }
+ }
+ default:
+ return NONE;
+ }
+ }
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/lib/DebugLib.java b/luaj-2.0.3/src/core/org/luaj/vm2/lib/DebugLib.java
new file mode 100644
index 0000000000..da3e103a62
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/lib/DebugLib.java
@@ -0,0 +1,977 @@
+/*******************************************************************************
+* Copyright (c) 2009-2011 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.lib;
+
+import java.lang.ref.WeakReference;
+
+import org.luaj.vm2.Lua;
+import org.luaj.vm2.LuaBoolean;
+import org.luaj.vm2.LuaClosure;
+import org.luaj.vm2.LuaError;
+import org.luaj.vm2.LuaFunction;
+import org.luaj.vm2.LuaNil;
+import org.luaj.vm2.LuaNumber;
+import org.luaj.vm2.LuaString;
+import org.luaj.vm2.LuaTable;
+import org.luaj.vm2.LuaThread;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.Print;
+import org.luaj.vm2.Prototype;
+import org.luaj.vm2.Varargs;
+
+/**
+ * Subclass of {@link LibFunction} which implements the lua standard {@code debug}
+ * library.
+ *
+ * The debug library in luaj tries to emulate the behavior of the corresponding C-based lua library.
+ * To do this, it must maintain a separate stack of calls to {@link LuaClosure} and {@link LibFunction}
+ * instances.
+ * Especially when lua-to-java bytecode compiling is being used
+ * via a {@link LuaCompiler} such as {@link LuaJC},
+ * this cannot be done in all cases.
+ *
+ * Typically, this library is included as part of a call to either
+ * {@link JsePlatform#debugGlobals()} or {@link JmePlatform#debugGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * @see LibFunction
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see http://www.lua.org/manual/5.1/manual.html#5.9
+ */
+public class DebugLib extends VarArgFunction {
+ public static final boolean CALLS = (null != System.getProperty("CALLS"));
+ public static final boolean TRACE = (null != System.getProperty("TRACE"));
+
+ // leave this unset to allow obfuscators to
+ // remove it in production builds
+ public static boolean DEBUG_ENABLED;
+
+ static final String[] NAMES = {
+ "debug",
+ "getfenv",
+ "gethook",
+ "getinfo",
+ "getlocal",
+ "getmetatable",
+ "getregistry",
+ "getupvalue",
+ "setfenv",
+ "sethook",
+ "setlocal",
+ "setmetatable",
+ "setupvalue",
+ "traceback",
+ };
+
+ private static final int INIT = 0;
+ private static final int DEBUG = 1;
+ private static final int GETFENV = 2;
+ private static final int GETHOOK = 3;
+ private static final int GETINFO = 4;
+ private static final int GETLOCAL = 5;
+ private static final int GETMETATABLE = 6;
+ private static final int GETREGISTRY = 7;
+ private static final int GETUPVALUE = 8;
+ private static final int SETFENV = 9;
+ private static final int SETHOOK = 10;
+ private static final int SETLOCAL = 11;
+ private static final int SETMETATABLE = 12;
+ private static final int SETUPVALUE = 13;
+ private static final int TRACEBACK = 14;
+
+ /* maximum stack for a Lua function */
+ private static final int MAXSTACK = 250;
+
+ private static final LuaString LUA = valueOf("Lua");
+ private static final LuaString JAVA = valueOf("Java");
+ private static final LuaString QMARK = valueOf("?");
+ private static final LuaString GLOBAL = valueOf("global");
+ private static final LuaString LOCAL = valueOf("local");
+ private static final LuaString METHOD = valueOf("method");
+ private static final LuaString UPVALUE = valueOf("upvalue");
+ private static final LuaString FIELD = valueOf("field");
+ private static final LuaString CALL = valueOf("call");
+ private static final LuaString LINE = valueOf("line");
+ private static final LuaString COUNT = valueOf("count");
+ private static final LuaString RETURN = valueOf("return");
+ private static final LuaString TAILRETURN = valueOf("tail return");
+
+ private static final LuaString FUNC = valueOf("func");
+ private static final LuaString NUPS = valueOf("nups");
+ private static final LuaString NAME = valueOf("name");
+ private static final LuaString NAMEWHAT = valueOf("namewhat");
+ private static final LuaString WHAT = valueOf("what");
+ private static final LuaString SOURCE = valueOf("source");
+ private static final LuaString SHORT_SRC = valueOf("short_src");
+ private static final LuaString LINEDEFINED = valueOf("linedefined");
+ private static final LuaString LASTLINEDEFINED = valueOf("lastlinedefined");
+ private static final LuaString CURRENTLINE = valueOf("currentline");
+ private static final LuaString ACTIVELINES = valueOf("activelines");
+
+ public DebugLib() {
+ }
+
+ private LuaTable init() {
+ DEBUG_ENABLED = true;
+ LuaTable t = new LuaTable();
+ bind(t, DebugLib.class, NAMES, DEBUG);
+ env.set("debug", t);
+ PackageLib.instance.LOADED.set("debug", t);
+ return t;
+ }
+
+ public Varargs invoke(Varargs args) {
+ switch ( opcode ) {
+ case INIT: return init();
+ case DEBUG: return _debug(args);
+ case GETFENV: return _getfenv(args);
+ case GETHOOK: return _gethook(args);
+ case GETINFO: return _getinfo(args,this);
+ case GETLOCAL: return _getlocal(args);
+ case GETMETATABLE: return _getmetatable(args);
+ case GETREGISTRY: return _getregistry(args);
+ case GETUPVALUE: return _getupvalue(args);
+ case SETFENV: return _setfenv(args);
+ case SETHOOK: return _sethook(args);
+ case SETLOCAL: return _setlocal(args);
+ case SETMETATABLE: return _setmetatable(args);
+ case SETUPVALUE: return _setupvalue(args);
+ case TRACEBACK: return _traceback(args);
+ default: return NONE;
+ }
+ }
+
+ // ------------------------ Debug Info management --------------------------
+ //
+ // when DEBUG_ENABLED is set to true, these functions will be called
+ // by Closure instances as they process bytecodes.
+ //
+ // Each thread will get a DebugState attached to it by the debug library
+ // which will track function calls, hook functions, etc.
+ //
+ static class DebugInfo {
+ LuaValue func;
+ LuaClosure closure;
+ LuaValue[] stack;
+ Varargs varargs, extras;
+ int pc, top;
+
+ private DebugInfo() {
+ func = NIL;
+ }
+ private DebugInfo(LuaValue func) {
+ pc = -1;
+ setfunction( func );
+ }
+ void setargs(Varargs varargs, LuaValue[] stack) {
+ this.varargs = varargs;
+ this.stack = stack;
+ }
+ void setfunction( LuaValue func ) {
+ this.func = func;
+ this.closure = (func instanceof LuaClosure? (LuaClosure) func: null);
+ }
+ void clear() {
+ func = NIL;
+ closure = null;
+ stack = null;
+ varargs = extras = null;
+ pc = top = 0;
+ }
+ public void bytecode(int pc, Varargs extras, int top) {
+ this.pc = pc;
+ this.top = top;
+ this.extras = extras;
+ }
+ public int currentline() {
+ if ( closure == null ) return -1;
+ int[] li = closure.p.lineinfo;
+ return li==null || pc<0 || pc>=li.length? -1: li[pc];
+ }
+ public LuaString[] getfunckind() {
+ if ( closure == null || pc<0 ) return null;
+ int stackpos = (closure.p.code[pc] >> 6) & 0xff;
+ return getobjname(this, stackpos);
+ }
+ public String sourceline() {
+ if ( closure == null ) return func.tojstring();
+ String s = closure.p.source.tojstring();
+ int line = currentline();
+ return (s.startsWith("@")||s.startsWith("=")? s.substring(1): s) + ":" + line;
+ }
+ public String tracename() {
+ // if ( func != null )
+ // return func.tojstring();
+ LuaString[] kind = getfunckind();
+ if ( kind == null )
+ return "function ?";
+ return "function "+kind[0].tojstring();
+ }
+ public LuaString getlocalname(int index) {
+ if ( closure == null ) return null;
+ return closure.p.getlocalname(index, pc);
+ }
+ public String tojstring() {
+ return tracename()+" "+sourceline();
+ }
+ }
+
+ /** DebugState is associated with a Thread */
+ static class DebugState {
+ private final WeakReference thread_ref;
+ private int debugCalls = 0;
+ private DebugInfo[] debugInfo = new DebugInfo[LuaThread.MAX_CALLSTACK+1];
+ private LuaValue hookfunc;
+ private boolean hookcall,hookline,hookrtrn,inhook;
+ private int hookcount,hookcodes;
+ private int line;
+ DebugState(LuaThread thread) {
+ this.thread_ref = new WeakReference(thread);
+ }
+ public DebugInfo nextInfo() {
+ DebugInfo di = debugInfo[debugCalls];
+ if ( di == null )
+ debugInfo[debugCalls] = di = new DebugInfo();
+ return di;
+ }
+ public DebugInfo pushInfo( int calls ) {
+ while ( debugCalls < calls ) {
+ nextInfo();
+ ++debugCalls;
+ }
+ return debugInfo[debugCalls-1];
+ }
+ public void popInfo(int calls) {
+ while ( debugCalls > calls )
+ debugInfo[--debugCalls].clear();
+ }
+ void callHookFunc(DebugState ds, LuaString type, LuaValue arg) {
+ if ( inhook || hookfunc == null )
+ return;
+ inhook = true;
+ try {
+ int n = debugCalls;
+ ds.nextInfo().setargs( arg, null );
+ ds.pushInfo(n+1).setfunction(hookfunc);
+ try {
+ hookfunc.call(type,arg);
+ } finally {
+ ds.popInfo(n);
+ }
+ } catch ( Exception e ) {
+ e.printStackTrace();
+ } finally {
+ inhook = false;
+ }
+ }
+ public void sethook(LuaValue func, boolean call, boolean line, boolean rtrn, int count) {
+ this.hookcount = count;
+ this.hookcall = call;
+ this.hookline = line;
+ this.hookrtrn = rtrn;
+ this.hookfunc = func;
+ }
+ DebugInfo getDebugInfo() {
+ try {
+ return debugInfo[debugCalls-1];
+ } catch ( Exception e ) {
+ if ( debugCalls <= 0 )
+ return debugInfo[debugCalls++] = new DebugInfo();
+ return null;
+ }
+ }
+ DebugInfo getDebugInfo(int level) {
+ return level < 0 || level >= debugCalls? null: debugInfo[debugCalls-level-1];
+ }
+ public DebugInfo findDebugInfo(LuaValue func) {
+ for ( int i=debugCalls; --i>=0; ) {
+ if ( debugInfo[i].func == func ) {
+ return debugInfo[i];
+ }
+ }
+ return new DebugInfo(func);
+ }
+ public String tojstring() {
+ LuaThread thread = (LuaThread) thread_ref.get();
+ return thread != null? DebugLib.traceback(thread, 0): "orphaned thread";
+ }
+ }
+
+ static DebugState getDebugState( LuaThread thread ) {
+ if ( thread.debugState == null )
+ thread.debugState = new DebugState(thread);
+ return (DebugState) thread.debugState;
+ }
+
+ static DebugState getDebugState() {
+ return getDebugState( LuaThread.getRunning() );
+ }
+
+ /** Called by Closures to set up stack and arguments to next call */
+ public static void debugSetupCall(Varargs args, LuaValue[] stack) {
+ DebugState ds = getDebugState();
+ if ( ds.inhook )
+ return;
+ ds.nextInfo().setargs( args, stack );
+ }
+
+ /** Called by Closures and recursing java functions on entry
+ * @param thread the thread for the call
+ * @param calls the number of calls in the call stack
+ * @param func the function called
+ */
+ public static void debugOnCall(LuaThread thread, int calls, LuaFunction func) {
+ DebugState ds = getDebugState();
+ if ( ds.inhook )
+ return;
+ DebugInfo di = ds.pushInfo(calls);
+ di.setfunction( func );
+ if(CALLS)System.out.println("calling "+func);
+ if ( ds.hookcall )
+ ds.callHookFunc( ds, CALL, LuaValue.NIL );
+ }
+
+ /** Called by Closures and recursing java functions on return
+ * @param thread the thread for the call
+ * @param calls the number of calls in the call stack
+ */
+ public static void debugOnReturn(LuaThread thread, int calls) {
+ DebugState ds = getDebugState(thread);
+ if ( ds.inhook )
+ return;
+ if(CALLS)System.out.println("returning");
+ try {
+ if ( ds.hookrtrn )
+ ds.callHookFunc( ds, RETURN, LuaValue.NIL );
+ } finally {
+ getDebugState().popInfo(calls);
+ }
+ }
+
+ /** Called by Closures on bytecode execution */
+ public static void debugBytecode( int pc, Varargs extras, int top ) {
+ DebugState ds = getDebugState();
+ if ( ds.inhook )
+ return;
+ DebugInfo di = ds.getDebugInfo();
+ if(TRACE)Print.printState(di.closure, pc, di.stack, top, di.varargs);
+ di.bytecode( pc, extras, top );
+ if ( ds.hookcount > 0 ) {
+ if ( ++ds.hookcodes >= ds.hookcount ) {
+ ds.hookcodes = 0;
+ ds.callHookFunc( ds, COUNT, LuaValue.NIL );
+ }
+ }
+ if ( ds.hookline ) {
+ int newline = di.currentline();
+ if ( newline != ds.line ) {
+ int c = di.closure.p.code[pc];
+ if ( (c&0x3f) != Lua.OP_JMP || ((c>>>14)-0x1ffff) >= 0 ) {
+ ds.line = newline;
+ ds.callHookFunc( ds, LINE, LuaValue.valueOf(newline) );
+ }
+ }
+ }
+ }
+
+ // ------------------- library function implementations -----------------
+
+ // j2se subclass may wish to override and provide actual console here.
+ // j2me platform has not System.in to provide console.
+ static Varargs _debug(Varargs args) {
+ return NONE;
+ }
+
+ static Varargs _gethook(Varargs args) {
+ int a=1;
+ LuaThread thread = args.isthread(a)? args.checkthread(a++): LuaThread.getRunning();
+ DebugState ds = getDebugState(thread);
+ return varargsOf(
+ ds.hookfunc,
+ valueOf((ds.hookcall?"c":"")+(ds.hookline?"l":"")+(ds.hookrtrn?"r":"")),
+ valueOf(ds.hookcount));
+ }
+
+ static Varargs _sethook(Varargs args) {
+ int a=1;
+ LuaThread thread = args.isthread(a)? args.checkthread(a++): LuaThread.getRunning();
+ LuaValue func = args.optfunction(a++, null);
+ String str = args.optjstring(a++,"");
+ int count = args.optint(a++,0);
+ boolean call=false,line=false,rtrn=false;
+ for ( int i=0; i
+ * It contains the implementation of the io library support that is common to
+ * the JSE and JME platforms.
+ * In practice on of the concrete IOLib subclasses is chosen:
+ * {@link org.luaj.vm2.lib.jse.JseIoLib} for the JSE platform, and
+ * {@link org.luaj.vm2.lib.jme.JmeIoLib} for the JME platform.
+ *
+ * The JSE implementation conforms almost completely to the C-based lua library,
+ * while the JME implementation follows closely except in the area of random-access files,
+ * which are difficult to support properly on JME.
+ *
+ * Typically, this library is included as part of a call to either
+ * {@link JsePlatform#standardGlobals()} or {@link JmePlatform#standardGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * This has been implemented to match as closely as possible the behavior in the corresponding library in C.
+ * @see LibFunction
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see JseIoLib
+ * @see JmeIoLib
+ * @see http://www.lua.org/manual/5.1/manual.html#5.7
+ */
+abstract
+public class IoLib extends OneArgFunction {
+
+ abstract
+ protected class File extends LuaValue{
+ abstract public void write( LuaString string ) throws IOException;
+ abstract public void flush() throws IOException;
+ abstract public boolean isstdfile();
+ abstract public void close() throws IOException;
+ abstract public boolean isclosed();
+ // returns new position
+ abstract public int seek(String option, int bytecount) throws IOException;
+ abstract public void setvbuf(String mode, int size);
+ // get length remaining to read
+ abstract public int remaining() throws IOException;
+ // peek ahead one character
+ abstract public int peek() throws IOException, EOFException;
+ // return char if read, -1 if eof, throw IOException on other exception
+ abstract public int read() throws IOException, EOFException;
+ // return number of bytes read if positive, false if eof, throw IOException on other exception
+ abstract public int read(byte[] bytes, int offset, int length) throws IOException;
+
+ // delegate method access to file methods table
+ public LuaValue get( LuaValue key ) {
+ return filemethods.get(key);
+ }
+
+ // essentially a userdata instance
+ public int type() {
+ return LuaValue.TUSERDATA;
+ }
+ public String typename() {
+ return "userdata";
+ }
+
+ // displays as "file" type
+ public String tojstring() {
+ return "file: " + Integer.toHexString(hashCode());
+ }
+ }
+
+
+ /**
+ * Wrap the standard input.
+ * @return File
+ * @throws IOException
+ */
+ abstract protected File wrapStdin() throws IOException;
+
+ /**
+ * Wrap the standard output.
+ * @return File
+ * @throws IOException
+ */
+ abstract protected File wrapStdout() throws IOException;
+
+ /**
+ * Open a file in a particular mode.
+ * @param filename
+ * @param readMode true if opening in read mode
+ * @param appendMode true if opening in append mode
+ * @param updateMode true if opening in update mode
+ * @param binaryMode true if opening in binary mode
+ * @return File object if successful
+ * @throws IOException if could not be opened
+ */
+ abstract protected File openFile( String filename, boolean readMode, boolean appendMode, boolean updateMode, boolean binaryMode ) throws IOException;
+
+ /**
+ * Open a temporary file.
+ * @return File object if successful
+ * @throws IOException if could not be opened
+ */
+ abstract protected File tmpFile() throws IOException;
+
+ /**
+ * Start a new process and return a file for input or output
+ * @param prog the program to execute
+ * @param mode "r" to read, "w" to write
+ * @return File to read to or write from
+ * @throws IOException if an i/o exception occurs
+ */
+ abstract protected File openProgram(String prog, String mode) throws IOException;
+
+ private File infile = null;
+ private File outfile = null;
+ private File errfile = null;
+
+ private static final LuaValue STDIN = valueOf("stdin");
+ private static final LuaValue STDOUT = valueOf("stdout");
+ private static final LuaValue STDERR = valueOf("stderr");
+ private static final LuaValue FILE = valueOf("file");
+ private static final LuaValue CLOSED_FILE = valueOf("closed file");
+
+ private static final int IO_CLOSE = 0;
+ private static final int IO_FLUSH = 1;
+ private static final int IO_INPUT = 2;
+ private static final int IO_LINES = 3;
+ private static final int IO_OPEN = 4;
+ private static final int IO_OUTPUT = 5;
+ private static final int IO_POPEN = 6;
+ private static final int IO_READ = 7;
+ private static final int IO_TMPFILE = 8;
+ private static final int IO_TYPE = 9;
+ private static final int IO_WRITE = 10;
+
+ private static final int FILE_CLOSE = 11;
+ private static final int FILE_FLUSH = 12;
+ private static final int FILE_LINES = 13;
+ private static final int FILE_READ = 14;
+ private static final int FILE_SEEK = 15;
+ private static final int FILE_SETVBUF = 16;
+ private static final int FILE_WRITE = 17;
+
+ private static final int IO_INDEX = 18;
+ private static final int LINES_ITER = 19;
+
+ public static final String[] IO_NAMES = {
+ "close",
+ "flush",
+ "input",
+ "lines",
+ "open",
+ "output",
+ "popen",
+ "read",
+ "tmpfile",
+ "type",
+ "write",
+ };
+
+ public static final String[] FILE_NAMES = {
+ "close",
+ "flush",
+ "lines",
+ "read",
+ "seek",
+ "setvbuf",
+ "write",
+ };
+
+ LuaTable filemethods;
+
+ public IoLib() {
+ }
+
+ public LuaValue call(LuaValue arg) {
+
+ // io lib functions
+ LuaTable t = new LuaTable();
+ bind(t, IoLibV.class, IO_NAMES );
+
+ // create file methods table
+ filemethods = new LuaTable();
+ bind(filemethods, IoLibV.class, FILE_NAMES, FILE_CLOSE );
+
+ // set up file metatable
+ LuaTable mt = new LuaTable();
+ bind(mt, IoLibV.class, new String[] { "__index" }, IO_INDEX );
+ t.setmetatable( mt );
+
+ // all functions link to library instance
+ setLibInstance( t );
+ setLibInstance( filemethods );
+ setLibInstance( mt );
+
+ // return the table
+ env.set("io", t);
+ PackageLib.instance.LOADED.set("io", t);
+ return t;
+ }
+
+ private void setLibInstance(LuaTable t) {
+ LuaValue[] k = t.keys();
+ for ( int i=0, n=k.length; i
+ * To provide for common implementations in JME and JSE,
+ * library functions are typically grouped on one or more library classes
+ * and an opcode per library function is defined and used to key the switch
+ * to the correct function within the library.
+ *
+ * Since lua functions can be called with too few or too many arguments,
+ * and there are overloaded {@link LuaValue#call()} functions with varying
+ * number of arguments, a Java function exposed in lua needs to handle the
+ * argument fixup when a function is called with a number of arguments
+ * differs from that expected.
+ *
+ * To simplify the creation of library functions,
+ * there are 5 direct subclasses to handle common cases based on number of
+ * argument values and number of return return values.
+ *
+ * To be a Java library that can be loaded via {@code require}, it should have
+ * a public constructor that returns a {@link LuaValue} that, when executed,
+ * initializes the library.
+ *
+ * For example, the following code will implement a library called "hyperbolic"
+ * with two functions, "sinh", and "cosh":
+
+ * To test it, a script such as this can be used:
+ *
+ * It should produce something like:
+ *
+ * See the source code in any of the library functions
+ * such as {@link BaseLib} or {@link TableLib} for other examples.
+ */
+abstract public class LibFunction extends LuaFunction {
+
+ /** User-defined opcode to differentiate between instances of the library function class.
+ *
+ * Subclass will typicall switch on this value to provide the specific behavior for each function.
+ */
+ protected int opcode;
+
+ /** The common name for this function, useful for debugging.
+ *
+ * Binding functions initialize this to the name to which it is bound.
+ */
+ protected String name;
+
+ /** Default constructor for use by subclasses */
+ protected LibFunction() {
+ }
+
+ public String tojstring() {
+ return name != null? name: super.tojstring();
+ }
+
+ /**
+ * Bind a set of library functions.
+ *
+ * An array of names is provided, and the first name is bound
+ * with opcode = 0, second with 1, etc.
+ * @param env The environment to apply to each bound function
+ * @param factory the Class to instantiate for each bound function
+ * @param names array of String names, one for each function.
+ * @see #bind(LuaValue, Class, String[], int)
+ */
+ protected void bind(LuaValue env, Class factory, String[] names ) {
+ bind( env, factory, names, 0 );
+ }
+
+ /**
+ * Bind a set of library functions, with an offset
+ *
+ * An array of names is provided, and the first name is bound
+ * with opcode = {@code firstopcode}, second with {@code firstopcode+1}, etc.
+ * @param env The environment to apply to each bound function
+ * @param factory the Class to instantiate for each bound function
+ * @param names array of String names, one for each function.
+ * @param firstopcode the first opcode to use
+ * @see #bind(LuaValue, Class, String[])
+ */
+ protected void bind(LuaValue env, Class factory, String[] names, int firstopcode ) {
+ try {
+ for ( int i=0, n=names.length; i
+ * The implementations of {@code exp()} and {@code pow()} are constructed by
+ * hand for JME, so will be slower and less accurate than when executed on the JSE platform.
+ *
+ * Typically, this library is included as part of a call to either
+ * {@link JmePlatform#standardGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * This has been implemented to match as closely as possible the behavior in the corresponding library in C.
+ * @see LibFunction
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see JseMathLib
+ * @see http://www.lua.org/manual/5.1/manual.html#5.6
+ */
+public class MathLib extends OneArgFunction {
+
+ public static MathLib MATHLIB = null;
+
+ private Random random;
+
+ public MathLib() {
+ MATHLIB = this;
+ }
+
+ public LuaValue call(LuaValue arg) {
+ LuaTable t = new LuaTable(0,30);
+ t.set( "pi", Math.PI );
+ t.set( "huge", LuaDouble.POSINF );
+ bind( t, MathLib1.class, new String[] {
+ "abs", "ceil", "cos", "deg",
+ "exp", "floor", "rad", "sin",
+ "sqrt", "tan" } );
+ bind( t, MathLib2.class, new String[] {
+ "fmod", "ldexp", "pow", } );
+ bind( t, MathLibV.class, new String[] {
+ "frexp", "max", "min", "modf",
+ "randomseed", "random", } );
+ ((MathLibV) t.get("randomseed")).mathlib = this;
+ ((MathLibV) t.get("random" )).mathlib = this;
+ env.set("math", t);
+ PackageLib.instance.LOADED.set("math", t);
+ return t;
+ }
+
+ static final class MathLib1 extends OneArgFunction {
+ public LuaValue call(LuaValue arg) {
+ switch ( opcode ) {
+ case 0: return valueOf(Math.abs(arg.checkdouble()));
+ case 1: return valueOf(Math.ceil(arg.checkdouble()));
+ case 2: return valueOf(Math.cos(arg.checkdouble()));
+ case 3: return valueOf(Math.toDegrees(arg.checkdouble()));
+ case 4: return dpow(Math.E,arg.checkdouble());
+ case 5: return valueOf(Math.floor(arg.checkdouble()));
+ case 6: return valueOf(Math.toRadians(arg.checkdouble()));
+ case 7: return valueOf(Math.sin(arg.checkdouble()));
+ case 8: return valueOf(Math.sqrt(arg.checkdouble()));
+ case 9: return valueOf(Math.tan(arg.checkdouble()));
+ }
+ return NIL;
+ }
+ }
+
+ static final class MathLib2 extends TwoArgFunction {
+ protected MathLib mathlib;
+ public LuaValue call(LuaValue arg1, LuaValue arg2) {
+ switch ( opcode ) {
+ case 0: { // fmod
+ double x = arg1.checkdouble();
+ double y = arg2.checkdouble();
+ double q = x/y;
+ double f = x - y * (q>=0? Math.floor(q): Math.ceil(q));
+ return valueOf( f );
+ }
+ case 1: { // ldexp
+ double x = arg1.checkdouble();
+ double y = arg2.checkdouble()+1023.5;
+ long e = (long) ((0!=(1&((int)y)))? Math.floor(y): Math.ceil(y-1));
+ return valueOf(x * Double.longBitsToDouble(e << 52));
+ }
+ case 2: { // pow
+ return dpow(arg1.checkdouble(), arg2.checkdouble());
+ }
+ }
+ return NIL;
+ }
+ }
+
+ /** compute power using installed math library, or default if there is no math library installed */
+ public static LuaValue dpow(double a, double b) {
+ return LuaDouble.valueOf(
+ MATHLIB!=null?
+ MATHLIB.dpow_lib(a,b):
+ dpow_default(a,b) );
+ }
+ public static double dpow_d(double a, double b) {
+ return MATHLIB!=null?
+ MATHLIB.dpow_lib(a,b):
+ dpow_default(a,b);
+ }
+
+ /**
+ * Hook to override default dpow behavior with faster implementation.
+ */
+ public double dpow_lib(double a, double b) {
+ return dpow_default(a,b);
+ }
+
+ /**
+ * Default JME version computes using longhand heuristics.
+ */
+ protected static double dpow_default(double a, double b) {
+ if ( b < 0 )
+ return 1 / dpow_default( a, -b );
+ double p = 1;
+ int whole = (int) b;
+ for ( double v=a; whole > 0; whole>>=1, v*=v )
+ if ( (whole & 1) != 0 )
+ p *= v;
+ if ( (b -= whole) > 0 ) {
+ int frac = (int) (0x10000 * b);
+ for ( ; (frac&0xffff)!=0; frac<<=1 ) {
+ a = Math.sqrt(a);
+ if ( (frac & 0x8000) != 0 )
+ p *= a;
+ }
+ }
+ return p;
+ }
+
+ static final class MathLibV extends VarArgFunction {
+ protected MathLib mathlib;
+ public Varargs invoke(Varargs args) {
+ switch ( opcode ) {
+ case 0: { // frexp
+ double x = args.checkdouble(1);
+ if ( x == 0 ) return varargsOf(ZERO,ZERO);
+ long bits = Double.doubleToLongBits( x );
+ double m = ((bits & (~(-1L<<52))) + (1L<<52)) * ((bits >= 0)? (.5 / (1L<<52)): (-.5 / (1L<<52)));
+ double e = (((int) (bits >> 52)) & 0x7ff) - 1022;
+ return varargsOf( valueOf(m), valueOf(e) );
+ }
+ case 1: { // max
+ double m = args.checkdouble(1);
+ for ( int i=2,n=args.narg(); i<=n; ++i )
+ m = Math.max(m,args.checkdouble(i));
+ return valueOf(m);
+ }
+ case 2: { // min
+ double m = args.checkdouble(1);
+ for ( int i=2,n=args.narg(); i<=n; ++i )
+ m = Math.min(m,args.checkdouble(i));
+ return valueOf(m);
+ }
+ case 3: { // modf
+ double x = args.checkdouble(1);
+ double intPart = ( x > 0 ) ? Math.floor( x ) : Math.ceil( x );
+ double fracPart = x - intPart;
+ return varargsOf( valueOf(intPart), valueOf(fracPart) );
+ }
+ case 4: { // randomseed
+ long seed = args.checklong(1);
+ mathlib.random = new Random(seed);
+ return NONE;
+ }
+ case 5: { // random
+ if ( mathlib.random == null )
+ mathlib.random = new Random();
+
+ switch ( args.narg() ) {
+ case 0:
+ return valueOf( mathlib.random.nextDouble() );
+ case 1: {
+ int m = args.checkint(1);
+ if (m<1) argerror(1, "interval is empty");
+ return valueOf( 1 + mathlib.random.nextInt(m) );
+ }
+ default: {
+ int m = args.checkint(1);
+ int n = args.checkint(2);
+ if (n
+ * If more than one argument are required, or no arguments are required,
+ * or variable argument or variable return values,
+ * then use one of the related function
+ * {@link ZeroArgFunction}, {@link TwoArgFunction}, {@link ThreeArgFunction}, or {@link VarArgFunction}.
+ *
+ * See {@link LibFunction} for more information on implementation libraries and library functions.
+ * @see #call(LuaValue)
+ * @see LibFunction
+ * @see ZeroArgFunction
+ * @see TwoArgFunction
+ * @see ThreeArgFunction
+ * @see VarArgFunction
+ */
+abstract public class OneArgFunction extends LibFunction {
+
+ abstract public LuaValue call(LuaValue arg);
+
+ /** Default constructor */
+ public OneArgFunction() {
+ }
+
+ /** Constructor with specific environment
+ * @param env The environment to apply during constructon.
+ */
+ public OneArgFunction( LuaValue env ) {
+ this.env = env;
+ }
+
+ public final LuaValue call() {
+ return call(NIL);
+ }
+
+ public final LuaValue call(LuaValue arg1, LuaValue arg2) {
+ return call(arg1);
+ }
+
+ public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
+ return call(arg1);
+ }
+
+ public Varargs invoke(Varargs varargs) {
+ return call(varargs.arg1());
+ }
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/lib/OsLib.java b/luaj-2.0.3/src/core/org/luaj/vm2/lib/OsLib.java
new file mode 100644
index 0000000000..77c931542f
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/lib/OsLib.java
@@ -0,0 +1,323 @@
+/*******************************************************************************
+* 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.lib;
+
+import java.io.IOException;
+
+import org.luaj.vm2.LuaTable;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.Varargs;
+
+/**
+ * Subclass of {@link LibFunction} which implements the standard lua {@code os} library.
+ *
+ * It is a usable base with simplified stub functions
+ * for library functions that cannot be implemented uniformly
+ * on Jse and Jme.
+ *
+ * This can be installed as-is on either platform, or extended
+ * and refined to be used in a complete Jse implementation.
+ *
+ * Because the nature of the {@code os} library is to encapsulate
+ * os-specific features, the behavior of these functions varies considerably
+ * from their counterparts in the C platform.
+ *
+ * The following functions have limited implementations of features
+ * that are not supported well on Jme:
+ *
+ * Typically, this library is included as part of a call to either
+ * {@link JmePlatform#standardGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * @see LibFunction
+ * @see JseOsLib
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see http://www.lua.org/manual/5.1/manual.html#5.8
+ */
+public class OsLib extends VarArgFunction {
+ public static String TMP_PREFIX = ".luaj";
+ public static String TMP_SUFFIX = "tmp";
+
+ private static final int INIT = 0;
+ private static final int CLOCK = 1;
+ private static final int DATE = 2;
+ private static final int DIFFTIME = 3;
+ private static final int EXECUTE = 4;
+ private static final int EXIT = 5;
+ private static final int GETENV = 6;
+ private static final int REMOVE = 7;
+ private static final int RENAME = 8;
+ private static final int SETLOCALE = 9;
+ private static final int TIME = 10;
+ private static final int TMPNAME = 11;
+
+ private static final String[] NAMES = {
+ "clock",
+ "date",
+ "difftime",
+ "execute",
+ "exit",
+ "getenv",
+ "remove",
+ "rename",
+ "setlocale",
+ "time",
+ "tmpname",
+ };
+
+ private static final long t0 = System.currentTimeMillis();
+ private static long tmpnames = t0;
+
+ /**
+ * Create and OsLib instance.
+ */
+ public OsLib() {
+ }
+
+ public LuaValue init() {
+ LuaTable t = new LuaTable();
+ bind(t, this.getClass(), NAMES, CLOCK);
+ env.set("os", t);
+ PackageLib.instance.LOADED.set("os", t);
+ return t;
+ }
+
+ public Varargs invoke(Varargs args) {
+ try {
+ switch ( opcode ) {
+ case INIT:
+ return init();
+ case CLOCK:
+ return valueOf(clock());
+ case DATE: {
+ String s = args.optjstring(1, null);
+ double t = args.optdouble(2,-1);
+ return valueOf( date(s, t==-1? System.currentTimeMillis()/1000.: t) );
+ }
+ case DIFFTIME:
+ return valueOf(difftime(args.checkdouble(1),args.checkdouble(2)));
+ case EXECUTE:
+ return valueOf(execute(args.optjstring(1, null)));
+ case EXIT:
+ exit(args.optint(1, 0));
+ return NONE;
+ case GETENV: {
+ final String val = getenv(args.checkjstring(1));
+ return val!=null? valueOf(val): NIL;
+ }
+ case REMOVE:
+ remove(args.checkjstring(1));
+ return LuaValue.TRUE;
+ case RENAME:
+ rename(args.checkjstring(1), args.checkjstring(2));
+ return LuaValue.TRUE;
+ case SETLOCALE: {
+ String s = setlocale(args.optjstring(1,null), args.optjstring(2, "all"));
+ return s!=null? valueOf(s): NIL;
+ }
+ case TIME:
+ return valueOf(time(args.arg1().isnil()? null: args.checktable(1)));
+ case TMPNAME:
+ return valueOf(tmpname());
+ }
+ return NONE;
+ } catch ( IOException e ) {
+ return varargsOf(NIL, valueOf(e.getMessage()));
+ }
+ }
+
+ /**
+ * @return an approximation of the amount in seconds of CPU time used by
+ * the program.
+ */
+ protected double clock() {
+ return (System.currentTimeMillis()-t0) / 1000.;
+ }
+
+ /**
+ * Returns the number of seconds from time t1 to time t2.
+ * In POSIX, Windows, and some other systems, this value is exactly t2-t1.
+ * @param t2
+ * @param t1
+ * @return diffeence in time values, in seconds
+ */
+ protected double difftime(double t2, double t1) {
+ return t2 - t1;
+ }
+
+ /**
+ * If the time argument is present, this is the time to be formatted
+ * (see the os.time function for a description of this value).
+ * Otherwise, date formats the current time.
+ *
+ * If format starts with '!', then the date is formatted in Coordinated
+ * Universal Time. After this optional character, if format is the string
+ * "*t", then date returns a table with the following fields: year
+ * (four digits), month (1--12), day (1--31), hour (0--23), min (0--59),
+ * sec (0--61), wday (weekday, Sunday is 1), yday (day of the year),
+ * and isdst (daylight saving flag, a boolean).
+ *
+ * If format is not "*t", then date returns the date as a string,
+ * formatted according to the same rules as the C function strftime.
+ *
+ * When called without arguments, date returns a reasonable date and
+ * time representation that depends on the host system and on the
+ * current locale (that is, os.date() is equivalent to os.date("%c")).
+ *
+ * @param format
+ * @param time time since epoch, or -1 if not supplied
+ * @return a LString or a LTable containing date and time,
+ * formatted according to the given string format.
+ */
+ protected String date(String format, double time) {
+ return new java.util.Date((long)(time*1000)).toString();
+ }
+
+ /**
+ * This function is equivalent to the C function system.
+ * It passes command to be executed by an operating system shell.
+ * It returns a status code, which is system-dependent.
+ * If command is absent, then it returns nonzero if a shell
+ * is available and zero otherwise.
+ * @param command command to pass to the system
+ */
+ protected int execute(String command) {
+ return 0;
+ }
+
+ /**
+ * Calls the C function exit, with an optional code, to terminate the host program.
+ * @param code
+ */
+ protected void exit(int code) {
+ /* DAN200 START */
+ //System.exit(code);
+ /* DAN200 END */
+ }
+
+ /**
+ * Returns the value of the process environment variable varname,
+ * or null if the variable is not defined.
+ * @param varname
+ * @return String value, or null if not defined
+ */
+ protected String getenv(String varname) {
+ return System.getProperty(varname);
+ }
+
+ /**
+ * Deletes the file or directory with the given name.
+ * Directories must be empty to be removed.
+ * If this function fails, it throws and IOException
+ *
+ * @param filename
+ * @throws IOException if it fails
+ */
+ protected void remove(String filename) throws IOException {
+ throw new IOException( "not implemented" );
+ }
+
+ /**
+ * Renames file or directory named oldname to newname.
+ * If this function fails,it throws and IOException
+ *
+ * @param oldname old file name
+ * @param newname new file name
+ * @throws IOException if it fails
+ */
+ protected void rename(String oldname, String newname) throws IOException {
+ throw new IOException( "not implemented" );
+ }
+
+ /**
+ * Sets the current locale of the program. locale is a string specifying
+ * a locale; category is an optional string describing which category to change:
+ * "all", "collate", "ctype", "monetary", "numeric", or "time"; the default category
+ * is "all".
+ *
+ * If locale is the empty string, the current locale is set to an implementation-
+ * defined native locale. If locale is the string "C", the current locale is set
+ * to the standard C locale.
+ *
+ * When called with null as the first argument, this function only returns the
+ * name of the current locale for the given category.
+ *
+ * @param locale
+ * @param category
+ * @return the name of the new locale, or null if the request
+ * cannot be honored.
+ */
+ protected String setlocale(String locale, String category) {
+ return "C";
+ }
+
+ /**
+ * Returns the current time when called without arguments,
+ * or a time representing the date and time specified by the given table.
+ * This table must have fields year, month, and day,
+ * and may have fields hour, min, sec, and isdst
+ * (for a description of these fields, see the os.date function).
+ * @param table
+ * @return long value for the time
+ */
+ protected long time(LuaTable table) {
+ return System.currentTimeMillis();
+ }
+
+ /**
+ * Returns a string with a file name that can be used for a temporary file.
+ * The file must be explicitly opened before its use and explicitly removed
+ * when no longer needed.
+ *
+ * On some systems (POSIX), this function also creates a file with that name,
+ * to avoid security risks. (Someone else might create the file with wrong
+ * permissions in the time between getting the name and creating the file.)
+ * You still have to open the file to use it and to remove it (even if you
+ * do not use it).
+ *
+ * @return String filename to use
+ */
+ protected String tmpname() {
+ synchronized ( OsLib.class ) {
+ return TMP_PREFIX+(tmpnames++)+TMP_SUFFIX;
+ }
+ }
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/lib/PackageLib.java b/luaj-2.0.3/src/core/org/luaj/vm2/lib/PackageLib.java
new file mode 100644
index 0000000000..256c25195f
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/lib/PackageLib.java
@@ -0,0 +1,466 @@
+/*******************************************************************************
+* Copyright (c) 2010-2011 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.lib;
+
+import java.io.InputStream;
+import java.io.PrintStream;
+
+import org.luaj.vm2.LuaFunction;
+import org.luaj.vm2.LuaString;
+import org.luaj.vm2.LuaTable;
+import org.luaj.vm2.LuaThread;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.Varargs;
+
+/**
+ * Subclass of {@link LibFunction} which implements the lua standard package and module
+ * library functions.
+ *
+ *
+ * Typically, this library is included as part of a call to either
+ * {@link JsePlatform#standardGlobals()} or {@link JmePlatform#standardGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * This has been implemented to match as closely as possible the behavior in the corresponding library in C.
+ * However, the default filesystem search semantics are different and delegated to the bas library
+ * as outlined in the {@link BaseLib} and {@link JseBaseLib} documetnation.
+ * @see LibFunction
+ * @see BaseLib
+ * @see JseBaseLib
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see http://www.lua.org/manual/5.1/manual.html#5.3
+ */
+public class PackageLib extends OneArgFunction {
+
+ public static String DEFAULT_LUA_PATH = "?.lua";
+
+ public InputStream STDIN = null;
+ public PrintStream STDOUT = System.out;
+ public LuaTable LOADED;
+ public LuaTable PACKAGE;
+
+ /** Most recent instance of PackageLib */
+ public static PackageLib instance;
+
+ /** Loader that loads from preload table if found there */
+ public LuaValue preload_loader;
+
+ /** Loader that loads as a lua script using the LUA_PATH */
+ public LuaValue lua_loader;
+
+ /** Loader that loads as a Java class. Class must have public constructor and be a LuaValue */
+ public LuaValue java_loader;
+
+ private static final LuaString _M = valueOf("_M");
+ private static final LuaString _NAME = valueOf("_NAME");
+ private static final LuaString _PACKAGE = valueOf("_PACKAGE");
+ private static final LuaString _DOT = valueOf(".");
+ private static final LuaString _LOADERS = valueOf("loaders");
+ private static final LuaString _LOADED = valueOf("loaded");
+ private static final LuaString _LOADLIB = valueOf("loadlib");
+ private static final LuaString _PRELOAD = valueOf("preload");
+ private static final LuaString _PATH = valueOf("path");
+ private static final LuaString _SEEALL = valueOf("seeall");
+ private static final LuaString _SENTINEL = valueOf("\u0001");
+
+ private static final int OP_MODULE = 0;
+ private static final int OP_REQUIRE = 1;
+ private static final int OP_LOADLIB = 2;
+ private static final int OP_SEEALL = 3;
+ private static final int OP_PRELOAD_LOADER = 4;
+ private static final int OP_LUA_LOADER = 5;
+ private static final int OP_JAVA_LOADER = 6;
+
+ public PackageLib() {
+ instance = this;
+ }
+
+ public LuaValue call(LuaValue arg) {
+ env.set("require", new PkgLib1(env,"require",OP_REQUIRE,this));
+ env.set("module", new PkgLibV(env,"module",OP_MODULE,this));
+ env.set( "package", PACKAGE=tableOf( new LuaValue[] {
+ _LOADED, LOADED=tableOf(),
+ _PRELOAD, tableOf(),
+ _PATH, valueOf(DEFAULT_LUA_PATH),
+ _LOADLIB, new PkgLibV(env,"loadlib",OP_LOADLIB,this),
+ _SEEALL, new PkgLib1(env,"seeall",OP_SEEALL,this),
+ _LOADERS, listOf(new LuaValue[] {
+ preload_loader = new PkgLibV(env,"preload_loader", OP_PRELOAD_LOADER,this),
+ lua_loader = new PkgLibV(env,"lua_loader", OP_LUA_LOADER,this),
+ java_loader = new PkgLibV(env,"java_loader", OP_JAVA_LOADER,this),
+ }) }) );
+ LOADED.set("package", PACKAGE);
+ return env;
+ }
+
+ static final class PkgLib1 extends OneArgFunction {
+ PackageLib lib;
+ public PkgLib1(LuaValue env,String name, int opcode, PackageLib lib) {
+ this.env = env;
+ this.name = name;
+ this.opcode = opcode;
+ this.lib = lib;
+ }
+ public LuaValue call(LuaValue arg) {
+ switch ( opcode ) {
+ case OP_REQUIRE:
+ return lib.require(arg);
+ case OP_SEEALL: {
+ LuaTable t = arg.checktable();
+ LuaValue m = t.getmetatable();
+ if ( m == null )
+ t.setmetatable(m=tableOf());
+ m.set( INDEX, LuaThread.getGlobals() );
+ return NONE;
+ }
+ }
+ return NIL;
+ }
+ }
+
+ static final class PkgLibV extends VarArgFunction {
+ PackageLib lib;
+ public PkgLibV(LuaValue env,String name, int opcode, PackageLib lib) {
+ this.env = env;
+ this.name = name;
+ this.opcode = opcode;
+ this.lib = lib;
+ }
+ public Varargs invoke(Varargs args) {
+ switch ( opcode ) {
+ case OP_MODULE:
+ return lib.module(args);
+ case OP_LOADLIB:
+ return loadlib(args);
+ case OP_PRELOAD_LOADER: {
+ return lib.loader_preload(args);
+ }
+ case OP_LUA_LOADER: {
+ return lib.loader_Lua(args);
+ }
+ case OP_JAVA_LOADER: {
+ return lib.loader_Java(args);
+ }
+ }
+ return NONE;
+ }
+ }
+
+ /** Allow packages to mark themselves as loaded */
+ public void setIsLoaded(String name, LuaTable value) {
+ LOADED.set(name, value);
+ }
+
+ public void setLuaPath( String newLuaPath ) {
+ PACKAGE.set( _PATH, valueOf(newLuaPath) );
+ }
+
+ public String tojstring() {
+ return "package";
+ }
+
+
+ // ======================== Module, Package loading =============================
+ /**
+ * module (name [, ...])
+ *
+ * Creates a module. If there is a table in package.loaded[name], this table
+ * is the module. Otherwise, if there is a global table t with the given
+ * name, this table is the module. Otherwise creates a new table t and sets
+ * it as the value of the global name and the value of package.loaded[name].
+ * This function also initializes t._NAME with the given name, t._M with the
+ * module (t itself), and t._PACKAGE with the package name (the full module
+ * name minus last component; see below). Finally, module sets t as the new
+ * environment of the current function and the new value of
+ * package.loaded[name], so that require returns t.
+ *
+ * If name is a compound name (that is, one with components separated by
+ * dots), module creates (or reuses, if they already exist) tables for each
+ * component. For instance, if name is a.b.c, then module stores the module
+ * table in field c of field b of global a.
+ *
+ * This function may receive optional options after the module name, where
+ * each option is a function to be applied over the module.
+ */
+ public Varargs module(Varargs args) {
+ LuaString modname = args.checkstring(1);
+ int n = args.narg();
+ LuaValue value = LOADED.get(modname);
+ LuaValue module;
+ if ( ! value.istable() ) { /* not found? */
+
+ /* try global variable (and create one if it does not exist) */
+ LuaValue globals = LuaThread.getGlobals();
+ module = findtable( globals, modname );
+ if ( module == null )
+ error( "name conflict for module '"+modname+"'" );
+ LOADED.set(modname, module);
+ } else {
+ module = (LuaTable) value;
+ }
+
+
+ /* check whether table already has a _NAME field */
+ LuaValue name = module.get(_NAME);
+ if ( name.isnil() ) {
+ modinit( module, modname );
+ }
+
+ // set the environment of the current function
+ LuaFunction f = LuaThread.getCallstackFunction(1);
+ if ( f == null )
+ error("no calling function");
+ if ( ! f.isclosure() )
+ error("'module' not called from a Lua function");
+ f.setfenv(module);
+
+ // apply the functions
+ for ( int i=2; i<=n; i++ )
+ args.arg(i).call( module );
+
+ // returns no results
+ return NONE;
+ }
+
+ /**
+ *
+ * @param table the table at which to start the search
+ * @param fname the name to look up or create, such as "abc.def.ghi"
+ * @return the table for that name, possible a new one, or null if a non-table has that name already.
+ */
+ private static final LuaValue findtable(LuaValue table, LuaString fname) {
+ int b, e=(-1);
+ do {
+ e = fname.indexOf(_DOT, b=e+1 );
+ if ( e < 0 )
+ e = fname.m_length;
+ LuaString key = fname.substring(b, e);
+ LuaValue val = table.rawget(key);
+ if ( val.isnil() ) { /* no such field? */
+ LuaTable field = new LuaTable(); /* new table for field */
+ table.set(key, field);
+ table = field;
+ } else if ( ! val.istable() ) { /* field has a non-table value? */
+ return null;
+ } else {
+ table = val;
+ }
+ } while ( e < fname.m_length );
+ return table;
+ }
+
+ private static final void modinit(LuaValue module, LuaString modname) {
+ /* module._M = module */
+ module.set(_M, module);
+ int e = modname.lastIndexOf(_DOT);
+ module.set(_NAME, modname );
+ module.set(_PACKAGE, (e<0? EMPTYSTRING: modname.substring(0,e+1)) );
+ }
+
+ /**
+ * require (modname)
+ *
+ * Loads the given module. The function starts by looking into the package.loaded table to
+ * determine whether modname is already loaded. If it is, then require returns the value
+ * stored at package.loaded[modname]. Otherwise, it tries to find a loader for the module.
+ *
+ * To find a loader, require is guided by the package.loaders array. By changing this array,
+ * we can change how require looks for a module. The following explanation is based on the
+ * default configuration for package.loaders.
+ *
+ * First require queries package.preload[modname]. If it has a value, this value
+ * (which should be a function) is the loader. Otherwise require searches for a Lua loader
+ * using the path stored in package.path. If that also fails, it searches for a C loader
+ * using the path stored in package.cpath. If that also fails, it tries an all-in-one loader
+ * (see package.loaders).
+ *
+ * Once a loader is found, require calls the loader with a single argument, modname.
+ * If the loader returns any value, require assigns the returned value to package.loaded[modname].
+ * If the loader returns no value and has not assigned any value to package.loaded[modname],
+ * then require assigns true to this entry. In any case, require returns the final value of
+ * package.loaded[modname].
+ *
+ * If there is any error loading or running the module, or if it cannot find any loader for
+ * the module, then require signals an error.
+ */
+ public LuaValue require( LuaValue arg ) {
+ LuaString name = arg.checkstring();
+ LuaValue loaded = LOADED.get(name);
+ if ( loaded.toboolean() ) {
+ if ( loaded == _SENTINEL )
+ error("loop or previous error loading module '"+name+"'");
+ return loaded;
+ }
+
+ /* else must load it; iterate over available loaders */
+ LuaTable tbl = PACKAGE.get(_LOADERS).checktable();
+ StringBuffer sb = new StringBuffer();
+ LuaValue chunk = null;
+ for ( int i=1; true; i++ ) {
+ LuaValue loader = tbl.get(i);
+ if ( loader.isnil() ) {
+ error( "module '"+name+"' not found: "+name+sb );
+ }
+
+ /* call loader with module name as argument */
+ chunk = loader.call(name);
+ if ( chunk.isfunction() )
+ break;
+ if ( chunk.isstring() )
+ sb.append( chunk.tojstring() );
+ }
+
+ // load the module using the loader
+ LOADED.set(name, _SENTINEL);
+ LuaValue result = chunk.call(name);
+ if ( ! result.isnil() )
+ LOADED.set( name, result );
+ else if ( (result = LOADED.get(name)) == _SENTINEL )
+ LOADED.set( name, result = LuaValue.TRUE );
+ return result;
+ }
+
+ public static Varargs loadlib( Varargs args ) {
+ args.checkstring(1);
+ return varargsOf(NIL, valueOf("dynamic libraries not enabled"), valueOf("absent"));
+ }
+
+ LuaValue loader_preload( Varargs args ) {
+ LuaString name = args.checkstring(1);
+ LuaValue preload = PACKAGE.get(_PRELOAD).checktable();
+ LuaValue val = preload.get(name);
+ return val.isnil()?
+ valueOf("\n\tno field package.preload['"+name+"']"):
+ val;
+ }
+
+ LuaValue loader_Lua( Varargs args ) {
+ String name = args.checkjstring(1);
+ InputStream is = null;
+
+
+ // get package path
+ LuaValue pp = PACKAGE.get(_PATH);
+ if ( ! pp.isstring() )
+ return valueOf("package.path is not a string");
+ String path = pp.tojstring();
+
+ // check the path elements
+ int e = -1;
+ int n = path.length();
+ StringBuffer sb = null;
+ name = name.replace('.','/');
+ while ( e < n ) {
+
+ // find next template
+ int b = e+1;
+ e = path.indexOf(';',b);
+ if ( e < 0 )
+ e = path.length();
+ String template = path.substring(b,e);
+
+ // create filename
+ int q = template.indexOf('?');
+ String filename = template;
+ if ( q >= 0 ) {
+ filename = template.substring(0,q) + name + template.substring(q+1);
+ }
+
+ // try loading the file
+ Varargs v = BaseLib.loadFile(filename);
+ if ( v.arg1().isfunction() )
+ return v.arg1();
+
+ // report error
+ if ( sb == null )
+ sb = new StringBuffer();
+ sb.append( "\n\t'"+filename+"': "+v.arg(2) );
+ }
+ return valueOf(sb.toString());
+ }
+
+ LuaValue loader_Java( Varargs args ) {
+ String name = args.checkjstring(1);
+ String classname = toClassname( name );
+ Class c = null;
+ LuaValue v = null;
+ try {
+ c = Class.forName(classname);
+ v = (LuaValue) c.newInstance();
+ v.setfenv(env);
+ return v;
+ } catch ( ClassNotFoundException cnfe ) {
+ return valueOf("\n\tno class '"+classname+"'" );
+ } catch ( Exception e ) {
+ return valueOf("\n\tjava load failed on '"+classname+"', "+e );
+ }
+ }
+
+ /** Convert lua filename to valid class name */
+ public static final String toClassname( String filename ) {
+ int n=filename.length();
+ int j=n;
+ if ( filename.endsWith(".lua") )
+ j -= 4;
+ for ( int k=0; k
+ * This is used by required to load files that are part of
+ * the application, and implemented by BaseLib
+ * for both the Jme and Jse platforms.
+ *
+ * The Jme version of base lib {@link BaseLib}
+ * implements {@link BaseLib#FINDER} via {@link Class#getResourceAsStream(String)},
+ * while the Jse version {@link JseBaseLib} implements it using {@link java.io.File#File(String)}.
+ *
+ * The io library does not use this API for file manipulation.
+ *
+ * @see BaseLib
+ * @see BaseLib#FINDER
+ * @see JseBaseLib
+ * @see JmePlatform
+ * @see JsePlatform
+ */
+public interface ResourceFinder {
+
+ /**
+ * Try to open a file, or return null if not found.
+ *
+ * @see org.luaj.vm2.lib.BaseLib
+ * @see org.luaj.vm2.lib.jse.JseBaseLib
+ *
+ * @param filename
+ * @return InputStream, or null if not found.
+ */
+ public InputStream findResource( String filename );
+}
\ No newline at end of file
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/lib/StringLib.java b/luaj-2.0.3/src/core/org/luaj/vm2/lib/StringLib.java
new file mode 100644
index 0000000000..d7bc7cd902
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/lib/StringLib.java
@@ -0,0 +1,1190 @@
+/*******************************************************************************
+* Copyright (c) 2009-2011 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.lib;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.luaj.vm2.LuaClosure;
+import org.luaj.vm2.Buffer;
+import org.luaj.vm2.LuaString;
+import org.luaj.vm2.LuaTable;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.Varargs;
+import org.luaj.vm2.compiler.DumpState;
+
+/**
+ * Subclass of {@link LibFunction} which implements the lua standard {@code string}
+ * library.
+ *
+ *
+ * Typically, this library is included as part of a call to either
+ * {@link JsePlatform#standardGlobals()} or {@link JmePlatform#standardGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * This is a direct port of the corresponding library in C.
+ * @see LibFunction
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see http://www.lua.org/manual/5.1/manual.html#5.4
+ */
+public class StringLib extends OneArgFunction {
+
+ public static LuaTable instance;
+
+ public StringLib() {
+ }
+
+ public LuaValue call(LuaValue arg) {
+ LuaTable t = new LuaTable();
+ bind(t, StringLib1.class, new String[] {
+ "dump", "len", "lower", "reverse", "upper", } );
+ bind(t, StringLibV.class, new String[] {
+ "byte", "char", "find", "format",
+ "gmatch", "gsub", "match", "rep",
+ "sub"} );
+ env.set("string", t);
+ instance = t;
+ if ( LuaString.s_metatable == null )
+ LuaString.s_metatable = tableOf( new LuaValue[] { INDEX, t } );
+ PackageLib.instance.LOADED.set("string", t);
+ return t;
+ }
+
+ static final class StringLib1 extends OneArgFunction {
+ public LuaValue call(LuaValue arg) {
+ switch ( opcode ) {
+ case 0: return dump(arg); // dump (function)
+ case 1: return StringLib.len(arg); // len (function)
+ case 2: return lower(arg); // lower (function)
+ case 3: return reverse(arg); // reverse (function)
+ case 4: return upper(arg); // upper (function)
+ }
+ return NIL;
+ }
+ }
+
+ static final class StringLibV extends VarArgFunction {
+ public Varargs invoke(Varargs args) {
+ switch ( opcode ) {
+ case 0: return StringLib.byte_( args );
+ case 1: return StringLib.char_( args );
+ case 2: return StringLib.find( args );
+ case 3: return StringLib.format( args );
+ case 4: return StringLib.gmatch( args );
+ case 5: return StringLib.gsub( args );
+ case 6: return StringLib.match( args );
+ case 7: return StringLib.rep( args );
+ case 8: return StringLib.sub( args );
+ }
+ return NONE;
+ }
+ }
+
+ /**
+ * string.byte (s [, i [, j]])
+ *
+ * Returns the internal numerical codes of the
+ * characters s[i], s[i+1], ..., s[j]. The default value for i is 1; the
+ * default value for j is i.
+ *
+ * Note that numerical codes are not necessarily portable across platforms.
+ *
+ * @param args the calling args
+ */
+ static Varargs byte_( Varargs args ) {
+ LuaString s = args.checkstring(1);
+ int l = s.m_length;
+ int posi = posrelat( args.optint(2,1), l );
+ int pose = posrelat( args.optint(3,posi), l );
+ int n,i;
+ if (posi <= 0) posi = 1;
+ if (pose > l) pose = l;
+ if (posi > pose) return NONE; /* empty interval; return no values */
+ n = (int)(pose - posi + 1);
+ if (posi + n <= pose) /* overflow? */
+ error("string slice too long");
+ LuaValue[] v = new LuaValue[n];
+ for (i=0; i
+ * Typically, this library is included as part of a call to either
+ * {@link JsePlatform#standardGlobals()} or {@link JmePlatform#standardGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * This has been implemented to match as closely as possible the behavior in the corresponding library in C.
+ * @see LibFunction
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see http://www.lua.org/manual/5.1/manual.html#5.5
+ */
+public class TableLib extends OneArgFunction {
+
+ public TableLib() {
+ }
+
+ private LuaTable init() {
+ LuaTable t = new LuaTable();
+ bind(t, TableLib.class, new String[] { "getn", "maxn", }, 1 );
+ bind(t, TableLibV.class, new String[] {
+ "remove", "concat", "insert", "sort", "foreach", "foreachi", } );
+ env.set("table", t);
+ PackageLib.instance.LOADED.set("table", t);
+ return t;
+ }
+
+ public LuaValue call(LuaValue arg) {
+ switch ( opcode ) {
+ case 0: // init library
+ return init();
+ case 1: // "getn" (table) -> number
+ return arg.checktable().getn();
+ case 2: // "maxn" (table) -> number
+ return valueOf( arg.checktable().maxn());
+ }
+ return NIL;
+ }
+
+ static final class TableLibV extends VarArgFunction {
+ public Varargs invoke(Varargs args) {
+ switch ( opcode ) {
+ case 0: { // "remove" (table [, pos]) -> removed-ele
+ LuaTable table = args.checktable(1);
+ int pos = args.narg()>1? args.checkint(2): 0;
+ return table.remove(pos);
+ }
+ case 1: { // "concat" (table [, sep [, i [, j]]]) -> string
+ LuaTable table = args.checktable(1);
+ return table.concat(
+ args.optstring(2,LuaValue.EMPTYSTRING),
+ args.optint(3,1),
+ args.isvalue(4)? args.checkint(4): table.length() );
+ }
+ case 2: { // "insert" (table, [pos,] value) -> prev-ele
+ final LuaTable table = args.checktable(1);
+ final int pos = args.narg()>2? args.checkint(2): 0;
+ final LuaValue value = args.arg( args.narg()>2? 3: 2 );
+ table.insert( pos, value );
+ return NONE;
+ }
+ case 3: { // "sort" (table [, comp]) -> void
+ LuaTable table = args.checktable(1);
+ LuaValue compare = (args.isnoneornil(2)? NIL: args.checkfunction(2));
+ table.sort( compare );
+ return NONE;
+ }
+ case 4: { // (table, func) -> void
+ return args.checktable(1).foreach( args.checkfunction(2) );
+ }
+ case 5: { // "foreachi" (table, func) -> void
+ return args.checktable(1).foreachi( args.checkfunction(2) );
+ }
+ }
+ return NONE;
+ }
+ }
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/lib/ThreeArgFunction.java b/luaj-2.0.3/src/core/org/luaj/vm2/lib/ThreeArgFunction.java
new file mode 100644
index 0000000000..d958d72610
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/lib/ThreeArgFunction.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+* 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.lib;
+
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.Varargs;
+
+/** Abstract base class for Java function implementations that take two arguments and
+ * return one value.
+ *
+ * Subclasses need only implement {@link LuaValue#call(LuaValue,LuaValue,LuaValue)} to complete this class,
+ * simplifying development.
+ * All other uses of {@link #call()}, {@link #invoke(Varargs)},etc,
+ * are routed through this method by this class,
+ * dropping or extending arguments with {@code nil} values as required.
+ *
+ * If more or less than three arguments are required,
+ * or variable argument or variable return values,
+ * then use one of the related function
+ * {@link ZeroArgFunction}, {@link OneArgFunction}, {@link TwoArgFunction}, or {@link VarArgFunction}.
+ *
+ * See {@link LibFunction} for more information on implementation libraries and library functions.
+ * @see #call(LuaValue,LuaValue,LuaValue)
+ * @see LibFunction
+ * @see ZeroArgFunction
+ * @see OneArgFunction
+ * @see TwoArgFunction
+ * @see VarArgFunction
+ */
+abstract public class ThreeArgFunction extends LibFunction {
+
+ abstract public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3);
+
+ /** Default constructor */
+ public ThreeArgFunction() {
+ }
+
+ /** Constructor with specific environment
+ * @param env The environment to apply during constructon.
+ */
+ public ThreeArgFunction( LuaValue env ) {
+ this.env = env;
+ }
+
+ public final LuaValue call() {
+ return call(NIL, NIL, NIL);
+ }
+
+ public final LuaValue call(LuaValue arg) {
+ return call(arg, NIL, NIL);
+ }
+
+ public LuaValue call(LuaValue arg1, LuaValue arg2) {
+ return call(arg1, arg2, NIL);
+ }
+
+ public Varargs invoke(Varargs varargs) {
+ return call(varargs.arg1(),varargs.arg(2),varargs.arg(3));
+ }
+
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/lib/TwoArgFunction.java b/luaj-2.0.3/src/core/org/luaj/vm2/lib/TwoArgFunction.java
new file mode 100644
index 0000000000..b2c1b0c75b
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/lib/TwoArgFunction.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+* 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.lib;
+
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.Varargs;
+
+/** Abstract base class for Java function implementations that take two arguments and
+ * return one value.
+ *
+ * Subclasses need only implement {@link LuaValue#call(LuaValue,LuaValue)} to complete this class,
+ * simplifying development.
+ * All other uses of {@link #call()}, {@link #invoke(Varargs)},etc,
+ * are routed through this method by this class,
+ * dropping or extending arguments with {@code nil} values as required.
+ *
+ * If more or less than two arguments are required,
+ * or variable argument or variable return values,
+ * then use one of the related function
+ * {@link ZeroArgFunction}, {@link OneArgFunction}, {@link ThreeArgFunction}, or {@link VarArgFunction}.
+ *
+ * See {@link LibFunction} for more information on implementation libraries and library functions.
+ * @see #call(LuaValue,LuaValue)
+ * @see LibFunction
+ * @see ZeroArgFunction
+ * @see OneArgFunction
+ * @see ThreeArgFunction
+ * @see VarArgFunction
+ */
+abstract public class TwoArgFunction extends LibFunction {
+
+ abstract public LuaValue call(LuaValue arg1, LuaValue arg2);
+
+ /** Default constructor */
+ public TwoArgFunction() {
+ }
+
+ /** Constructor with specific environment
+ * @param env The environment to apply during constructon.
+ */
+ public TwoArgFunction( LuaValue env ) {
+ this.env = env;
+ }
+
+ public final LuaValue call() {
+ return call(NIL, NIL);
+ }
+
+ public final LuaValue call(LuaValue arg) {
+ return call(arg, NIL);
+ }
+
+ public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
+ return call(arg1, arg2);
+ }
+
+ public Varargs invoke(Varargs varargs) {
+ return call(varargs.arg1(),varargs.arg(2));
+ }
+
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/lib/VarArgFunction.java b/luaj-2.0.3/src/core/org/luaj/vm2/lib/VarArgFunction.java
new file mode 100644
index 0000000000..9fb07af1a3
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/lib/VarArgFunction.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+* 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.lib;
+
+import org.luaj.vm2.LuaThread;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.Varargs;
+
+/** Abstract base class for Java function implementations that takes varaiable arguments and
+ * returns multiple return values.
+ *
+ * Subclasses need only implement {@link LuaValue#invoke(Varargs)} to complete this class,
+ * simplifying development.
+ * All other uses of {@link #call(LuaValue)}, {@link #invoke()},etc,
+ * are routed through this method by this class,
+ * converting arguments to {@linnk Varargs} and
+ * dropping or extending return values with {@code nil} values as required.
+ *
+ * If between one and three arguments are required, and only one return value is returned,
+ * {@link ZeroArgFunction}, {@link OneArgFunction}, {@link TwoArgFunction}, or {@link ThreeArgFunction}.
+ *
+ * See {@link LibFunction} for more information on implementation libraries and library functions.
+ * @see #invoke(Varargs)
+ * @see LibFunction
+ * @see ZeroArgFunction
+ * @see OneArgFunction
+ * @see TwoArgFunction
+ * @see ThreeArgFunction
+ */
+abstract public class VarArgFunction extends LibFunction {
+ public VarArgFunction() {
+ }
+
+ public VarArgFunction( LuaValue env ) {
+ this.env = env;
+ }
+
+ public LuaValue call() {
+ return invoke(NONE).arg1();
+ }
+
+ public LuaValue call(LuaValue arg) {
+ return invoke(arg).arg1();
+ }
+
+ public LuaValue call(LuaValue arg1, LuaValue arg2) {
+ return invoke(varargsOf(arg1,arg2)).arg1();
+ }
+
+ public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
+ return invoke(varargsOf(arg1,arg2,arg3)).arg1();
+ }
+
+ /**
+ * Override and implement for the best performance.
+ * May not have expected behavior for tail calls.
+ * Should not be used if either:
+ * - function needs to be used as a module
+ * - function has a possibility of returning a TailcallVarargs
+ * @param args the arguments to the function call.
+ */
+ public Varargs invoke(Varargs args) {
+ LuaThread.CallStack cs = LuaThread.onCall(this);
+ try {
+ return this.onInvoke(args).eval();
+ } finally {
+ cs.onReturn();
+ }
+ }
+
+ /**
+ * Override to provide a call implementation that runs in an environment
+ * that can participate in setfenv, and behaves as expected
+ * when returning TailcallVarargs.
+ * @param args the arguments to the function call.
+ */
+ public Varargs onInvoke(Varargs args) {
+ return invoke(args);
+ }
+
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/lib/ZeroArgFunction.java b/luaj-2.0.3/src/core/org/luaj/vm2/lib/ZeroArgFunction.java
new file mode 100644
index 0000000000..526d2fedeb
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/lib/ZeroArgFunction.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+* Copyright (c) 2009-2011 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.lib;
+
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.Varargs;
+
+/** Abstract base class for Java function implementations that take no arguments and
+ * return one value.
+ *
+ * Subclasses need only implement {@link LuaValue#call()} to complete this class,
+ * simplifying development.
+ * All other uses of {@link #call(LuaValue)}, {@link #invoke(Varargs)},etc,
+ * are routed through this method by this class.
+ *
+ * If one or more arguments are required, or variable argument or variable return values,
+ * then use one of the related function
+ * {@link OneArgFunction}, {@link TwoArgFunction}, {@link ThreeArgFunction}, or {@link VarArgFunction}.
+ *
+ * See {@link LibFunction} for more information on implementation libraries and library functions.
+ * @see #call()
+ * @see LibFunction
+ * @see OneArgFunction
+ * @see TwoArgFunction
+ * @see ThreeArgFunction
+ * @see VarArgFunction
+ */
+abstract public class ZeroArgFunction extends LibFunction {
+
+ abstract public LuaValue call();
+
+ /** Default constructor */
+ public ZeroArgFunction() {
+ }
+
+ /** Constructor with specific environment
+ * @param env The environment to apply during constructon.
+ */
+ public ZeroArgFunction( LuaValue env ) {
+ this.env = env;
+ }
+
+ public LuaValue call(LuaValue arg) {
+ return call();
+ }
+
+ public LuaValue call(LuaValue arg1, LuaValue arg2) {
+ return call();
+ }
+
+ public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
+ return call();
+ }
+
+ public Varargs invoke(Varargs varargs) {
+ return call();
+ }
+}
diff --git a/luaj-2.0.3/src/jme/org/luaj/vm2/lib/jme/JmeIoLib.java b/luaj-2.0.3/src/jme/org/luaj/vm2/lib/jme/JmeIoLib.java
new file mode 100644
index 0000000000..1a66df9e20
--- /dev/null
+++ b/luaj-2.0.3/src/jme/org/luaj/vm2/lib/jme/JmeIoLib.java
@@ -0,0 +1,227 @@
+/*******************************************************************************
+* Copyright (c) 2009-2011 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.lib.jme;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.microedition.io.Connector;
+import javax.microedition.io.StreamConnection;
+
+import org.luaj.vm2.LuaString;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.lib.BaseLib;
+import org.luaj.vm2.lib.IoLib;
+import org.luaj.vm2.lib.LibFunction;
+
+/**
+ * Subclass of {@link IoLib} and therefore {@link LibFunction} which implements the lua standard {@code io}
+ * library for the JSE platform.
+ *
+ * The implementation of the is based on CLDC 1.0 and StreamConnection.
+ * However, seek is not supported.
+ *
+ * Typically, this library is included as part of a call to
+ * {@link JmePlatform#standardGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * This has been implemented to match as closely as possible the behavior in the corresponding library in C.
+ * @see LibFunction
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see IoLib
+ * @see JseIoLib
+ * @see http://www.lua.org/manual/5.1/manual.html#5.6
+ */
+public class JmeIoLib extends IoLib {
+
+ public JmeIoLib() {
+ super();
+ }
+
+ protected File wrapStdin() throws IOException {
+ return new FileImpl(BaseLib.instance.STDIN);
+ }
+
+ protected File wrapStdout() throws IOException {
+ return new FileImpl(BaseLib.instance.STDOUT);
+ }
+
+ protected File openFile( String filename, boolean readMode, boolean appendMode, boolean updateMode, boolean binaryMode ) throws IOException {
+ String url = "file:///" + filename;
+ int mode = readMode? Connector.READ: Connector.READ_WRITE;
+ StreamConnection conn = (StreamConnection) Connector.open( url, mode );
+ File f = readMode?
+ new FileImpl(conn, conn.openInputStream(), null):
+ new FileImpl(conn, conn.openInputStream(), conn.openOutputStream());
+ /*
+ if ( appendMode ) {
+ f.seek("end",0);
+ } else {
+ if ( ! readMode )
+ conn.truncate(0);
+ }
+ */
+ return f;
+ }
+
+ private static void notimplemented() throws IOException {
+ throw new IOException("not implemented");
+ }
+
+ protected File openProgram(String prog, String mode) throws IOException {
+ notimplemented();
+ return null;
+ }
+
+ protected File tmpFile() throws IOException {
+ notimplemented();
+ return null;
+ }
+
+ private final class FileImpl extends File {
+ private final StreamConnection conn;
+ private final InputStream is;
+ private final OutputStream os;
+ private boolean closed = false;
+ private boolean nobuffer = false;
+ private int lookahead = -1;
+ private FileImpl( StreamConnection conn, InputStream is, OutputStream os ) {
+ this.conn = conn;
+ this.is = is;
+ this.os = os;
+ }
+ private FileImpl( InputStream i ) {
+ this( null, i, null );
+ }
+ private FileImpl( OutputStream o ) {
+ this( null, null, o );
+ }
+ public String tojstring() {
+ return "file ("+this.hashCode()+")";
+ }
+ public boolean isstdfile() {
+ return conn == null;
+ }
+ public void close() throws IOException {
+ closed = true;
+ if ( conn != null ) {
+ conn.close();
+ }
+ }
+ public void flush() throws IOException {
+ if ( os != null )
+ os.flush();
+ }
+ public void write(LuaString s) throws IOException {
+ if ( os != null )
+ os.write( s.m_bytes, s.m_offset, s.m_length );
+ else
+ notimplemented();
+ if ( nobuffer )
+ flush();
+ }
+ public boolean isclosed() {
+ return closed;
+ }
+ public int seek(String option, int pos) throws IOException {
+ /*
+ if ( conn != null ) {
+ if ( "set".equals(option) ) {
+ conn.seek(pos);
+ return (int) conn.getFilePointer();
+ } else if ( "end".equals(option) ) {
+ conn.seek(conn.length()+1+pos);
+ return (int) conn.length()+1;
+ } else {
+ conn.seek(conn.getFilePointer()+pos);
+ return (int) conn.getFilePointer();
+ }
+ }
+ */
+ notimplemented();
+ return 0;
+ }
+ public void setvbuf(String mode, int size) {
+ nobuffer = "no".equals(mode);
+ }
+
+ // get length remaining to read
+ public int remaining() throws IOException {
+ return -1;
+ }
+
+ // peek ahead one character
+ public int peek() throws IOException {
+ if ( lookahead < 0 )
+ lookahead = is.read();
+ return lookahead;
+ }
+
+ // return char if read, -1 if eof, throw IOException on other exception
+ public int read() throws IOException {
+ if ( lookahead >= 0 ) {
+ int c = lookahead;
+ lookahead = -1;
+ return c;
+ }
+ if ( is != null )
+ return is.read();
+ notimplemented();
+ return 0;
+ }
+
+ // return number of bytes read if positive, -1 if eof, throws IOException
+ public int read(byte[] bytes, int offset, int length) throws IOException {
+ int n,i=0;
+ if (is!=null) {
+ if ( length > 0 && lookahead >= 0 ) {
+ bytes[offset] = (byte) lookahead;
+ lookahead = -1;
+ i += 1;
+ }
+ for ( ; i
+ * The JME platform, being limited, cannot implement all libraries in all aspects. The main limitations are
+ *
+ * It is used to allocate either a set of standard globals using
+ * {@link #standardGlobals()} or debug globals using {@link #debugGlobals()}
+ *
+ * A simple example of initializing globals and using them from Java is:
+ *
+ * Once globals are created, a simple way to load and run a script is:
+ *
+ * although {@code require} could also be used:
+ *
+ * The standard globals will contain all standard libraries in their JME flavors:
+ *
+ * The debug globals are simply the standard globals plus the {@code debug} library {@link DebugLib}.
+ *
+ *
+ * The class ensures that initialization is done in the correct order,
+ * and that linkage is made to {@link LuaThread#setGlobals(LuaValue)}.
+ * @see JsePlatform
+ * @see LoadState
+ */
+public class JmePlatform {
+
+ /**
+ * Create a standard set of globals for JME including all the libraries.
+ *
+ * @return Table of globals initialized with the standard JME libraries
+ * @see #debugGlobals()
+ * @see JsePlatform
+ * @see JmePlatform
+ */
+ public static LuaTable standardGlobals() {
+ LuaTable _G = new LuaTable();
+ _G.load(new BaseLib());
+ _G.load(new PackageLib());
+ _G.load(new OsLib());
+ _G.load(new MathLib());
+ _G.load(new TableLib());
+ _G.load(new StringLib());
+ _G.load(new CoroutineLib());
+ _G.load(new JmeIoLib());
+ LuaThread.setGlobals(_G);
+ LuaC.install();
+ return _G;
+ }
+
+ /** Create standard globals including the {@link debug} library.
+ *
+ * @return Table of globals initialized with the standard JSE and debug libraries
+ * @see #standarsGlobals()
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see DebugLib
+ */
+ public static LuaTable debugGlobals() {
+ LuaTable _G = standardGlobals();
+ _G.load(new DebugLib());
+ return _G;
+ }
+}
diff --git a/luaj-2.0.3/src/jse/META-INF/services/javax.script.ScriptEngineFactory b/luaj-2.0.3/src/jse/META-INF/services/javax.script.ScriptEngineFactory
new file mode 100644
index 0000000000..e3e6dde468
--- /dev/null
+++ b/luaj-2.0.3/src/jse/META-INF/services/javax.script.ScriptEngineFactory
@@ -0,0 +1 @@
+org.luaj.vm2.script.LuaScriptEngineFactory
\ No newline at end of file
diff --git a/luaj-2.0.3/src/jse/lua.java b/luaj-2.0.3/src/jse/lua.java
new file mode 100644
index 0000000000..ecc1230ace
--- /dev/null
+++ b/luaj-2.0.3/src/jse/lua.java
@@ -0,0 +1,223 @@
+/*******************************************************************************
+* 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.
+******************************************************************************/
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Vector;
+
+import org.luaj.vm2.LoadState;
+import org.luaj.vm2.Lua;
+import org.luaj.vm2.LuaFunction;
+import org.luaj.vm2.LuaTable;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.Varargs;
+import org.luaj.vm2.lib.jse.JsePlatform;
+import org.luaj.vm2.lua2java.Lua2Java;
+import org.luaj.vm2.luajc.LuaJC;
+
+
+/**
+ * lua command for use in java se environments.
+ */
+public class lua {
+ private static final String version = Lua._VERSION + "Copyright (c) 2009 Luaj.org.org";
+
+ private static final String usage =
+ "usage: java -cp luaj-jse.jar lua [options] [script [args]].\n" +
+ "Available options are:\n" +
+ " -e stat execute string 'stat'\n" +
+ " -l name require library 'name'\n" +
+ " -i enter interactive mode after executing 'script'\n" +
+ " -v show version information\n" +
+ " -j use lua2java source-to-source compiler\n" +
+ " -b use luajc bytecode-to-bytecode compiler (requires bcel on class path)\n" +
+ " -n nodebug - do not load debug library by default\n" +
+ " -- stop handling options\n" +
+ " - execute stdin and stop handling options";
+
+ private static void usageExit() {
+ System.out.println(usage);
+ System.exit(-1);
+ }
+
+ private static LuaValue _G;
+
+ public static void main( String[] args ) throws IOException {
+
+ // process args
+ boolean interactive = (args.length == 0);
+ boolean versioninfo = false;
+ boolean processing = true;
+ boolean nodebug = false;
+ boolean luajc = false;
+ boolean lua2java = false;
+ Vector libs = null;
+ try {
+ // stateful argument processing
+ for ( int i=0; i
+ * To coerce scalar types, the various, generally the {@code valueOf(type)} methods
+ * on {@link LuaValue} may be used:
+ *
+ * To coerce arrays of objects and lists, the {@code listOf(..)} and {@code tableOf(...)} methods
+ * on {@link LuaValue} may be used:
+ *
+ * Integral types {@code boolean}, {@code byte}, {@code char}, and {@code int}
+ * will become {@link LuaInteger};
+ * {@code long}, {@code float}, and {@code double} will become {@link LuaDouble};
+ * {@code String} and {@code byte[]} will become {@link LuaString};
+ * other types will become {@link LuaUserdata}.
+ * @param o Java object needing conversion
+ * @return {@link LuaValue} corresponding to the supplied Java value.
+ * @see LuaValue
+ * @see LuaInteger
+ * @see LuaDouble
+ * @see LuaString
+ * @see LuaUserdata
+ */
+ public static LuaValue coerce(Object o) {
+ if ( o == null )
+ return LuaValue.NIL;
+ Class clazz = o.getClass();
+ Coercion c = (Coercion) COERCIONS.get( clazz );
+ if ( c == null ) {
+ c = o instanceof Class? JavaClass.forClass((Class)o):
+ clazz.isArray()? arrayCoercion:
+ instanceCoercion;
+ COERCIONS.put( clazz, c );
+ }
+ return c.coerce(o);
+ }
+
+ static final Coercion instanceCoercion = new Coercion() {
+ public LuaValue coerce(Object javaValue) {
+ return new JavaInstance(javaValue);
+ }
+ };
+
+ // should be userdata?
+ static final Coercion arrayCoercion = new Coercion() {
+ public LuaValue coerce(Object javaValue) {
+ return new JavaArray(javaValue);
+ }
+ };
+}
diff --git a/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/CoerceLuaToJava.java b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/CoerceLuaToJava.java
new file mode 100644
index 0000000000..7191162ecb
--- /dev/null
+++ b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/CoerceLuaToJava.java
@@ -0,0 +1,367 @@
+/*******************************************************************************
+* Copyright (c) 2009-2011 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.lib.jse;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.luaj.vm2.LuaError;
+import org.luaj.vm2.LuaString;
+import org.luaj.vm2.LuaTable;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.Varargs;
+
+/**
+ * Helper class to coerce values from lua to Java within the luajava library.
+ *
+ * This class is primarily used by the {@link LuajavaLib},
+ * but can also be used directly when working with Java/lua bindings.
+ *
+ * To coerce to specific Java values, generally the {@code toType()} methods
+ * on {@link LuaValue} may be used:
+ *
+ * For data in lua tables, the various methods on {@link LuaTable} can be used directly
+ * to convert data to something more useful.
+ *
+ * @see LuajavaLib
+ * @see CoerceJavaToLua
+ */
+public class CoerceLuaToJava {
+
+ static int SCORE_NULL_VALUE = 0x10;
+ static int SCORE_WRONG_TYPE = 0x100;
+ static int SCORE_UNCOERCIBLE = 0x10000;
+
+ static interface Coercion {
+ public int score( LuaValue value );
+ public Object coerce( LuaValue value );
+ };
+
+ /**
+ * Coerce a LuaValue value to a specified java class
+ * @param value LuaValue to coerce
+ * @param clazz Class to coerce into
+ * @return Object of type clazz (or a subclass) with the corresponding value.
+ */
+ public static Object coerce(LuaValue value, Class clazz) {
+ return getCoercion(clazz).coerce(value);
+ }
+
+ static final Map COERCIONS = Collections.synchronizedMap(new HashMap());
+
+ static final class BoolCoercion implements Coercion {
+ public String toString() {
+ return "BoolCoercion()";
+ }
+ public int score( LuaValue value ) {
+ switch ( value.type() ) {
+ case LuaValue.TBOOLEAN:
+ return 0;
+ }
+ return 1;
+ }
+
+ public Object coerce(LuaValue value) {
+ return value.toboolean()? Boolean.TRUE: Boolean.FALSE;
+ }
+ }
+
+ static final class NumericCoercion implements Coercion {
+ static final int TARGET_TYPE_BYTE = 0;
+ static final int TARGET_TYPE_CHAR = 1;
+ static final int TARGET_TYPE_SHORT = 2;
+ static final int TARGET_TYPE_INT = 3;
+ static final int TARGET_TYPE_LONG = 4;
+ static final int TARGET_TYPE_FLOAT = 5;
+ static final int TARGET_TYPE_DOUBLE = 6;
+ static final String[] TYPE_NAMES = { "byte", "char", "short", "int", "long", "float", "double" };
+ final int targetType;
+ public String toString() {
+ return "NumericCoercion("+TYPE_NAMES[targetType]+")";
+ }
+ NumericCoercion(int targetType) {
+ this.targetType = targetType;
+ }
+ public int score( LuaValue value ) {
+ if ( value.isint() ) {
+ switch ( targetType ) {
+ case TARGET_TYPE_BYTE: {
+ int i = value.toint();
+ return (i==(byte)i)? 0: SCORE_WRONG_TYPE;
+ }
+ case TARGET_TYPE_CHAR: {
+ int i = value.toint();
+ return (i==(byte)i)? 1: (i==(char)i)? 0: SCORE_WRONG_TYPE;
+ }
+ case TARGET_TYPE_SHORT: {
+ int i = value.toint();
+ return (i==(byte)i)? 1: (i==(short)i)? 0: SCORE_WRONG_TYPE;
+ }
+ case TARGET_TYPE_INT: {
+ int i = value.toint();
+ return (i==(byte)i)? 2: ((i==(char)i) || (i==(short)i))? 1: 0;
+ }
+ case TARGET_TYPE_FLOAT: return 1;
+ case TARGET_TYPE_LONG: return 1;
+ case TARGET_TYPE_DOUBLE: return 2;
+ default: return SCORE_WRONG_TYPE;
+ }
+ } else if ( value.isnumber() ) {
+ switch ( targetType ) {
+ case TARGET_TYPE_BYTE: return SCORE_WRONG_TYPE;
+ case TARGET_TYPE_CHAR: return SCORE_WRONG_TYPE;
+ case TARGET_TYPE_SHORT: return SCORE_WRONG_TYPE;
+ case TARGET_TYPE_INT: return SCORE_WRONG_TYPE;
+ case TARGET_TYPE_LONG: {
+ double d = value.todouble();
+ return (d==(long)d)? 0: SCORE_WRONG_TYPE;
+ }
+ case TARGET_TYPE_FLOAT: {
+ double d = value.todouble();
+ return (d==(float)d)? 0: SCORE_WRONG_TYPE;
+ }
+ case TARGET_TYPE_DOUBLE: {
+ double d = value.todouble();
+ return ((d==(long)d) || (d==(float)d))? 1: 0;
+ }
+ default: return SCORE_WRONG_TYPE;
+ }
+ } else {
+ return SCORE_UNCOERCIBLE;
+ }
+ }
+
+ public Object coerce(LuaValue value) {
+ switch ( targetType ) {
+ case TARGET_TYPE_BYTE: return new Byte( (byte) value.toint() );
+ case TARGET_TYPE_CHAR: return new Character( (char) value.toint() );
+ case TARGET_TYPE_SHORT: return new Short( (short) value.toint() );
+ case TARGET_TYPE_INT: return new Integer( (int) value.toint() );
+ case TARGET_TYPE_LONG: return new Long( (long) value.todouble() );
+ case TARGET_TYPE_FLOAT: return new Float( (float) value.todouble() );
+ case TARGET_TYPE_DOUBLE: return new Double( (double) value.todouble() );
+ default: return null;
+ }
+ }
+ }
+
+ static final class StringCoercion implements Coercion {
+ public static final int TARGET_TYPE_STRING = 0;
+ public static final int TARGET_TYPE_BYTES = 1;
+ final int targetType;
+ public StringCoercion(int targetType) {
+ this.targetType = targetType;
+ }
+ public String toString() {
+ return "StringCoercion("+(targetType==TARGET_TYPE_STRING? "String": "byte[]")+")";
+ }
+ public int score(LuaValue value) {
+ switch ( value.type() ) {
+ case LuaValue.TSTRING:
+ return value.checkstring().isValidUtf8()?
+ (targetType==TARGET_TYPE_STRING? 0: 1):
+ (targetType==TARGET_TYPE_BYTES? 0: SCORE_WRONG_TYPE);
+ case LuaValue.TNIL:
+ return SCORE_NULL_VALUE;
+ default:
+ return targetType == TARGET_TYPE_STRING? SCORE_WRONG_TYPE: SCORE_UNCOERCIBLE;
+ }
+ }
+ public Object coerce(LuaValue value) {
+ if ( value.isnil() )
+ return null;
+ if ( targetType == TARGET_TYPE_STRING )
+ return value.tojstring();
+ LuaString s = value.checkstring();
+ byte[] b = new byte[s.m_length];
+ s.copyInto(0, b, 0, b.length);
+ return b;
+ }
+ }
+
+ static final class ArrayCoercion implements Coercion {
+ final Class componentType;
+ final Coercion componentCoercion;
+ public ArrayCoercion(Class componentType) {
+ this.componentType = componentType;
+ this.componentCoercion = getCoercion(componentType);
+ }
+ public String toString() {
+ return "ArrayCoercion("+componentType.getName()+")";
+ }
+ public int score(LuaValue value) {
+ switch ( value.type() ) {
+ case LuaValue.TTABLE:
+ return value.length()==0? 0: componentCoercion.score( value.get(1) );
+ case LuaValue.TUSERDATA:
+ return inheritanceLevels( componentType, value.touserdata().getClass().getComponentType() );
+ case LuaValue.TNIL:
+ return SCORE_NULL_VALUE;
+ default:
+ return SCORE_UNCOERCIBLE;
+ }
+ }
+ public Object coerce(LuaValue value) {
+ switch ( value.type() ) {
+ case LuaValue.TTABLE: {
+ int n = value.length();
+ Object a = Array.newInstance(componentType, n);
+ for ( int i=0; i
+ * This class is not used directly.
+ * It is returned by calls to {@link CoerceJavaToLua#coerce(Object)}
+ * when an array is supplied.
+ * @see CoerceJavaToLua
+ * @see CoerceLuaToJava
+ */
+class JavaArray extends LuaUserdata {
+
+ static final LuaValue LENGTH = valueOf("length");
+
+ JavaArray(Object instance) {
+ super(instance);
+ }
+
+ public LuaValue get(LuaValue key) {
+ if ( key.equals(LENGTH) )
+ return valueOf(Array.getLength(m_instance));
+ if ( key.isint() ) {
+ int i = key.toint() - 1;
+ return i>=0 && i
+ * This class is not used directly.
+ * It is returned by calls to {@link CoerceJavaToLua#coerce(Object)}
+ * when a Class is supplied.
+ * @see CoerceJavaToLua
+ * @see CoerceLuaToJava
+ */
+class JavaClass extends JavaInstance implements CoerceJavaToLua.Coercion {
+
+ static final Map classes = Collections.synchronizedMap(new HashMap());
+
+ static final LuaValue NEW = valueOf("new");
+
+ Map fields;
+ Map methods;
+
+ static JavaClass forClass(Class c) {
+ JavaClass j = (JavaClass) classes.get(c);
+ if ( j == null )
+ classes.put( c, j = new JavaClass(c) );
+ return j;
+ }
+
+ JavaClass(Class c) {
+ super(c);
+ this.jclass = this;
+ }
+
+ public LuaValue coerce(Object javaValue) {
+ return this;
+ }
+
+ Field getField(LuaValue key) {
+ if ( fields == null ) {
+ Map m = new HashMap();
+ Field[] f = ((Class)m_instance).getFields();
+ for ( int i=0; i
+ * This class is not used directly.
+ * It is returned by calls to {@link JavaClass#new(LuaValue key)}
+ * when the value of key is "new".
+ * @see CoerceJavaToLua
+ * @see CoerceLuaToJava
+ */
+class JavaConstructor extends JavaMember {
+
+ static final Map constructors = Collections.synchronizedMap(new HashMap());
+
+ static JavaConstructor forConstructor(Constructor c) {
+ JavaConstructor j = (JavaConstructor) constructors.get(c);
+ if ( j == null )
+ constructors.put( c, j = new JavaConstructor(c) );
+ return j;
+ }
+
+ public static LuaValue forConstructors(JavaConstructor[] array) {
+ return new Overload(array);
+ }
+
+ final Constructor constructor;
+
+ private JavaConstructor(Constructor c) {
+ super( c.getParameterTypes(), c.getModifiers() );
+ this.constructor = c;
+ }
+
+ public Varargs invoke(Varargs args) {
+ Object[] a = convertArgs(args);
+ try {
+ return CoerceJavaToLua.coerce( constructor.newInstance(a) );
+ } catch (InvocationTargetException e) {
+ throw new LuaError(e.getTargetException());
+ } catch (Exception e) {
+ return LuaValue.error("coercion error "+e);
+ }
+ }
+
+ /**
+ * LuaValue that represents an overloaded Java constructor.
+ *
+ * On invocation, will pick the best method from the list, and invoke it.
+ *
+ * This class is not used directly.
+ * It is returned by calls to calls to {@link JavaClass#get(LuaValue key)}
+ * when key is "new" and there is more than one public constructor.
+ */
+ static class Overload extends VarArgFunction {
+ final JavaConstructor[] constructors;
+ public Overload(JavaConstructor[] c) {
+ this.constructors = c;
+ }
+
+ public Varargs invoke(Varargs args) {
+ JavaConstructor best = null;
+ int score = CoerceLuaToJava.SCORE_UNCOERCIBLE;
+ for ( int i=0; i
+ * This class is not used directly.
+ * It is returned by calls to {@link CoerceJavaToLua#coerce(Object)}
+ * when a subclass of Object is supplied.
+ * @see CoerceJavaToLua
+ * @see CoerceLuaToJava
+ */
+class JavaInstance extends LuaUserdata {
+
+ JavaClass jclass;
+
+ JavaInstance(Object instance) {
+ super(instance);
+ }
+
+ public LuaValue get(LuaValue key) {
+ if ( jclass == null )
+ jclass = JavaClass.forClass(m_instance.getClass());
+ Field f = jclass.getField(key);
+ if ( f != null )
+ try {
+ return CoerceJavaToLua.coerce(f.get(m_instance));
+ } catch (Exception e) {
+ throw new LuaError(e);
+ }
+ LuaValue m = jclass.getMethod(key);
+ if ( m != null )
+ return m;
+ return super.get(key);
+ }
+
+ public void set(LuaValue key, LuaValue value) {
+ if ( jclass == null )
+ jclass = JavaClass.forClass(m_instance.getClass());
+ Field f = jclass.getField(key);
+ if ( f != null )
+ try {
+ f.set(m_instance, CoerceLuaToJava.coerce(value, f.getType()));
+ return;
+ } catch (Exception e) {
+ throw new LuaError(e);
+ }
+ super.set(key, value);
+ }
+
+}
diff --git a/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JavaMember.java b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JavaMember.java
new file mode 100644
index 0000000000..e4e9b7ed7f
--- /dev/null
+++ b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JavaMember.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+* Copyright (c) 2011 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.lib.jse;
+
+import org.luaj.vm2.Varargs;
+import org.luaj.vm2.lib.VarArgFunction;
+import org.luaj.vm2.lib.jse.CoerceLuaToJava.Coercion;
+
+/**
+ * Java method or constructor.
+ *
+ * Primarily handles argument coercion for parameter lists including scoring of compatibility and
+ * java varargs handling.
+ *
+ * This class is not used directly.
+ * It is an abstract base class for {@link JavaConstructor} and {@link JavaMethod}.
+ * @see JavaConstructor
+ * @see JavaMethod
+ * @see CoerceJavaToLua
+ * @see CoerceLuaToJava
+ */
+abstract
+class JavaMember extends VarArgFunction {
+
+ static final int METHOD_MODIFIERS_VARARGS = 0x80;
+
+ final Coercion[] fixedargs;
+ final Coercion varargs;
+
+ protected JavaMember(Class[] params, int modifiers) {
+ boolean isvarargs = ((modifiers & METHOD_MODIFIERS_VARARGS) != 0);
+ fixedargs = new CoerceLuaToJava.Coercion[isvarargs? params.length-1: params.length];
+ for ( int i=0; i
+ * This class is not used directly.
+ * It is returned by calls to calls to {@link JavaInstance#get(LuaValue key)}
+ * when a method is named.
+ * @see CoerceJavaToLua
+ * @see CoerceLuaToJava
+ */
+class JavaMethod extends JavaMember {
+
+ static final Map methods = Collections.synchronizedMap(new HashMap());
+
+ static JavaMethod forMethod(Method m) {
+ JavaMethod j = (JavaMethod) methods.get(m);
+ if ( j == null )
+ methods.put( m, j = new JavaMethod(m) );
+ return j;
+ }
+
+ static LuaFunction forMethods(JavaMethod[] m) {
+ return new Overload(m);
+ }
+
+ final Method method;
+
+ private JavaMethod(Method m) {
+ super( m.getParameterTypes(), m.getModifiers() );
+ this.method = m;
+ try {
+ if (!m.isAccessible())
+ m.setAccessible(true);
+ } catch (SecurityException s) {
+ }
+ }
+
+ public LuaValue call() {
+ return error("method cannot be called without instance");
+ }
+
+ public LuaValue call(LuaValue arg) {
+ return invokeMethod(arg.checkuserdata(), LuaValue.NONE);
+ }
+
+ public LuaValue call(LuaValue arg1, LuaValue arg2) {
+ return invokeMethod(arg1.checkuserdata(), arg2);
+ }
+
+ public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
+ return invokeMethod(arg1.checkuserdata(), LuaValue.varargsOf(arg2, arg3));
+ }
+
+ public Varargs invoke(Varargs args) {
+ return invokeMethod(args.checkuserdata(1), args.subargs(2));
+ }
+
+ LuaValue invokeMethod(Object instance, Varargs args) {
+ Object[] a = convertArgs(args);
+ try {
+ return CoerceJavaToLua.coerce( method.invoke(instance, a) );
+ } catch (InvocationTargetException e) {
+ throw new LuaError(e.getTargetException());
+ } catch (Exception e) {
+ return LuaValue.error("coercion error "+e);
+ }
+ }
+
+ /**
+ * LuaValue that represents an overloaded Java method.
+ *
+ * On invocation, will pick the best method from the list, and invoke it.
+ *
+ * This class is not used directly.
+ * It is returned by calls to calls to {@link JavaInstance#get(LuaValue key)}
+ * when an overloaded method is named.
+ */
+ static class Overload extends LuaFunction {
+
+ final JavaMethod[] methods;
+
+ Overload(JavaMethod[] methods) {
+ this.methods = methods;
+ }
+
+ public LuaValue call() {
+ return error("method cannot be called without instance");
+ }
+
+ public LuaValue call(LuaValue arg) {
+ return invokeBestMethod(arg.checkuserdata(), LuaValue.NONE);
+ }
+
+ public LuaValue call(LuaValue arg1, LuaValue arg2) {
+ return invokeBestMethod(arg1.checkuserdata(), arg2);
+ }
+
+ public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
+ return invokeBestMethod(arg1.checkuserdata(), LuaValue.varargsOf(arg2, arg3));
+ }
+
+ public Varargs invoke(Varargs args) {
+ return invokeBestMethod(args.checkuserdata(1), args.subargs(2));
+ }
+
+ private LuaValue invokeBestMethod(Object instance, Varargs args) {
+ JavaMethod best = null;
+ int score = CoerceLuaToJava.SCORE_UNCOERCIBLE;
+ for ( int i=0; i
+ * Typically, this library is included as part of a call to
+ * {@link JsePlatform#standardGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * This is a direct port of the corresponding library in C.
+ * @see BaseLib
+ * @see ResourceFinder
+ * @see #FINDER
+ * @see LibFunction
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see http://www.lua.org/manual/5.1/manual.html#5.1
+ */
+
+public class JseBaseLib extends org.luaj.vm2.lib.BaseLib {
+
+ /** Construct a JSE base library instance */
+ public JseBaseLib() {
+ STDIN = System.in;
+ }
+
+ /**
+ * Try to open a file in the current working directory,
+ * or fall back to base opener if not found.
+ *
+ * This implementation attempts to open the file using new File(filename).
+ * It falls back to the base implementation that looks it up as a resource
+ * in the class path if not found as a plain file.
+ *
+ * @see org.luaj.vm2.lib.BaseLib
+ * @see org.luaj.vm2.lib.ResourceFinder
+ *
+ * @param filename
+ * @return InputStream, or null if not found.
+ */
+ public InputStream findResource(String filename) {
+ File f = new File(filename);
+ if ( ! f.exists() )
+ return super.findResource(filename);
+ try {
+ return new FileInputStream(f);
+ } catch ( IOException ioe ) {
+ return null;
+ }
+ }
+}
diff --git a/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JseIoLib.java b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JseIoLib.java
new file mode 100644
index 0000000000..8a86ca8fa3
--- /dev/null
+++ b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JseIoLib.java
@@ -0,0 +1,222 @@
+/*******************************************************************************
+* 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.lib.jse;
+
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.RandomAccessFile;
+
+import org.luaj.vm2.LuaError;
+import org.luaj.vm2.LuaString;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.lib.BaseLib;
+import org.luaj.vm2.lib.IoLib;
+import org.luaj.vm2.lib.LibFunction;
+
+/**
+ * Subclass of {@link IoLib} and therefore {@link LibFunction} which implements the lua standard {@code io}
+ * library for the JSE platform.
+ *
+ * It uses RandomAccessFile to implement seek on files.
+ *
+ * Typically, this library is included as part of a call to
+ * {@link JsePlatform#standardGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * This has been implemented to match as closely as possible the behavior in the corresponding library in C.
+ * @see LibFunction
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see IoLib
+ * @see JmeIoLib
+ * @see http://www.lua.org/manual/5.1/manual.html#5.7
+ */
+public class JseIoLib extends IoLib {
+
+ public JseIoLib() {
+ super();
+ }
+
+ protected File wrapStdin() throws IOException {
+ return new FileImpl(BaseLib.instance.STDIN);
+ }
+
+ protected File wrapStdout() throws IOException {
+ return new FileImpl(BaseLib.instance.STDOUT);
+ }
+
+ protected File openFile( String filename, boolean readMode, boolean appendMode, boolean updateMode, boolean binaryMode ) throws IOException {
+ RandomAccessFile f = new RandomAccessFile(filename,readMode? "r": "rw");
+ if ( appendMode ) {
+ f.seek(f.length());
+ } else {
+ if ( ! readMode )
+ f.setLength(0);
+ }
+ return new FileImpl( f );
+ }
+
+ protected File openProgram(String prog, String mode) throws IOException {
+ final Process p = Runtime.getRuntime().exec(prog);
+ return "w".equals(mode)?
+ new FileImpl( p.getOutputStream() ):
+ new FileImpl( p.getInputStream() );
+ }
+
+ protected File tmpFile() throws IOException {
+ java.io.File f = java.io.File.createTempFile(".luaj","bin");
+ f.deleteOnExit();
+ return new FileImpl( new RandomAccessFile(f,"rw") );
+ }
+
+ private static void notimplemented() {
+ throw new LuaError("not implemented");
+ }
+
+ private final class FileImpl extends File {
+ private final RandomAccessFile file;
+ private final InputStream is;
+ private final OutputStream os;
+ private boolean closed = false;
+ private boolean nobuffer = false;
+ private FileImpl( RandomAccessFile file, InputStream is, OutputStream os ) {
+ this.file = file;
+ this.is = is!=null? is.markSupported()? is: new BufferedInputStream(is): null;
+ this.os = os;
+ }
+ private FileImpl( RandomAccessFile f ) {
+ this( f, null, null );
+ }
+ private FileImpl( InputStream i ) {
+ this( null, i, null );
+ }
+ private FileImpl( OutputStream o ) {
+ this( null, null, o );
+ }
+ public String tojstring() {
+ return "file ("+this.hashCode()+")";
+ }
+ public boolean isstdfile() {
+ return file == null;
+ }
+ public void close() throws IOException {
+ closed = true;
+ if ( file != null ) {
+ file.close();
+ }
+ }
+ public void flush() throws IOException {
+ if ( os != null )
+ os.flush();
+ }
+ public void write(LuaString s) throws IOException {
+ if ( os != null )
+ os.write( s.m_bytes, s.m_offset, s.m_length );
+ else if ( file != null )
+ file.write( s.m_bytes, s.m_offset, s.m_length );
+ else
+ notimplemented();
+ if ( nobuffer )
+ flush();
+ }
+ public boolean isclosed() {
+ return closed;
+ }
+ public int seek(String option, int pos) throws IOException {
+ if ( file != null ) {
+ if ( "set".equals(option) ) {
+ file.seek(pos);
+ } else if ( "end".equals(option) ) {
+ file.seek(file.length()+pos);
+ } else {
+ file.seek(file.getFilePointer()+pos);
+ }
+ return (int) file.getFilePointer();
+ }
+ notimplemented();
+ return 0;
+ }
+ public void setvbuf(String mode, int size) {
+ nobuffer = "no".equals(mode);
+ }
+
+ // get length remaining to read
+ public int remaining() throws IOException {
+ return file!=null? (int) (file.length()-file.getFilePointer()): -1;
+ }
+
+ // peek ahead one character
+ public int peek() throws IOException {
+ if ( is != null ) {
+ is.mark(1);
+ int c = is.read();
+ is.reset();
+ return c;
+ } else if ( file != null ) {
+ long fp = file.getFilePointer();
+ int c = file.read();
+ file.seek(fp);
+ return c;
+ }
+ notimplemented();
+ return 0;
+ }
+
+ // return char if read, -1 if eof, throw IOException on other exception
+ public int read() throws IOException {
+ if ( is != null )
+ return is.read();
+ else if ( file != null ) {
+ return file.read();
+ }
+ notimplemented();
+ return 0;
+ }
+
+ // return number of bytes read if positive, -1 if eof, throws IOException
+ public int read(byte[] bytes, int offset, int length) throws IOException {
+ if (file!=null) {
+ return file.read(bytes, offset, length);
+ } else if (is!=null) {
+ return is.read(bytes, offset, length);
+ } else {
+ notimplemented();
+ }
+ return length;
+ }
+ }
+}
diff --git a/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JseMathLib.java b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JseMathLib.java
new file mode 100644
index 0000000000..1f8d2e6957
--- /dev/null
+++ b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JseMathLib.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+* Copyright (c) 2009-2011 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.lib.jse;
+
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.lib.LibFunction;
+import org.luaj.vm2.lib.OneArgFunction;
+import org.luaj.vm2.lib.TwoArgFunction;
+
+/**
+ * Subclass of {@link LibFunction} which implements the lua standard {@code math}
+ * library.
+ *
+ * It contains all lua math functions, including those not available on the JME platform.
+ * See {@link org.luaj.lib.MathLib} for the exception list.
+ *
+ * Typically, this library is included as part of a call to
+ * {@link JsePlatform#standardGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * This has been implemented to match as closely as possible the behavior in the corresponding library in C.
+ * @see LibFunction
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see JseMathLib
+ * @see http://www.lua.org/manual/5.1/manual.html#5.6
+ */
+public class JseMathLib extends org.luaj.vm2.lib.MathLib {
+
+ public JseMathLib() {}
+
+ public LuaValue call(LuaValue arg) {
+ LuaValue t = super.call(arg);
+ bind( t, JseMathLib1.class, new String[] {
+ "acos", "asin", "atan", "cosh",
+ "exp", "log", "log10", "sinh",
+ "tanh" } );
+ bind( t, JseMathLib2.class, new String[] {
+ "atan2", "pow", } );
+ return t;
+ }
+
+ public static final class JseMathLib1 extends OneArgFunction {
+ public LuaValue call(LuaValue arg) {
+ switch ( opcode ) {
+ case 0: return valueOf(Math.acos(arg.checkdouble()));
+ case 1: return valueOf(Math.asin(arg.checkdouble()));
+ case 2: return valueOf(Math.atan(arg.checkdouble()));
+ case 3: return valueOf(Math.cosh(arg.checkdouble()));
+ case 4: return valueOf(Math.exp(arg.checkdouble()));
+ case 5: return valueOf(Math.log(arg.checkdouble()));
+ case 6: return valueOf(Math.log10(arg.checkdouble()));
+ case 7: return valueOf(Math.sinh(arg.checkdouble()));
+ case 8: return valueOf(Math.tanh(arg.checkdouble()));
+ }
+ return NIL;
+ }
+ }
+
+ public static final class JseMathLib2 extends TwoArgFunction {
+ public LuaValue call(LuaValue arg1, LuaValue arg2) {
+ switch ( opcode ) {
+ case 0: return valueOf(Math.atan2(arg1.checkdouble(), arg2.checkdouble()));
+ case 1: return valueOf(Math.pow(arg1.checkdouble(), arg2.checkdouble()));
+ }
+ return NIL;
+ }
+ }
+
+ /** Faster, better version of pow() used by arithmetic operator ^ */
+ public double dpow_lib(double a, double b) {
+ return Math.pow(a, b);
+ }
+
+
+}
diff --git a/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JseOsLib.java b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JseOsLib.java
new file mode 100644
index 0000000000..9952cd1c73
--- /dev/null
+++ b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JseOsLib.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+* 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.lib.jse;
+import java.io.File;
+import java.io.IOException;
+
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.lib.LibFunction;
+
+/**
+ * Subclass of {@link LibFunction} which implements the standard lua {@code os} library.
+ *
+ * This contains more complete implementations of the following functions
+ * using features that are specific to JSE:
+ *
+ * Because the nature of the {@code os} library is to encapsulate
+ * os-specific features, the behavior of these functions varies considerably
+ * from their counterparts in the C platform.
+ *
+ * Typically, this library is included as part of a call to either
+ * {@link JsePlatform#standardGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * @see LibFunction
+ * @see OsLib
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see http://www.lua.org/manual/5.1/manual.html#5.8
+ */
+public class JseOsLib extends org.luaj.vm2.lib.OsLib {
+
+ /** return code indicating the execute() threw an I/O exception */
+ public static int EXEC_IOEXCEPTION = 1;
+
+ /** return code indicating the execute() was interrupted */
+ public static int EXEC_INTERRUPTED = -2;
+
+ /** return code indicating the execute() threw an unknown exception */
+ public static int EXEC_ERROR = -3;
+
+ /** public constructor */
+ public JseOsLib() {
+ }
+
+ protected int execute(String command) {
+ Runtime r = Runtime.getRuntime();
+ try {
+ final Process p = r.exec(command);
+ try {
+ p.waitFor();
+ return p.exitValue();
+ } finally {
+ p.destroy();
+ }
+ } catch (IOException ioe) {
+ return EXEC_IOEXCEPTION;
+ } catch (InterruptedException e) {
+ return EXEC_INTERRUPTED;
+ } catch (Throwable t) {
+ return EXEC_ERROR;
+ }
+ }
+
+ protected void remove(String filename) throws IOException {
+ File f = new File(filename);
+ if ( ! f.exists() )
+ throw new IOException("No such file or directory");
+ if ( ! f.delete() )
+ throw new IOException("Failed to delete");
+ }
+
+ protected void rename(String oldname, String newname) throws IOException {
+ File f = new File(oldname);
+ if ( ! f.exists() )
+ throw new IOException("No such file or directory");
+ if ( ! f.renameTo(new File(newname)) )
+ throw new IOException("Failed to delete");
+ }
+
+ protected String tmpname() {
+ try {
+ java.io.File f = java.io.File.createTempFile(TMP_PREFIX ,TMP_SUFFIX);
+ return f.getName();
+ } catch ( IOException ioe ) {
+ return super.tmpname();
+ }
+ }
+
+}
diff --git a/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JsePlatform.java b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JsePlatform.java
new file mode 100644
index 0000000000..7008280e59
--- /dev/null
+++ b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JsePlatform.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2009-2011 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.lib.jse;
+
+import org.luaj.vm2.compiler.LuaC;
+import org.luaj.vm2.LuaTable;
+import org.luaj.vm2.LuaThread;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.lib.CoroutineLib;
+import org.luaj.vm2.lib.DebugLib;
+import org.luaj.vm2.lib.PackageLib;
+import org.luaj.vm2.lib.StringLib;
+import org.luaj.vm2.lib.TableLib;
+
+/** The {@link JsePlatform} class is a convenience class to standardize
+ * how globals tables are initialized for the JSE platform.
+ *
+ * It is used to allocate either a set of standard globals using
+ * {@link #standardGlobals()} or debug globals using {@link #debugGlobals()}
+ *
+ * A simple example of initializing globals and using them from Java is:
+ *
+ * Once globals are created, a simple way to load and run a script is:
+ *
+ * although {@code require} could also be used:
+ *
+ * The standard globals will contain all standard libraries plus {@code luajava}:
+ *
+ * The debug globals are simply the standard globals plus the {@code debug} library {@link DebugLib}.
+ *
+ * The class ensures that initialization is done in the correct order,
+ * and that linkage is made to {@link LuaThread#setGlobals(LuaValue)}.
+ * @see JmePlatform
+ */
+public class JsePlatform {
+
+ /**
+ * Create a standard set of globals for JSE including all the libraries.
+ *
+ * @return Table of globals initialized with the standard JSE libraries
+ * @see #debugGlobals()
+ * @see JsePlatform
+ * @see JmePlatform
+ */
+ public static LuaTable standardGlobals() {
+ LuaTable _G = new LuaTable();
+ _G.load(new JseBaseLib());
+ _G.load(new PackageLib());
+ _G.load(new TableLib());
+ _G.load(new StringLib());
+ _G.load(new CoroutineLib());
+ _G.load(new JseMathLib());
+ _G.load(new JseIoLib());
+ _G.load(new JseOsLib());
+ _G.load(new LuajavaLib());
+ LuaThread.setGlobals(_G);
+ LuaC.install();
+ return _G;
+ }
+
+ /** Create standard globals including the {@link debug} library.
+ *
+ * @return Table of globals initialized with the standard JSE and debug libraries
+ * @see #standardGlobals()
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see DebugLib
+ */
+ public static LuaTable debugGlobals() {
+ LuaTable _G = standardGlobals();
+ _G.load(new DebugLib());
+ return _G;
+ }
+}
diff --git a/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JseProcess.java b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JseProcess.java
new file mode 100644
index 0000000000..c24b6d587c
--- /dev/null
+++ b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/JseProcess.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+* Copyright (c) 2013 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.lib.jse;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/** Analog of Process that pipes input and output to client-specified streams.
+ */
+public class JseProcess {
+
+ final Process process;
+ final Thread input,output,error;
+
+ /** Construct a process around a command, with specified streams to redirect input and output to.
+ *
+ * @param cmd The command to execute, including arguments, if any
+ * @param stdin Optional InputStream to read from as process input, or null if input is not needed.
+ * @param stdout Optional OutputStream to copy process output to, or null if output is ignored.
+ * @param stderr Optinoal OutputStream to copy process stderr output to, or null if output is ignored.
+ * @throws IOException If the system process could not be created.
+ * @see Process
+ */
+ public JseProcess(String[] cmd, InputStream stdin, OutputStream stdout, OutputStream stderr) throws IOException {
+ this(Runtime.getRuntime().exec(cmd), stdin, stdout, stderr);
+ }
+
+ /** Construct a process around a command, with specified streams to redirect input and output to.
+ *
+ * @param cmd The command to execute, including arguments, if any
+ * @param stdin Optional InputStream to read from as process input, or null if input is not needed.
+ * @param stdout Optional OutputStream to copy process output to, or null if output is ignored.
+ * @param stderr Optinoal OutputStream to copy process stderr output to, or null if output is ignored.
+ * @throws IOException If the system process could not be created.
+ * @see Process
+ */
+ public JseProcess(String cmd, InputStream stdin, OutputStream stdout, OutputStream stderr) throws IOException {
+ this(Runtime.getRuntime().exec(cmd), stdin, stdout, stderr);
+ }
+
+ private JseProcess(Process process, InputStream stdin, OutputStream stdout, OutputStream stderr) {
+ this.process = process;
+ input = stdin == null? null: copyBytes(stdin, process.getOutputStream(), null, process.getOutputStream());
+ output = stdout == null? null: copyBytes(process.getInputStream(), stdout, process.getInputStream(), null);
+ error = stderr == null? null: copyBytes(process.getErrorStream(), stderr, process.getErrorStream(), null);
+ }
+
+ /** Get the exit value of the process. */
+ public int exitValue() {
+ return process.exitValue();
+ }
+
+ /** Wait for the process to complete, and all pending output to finish.
+ * @return The exit status.
+ * @throws InterruptedException
+ */
+ public int waitFor() throws InterruptedException {
+ int r = process.waitFor();
+ if (input != null)
+ input.join();
+ if (output != null)
+ output.join();
+ if (error != null)
+ error.join();
+ process.destroy();
+ return r;
+ }
+
+ /** Create a thread to copy bytes from input to output. */
+ private Thread copyBytes(final InputStream input,
+ final OutputStream output, final InputStream ownedInput,
+ final OutputStream ownedOutput) {
+ Thread t = (new Thread() {
+ public void run() {
+ try {
+ byte[] buf = new byte[1024];
+ int r;
+ try {
+ while ((r = input.read(buf)) >= 0) {
+ output.write(buf, 0, r);
+ }
+ } finally {
+ if (ownedInput != null)
+ ownedInput.close();
+ if (ownedOutput != null)
+ ownedOutput.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ t.start();
+ return t;
+ }
+}
diff --git a/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/LuajavaLib.java b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/LuajavaLib.java
new file mode 100644
index 0000000000..47de379260
--- /dev/null
+++ b/luaj-2.0.3/src/jse/org/luaj/vm2/lib/jse/LuajavaLib.java
@@ -0,0 +1,195 @@
+/*******************************************************************************
+* 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.lib.jse;
+
+
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.luaj.vm2.LuaError;
+import org.luaj.vm2.LuaTable;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.Varargs;
+import org.luaj.vm2.compiler.LuaC;
+import org.luaj.vm2.lib.LibFunction;
+import org.luaj.vm2.lib.PackageLib;
+import org.luaj.vm2.lib.VarArgFunction;
+
+/**
+ * Subclass of {@link LibFunction} which implements the features of the luajava package.
+ *
+ * Luajava is an approach to mixing lua and java using simple functions that bind
+ * java classes and methods to lua dynamically. The API is documented on the
+ * luajava documentation pages.
+ *
+ * Typically, this library is included as part of a call to either
+ * {@link JsePlatform#standardGlobals()}
+ *
+ * To instantiate and use it directly,
+ * link it into your globals table via {@link LuaValue#load(LuaValue)} using code such as:
+ *
+ * This has been implemented to match as closely as possible the behavior in the corresponding library in C.
+ * @see LibFunction
+ * @see org.luaj.vm2.lib.jse.JsePlatform
+ * @see org.luaj.vm2.lib.jme.JmePlatform
+ * @see LuaC
+ * @see http://www.keplerproject.org/luajava/manual.html#luareference
+ */
+public class LuajavaLib extends VarArgFunction {
+
+ static final int INIT = 0;
+ static final int BINDCLASS = 1;
+ static final int NEWINSTANCE = 2;
+ static final int NEW = 3;
+ static final int CREATEPROXY = 4;
+ static final int LOADLIB = 5;
+
+ static final String[] NAMES = {
+ "bindClass",
+ "newInstance",
+ "new",
+ "createProxy",
+ "loadLib",
+ };
+
+ static final int METHOD_MODIFIERS_VARARGS = 0x80;
+
+ public LuajavaLib() {
+ }
+
+ public Varargs invoke(Varargs args) {
+ try {
+ switch ( opcode ) {
+ case INIT: {
+ LuaTable t = new LuaTable();
+ bind( t, LuajavaLib.class, NAMES, BINDCLASS );
+ env.set("luajava", t);
+ PackageLib.instance.LOADED.set("luajava", t);
+ return t;
+ }
+ case BINDCLASS: {
+ final Class clazz = classForName(args.checkjstring(1));
+ return JavaClass.forClass(clazz);
+ }
+ case NEWINSTANCE:
+ case NEW: {
+ // get constructor
+ final LuaValue c = args.checkvalue(1);
+ final Class clazz = (opcode==NEWINSTANCE? classForName(c.tojstring()): (Class) c.checkuserdata(Class.class));
+ final Varargs consargs = args.subargs(2);
+ return JavaClass.forClass(clazz).getConstructor().invoke(consargs);
+ }
+
+ case CREATEPROXY: {
+ final int niface = args.narg()-1;
+ if ( niface <= 0 )
+ throw new LuaError("no interfaces");
+ final LuaValue lobj = args.checktable(niface+1);
+
+ // get the interfaces
+ final Class[] ifaces = new Class[niface];
+ for ( int i=0; i {@code
+* LuaValue _G = JsePlatform.standardGlobals();
+* LoadState.load( new FileInputStream("main.lua"), "main.lua", _G ).call();
+* }
+* This should work regardless of which {@link LuaCompiler}
+* has been installed.
+* {@code
+* LuaValue _G = JsePlatform.standardGlobals();
+* LuaJC.install();
+* LoadState.load( new FileInputStream("main.lua"), "main.lua", _G ).call();
+* }
+*
+* @see LuaCompiler
+* @see LuaClosure
+* @see LuaFunction
+* @see LoadState#compiler
+* @see LoadState#load(InputStream, String, LuaValue)
+* @see LuaC
+* @see LuaJC
+*/
+public class LoadState {
+
+ /** format corresponding to non-number-patched lua, all numbers are floats or doubles */
+ public static final int NUMBER_FORMAT_FLOATS_OR_DOUBLES = 0;
+
+ /** format corresponding to non-number-patched lua, all numbers are ints */
+ public static final int NUMBER_FORMAT_INTS_ONLY = 1;
+
+ /** format corresponding to number-patched lua, all numbers are 32-bit (4 byte) ints */
+ public static final int NUMBER_FORMAT_NUM_PATCH_INT32 = 4;
+
+ // type constants
+ public static final int LUA_TINT = (-2);
+ public static final int LUA_TNONE = (-1);
+ public static final int LUA_TNIL = 0;
+ public static final int LUA_TBOOLEAN = 1;
+ public static final int LUA_TLIGHTUSERDATA = 2;
+ public static final int LUA_TNUMBER = 3;
+ public static final int LUA_TSTRING = 4;
+ public static final int LUA_TTABLE = 5;
+ public static final int LUA_TFUNCTION = 6;
+ public static final int LUA_TUSERDATA = 7;
+ public static final int LUA_TTHREAD = 8;
+ public static final int LUA_TVALUE = 9;
+
+ /** Interface for the compiler, if it is installed.
+ *
+ *
+ * {@code
+ * InputStream is = new ByteArrayInputStream("print('hello,world').getBytes());
+ * Prototype p = LuaC.instance.compile(is, "script");
+ * LuaValue _G = JsePlatform.standardGlobals()
+ * LuaClosure f = new LuaClosure(p, _G);
+ * }
+ * {@code
+ * LuaFunction f = LuaC.instance.load(is, "script", _G);
+ * }
+ * {@code
+ * LuaValue r = f.call();
+ * _G.set( "mypkg", r )
+ * }
+ *
+ *
+ * @see LuaValue
+ * @see LuaFunction
+ * @see LuaValue#isclosure()
+ * @see LuaValue#checkclosure()
+ * @see LuaValue#optclosure(LuaClosure)
+ * @see LoadState
+ * @see LoadState#compiler
+ */
+public class LuaClosure extends LuaFunction {
+ private static final UpValue[] NOUPVALUES = new UpValue[0];
+
+ public final Prototype p;
+ public final UpValue[] upValues;
+
+ LuaClosure() {
+ p = null;
+ upValues = null;
+ }
+ /** Supply the initial environment */
+ public LuaClosure(Prototype p, LuaValue env) {
+ super( env );
+ this.p = p;
+ this.upValues = p.nups>0? new UpValue[p.nups]: NOUPVALUES;
+ }
+
+ protected LuaClosure(int nupvalues, LuaValue env) {
+ super( env );
+ this.p = null;
+ this.upValues = nupvalues>0? new UpValue[nupvalues]: NOUPVALUES;
+ }
+
+ public boolean isclosure() {
+ return true;
+ }
+
+ public LuaClosure optclosure(LuaClosure defval) {
+ return this;
+ }
+
+ public LuaClosure checkclosure() {
+ return this;
+ }
+
+ public LuaValue getmetatable() {
+ return s_metatable;
+ }
+
+ public final LuaValue call() {
+ LuaValue[] stack = new LuaValue[p.maxstacksize];
+ System.arraycopy(NILS, 0, stack, 0, p.maxstacksize);
+ return execute(stack,NONE).arg1();
+ }
+
+ public final LuaValue call(LuaValue arg) {
+ LuaValue[] stack = new LuaValue[p.maxstacksize];
+ System.arraycopy(NILS, 0, stack, 0, p.maxstacksize);
+ switch ( p.numparams ) {
+ default: stack[0]=arg; return execute(stack,NONE).arg1();
+ case 0: return execute(stack,arg).arg1();
+ }
+ }
+
+ public final LuaValue call(LuaValue arg1, LuaValue arg2) {
+ LuaValue[] stack = new LuaValue[p.maxstacksize];
+ System.arraycopy(NILS, 0, stack, 0, p.maxstacksize);
+ switch ( p.numparams ) {
+ default: stack[0]=arg1; stack[1]=arg2; return execute(stack,NONE).arg1();
+ case 1: stack[0]=arg1; return execute(stack,arg2).arg1();
+ case 0: return execute(stack,p.is_vararg!=0? varargsOf(arg1,arg2): NONE).arg1();
+ }
+ }
+
+ public final LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) {
+ LuaValue[] stack = new LuaValue[p.maxstacksize];
+ System.arraycopy(NILS, 0, stack, 0, p.maxstacksize);
+ switch ( p.numparams ) {
+ default: stack[0]=arg1; stack[1]=arg2; stack[2]=arg3; return execute(stack,NONE).arg1();
+ case 2: stack[0]=arg1; stack[1]=arg2; return execute(stack,arg3).arg1();
+ case 1: stack[0]=arg1; return execute(stack,p.is_vararg!=0? varargsOf(arg2,arg3): NONE).arg1();
+ case 0: return execute(stack,p.is_vararg!=0? varargsOf(arg1,arg2,arg3): NONE).arg1();
+ }
+ }
+
+ public final Varargs invoke(Varargs varargs) {
+ return onInvoke( varargs ).eval();
+ }
+
+ public Varargs onInvoke(Varargs varargs) {
+ LuaValue[] stack = new LuaValue[p.maxstacksize];
+ System.arraycopy(NILS, 0, stack, 0, p.maxstacksize);
+ for ( int i=0; i
+ *
+ *
+ *
+ * {@code
+ * LuaValue k = LuaValue.NIL;
+ * while ( true ) {
+ * Varargs n = table.next(k);
+ * if ( (k = n.arg1()).isnil() )
+ * break;
+ * LuaValue v = n.arg(2)
+ * process( k, v )
+ * }}
+ *
+ *
+ *
+ * @see LuaValue
+ */
+public class LuaTable extends LuaValue {
+ private static final int MIN_HASH_CAPACITY = 2;
+ private static final LuaString N = valueOf("n");
+
+ /** the array values */
+ protected LuaValue[] array;
+
+ /** the hash keys */
+ protected LuaValue[] hashKeys;
+
+ /** the hash values */
+ protected LuaValue[] hashValues;
+
+ /** the number of hash entries */
+ protected int hashEntries;
+
+ /** metatable for this table, or null */
+ protected LuaValue m_metatable;
+
+ /** Construct empty table */
+ public LuaTable() {
+ array = NOVALS;
+ hashKeys = NOVALS;
+ hashValues = NOVALS;
+ }
+
+ /**
+ * Construct table with preset capacity.
+ * @param narray capacity of array part
+ * @param nhash capacity of hash part
+ */
+ public LuaTable(int narray, int nhash) {
+ presize(narray, nhash);
+ }
+
+ /**
+ * Construct table with named and unnamed parts.
+ * @param named Named elements in order {@code key-a, value-a, key-b, value-b, ... }
+ * @param unnamed Unnamed elements in order {@code value-1, value-2, ... }
+ * @param lastarg Additional unnamed values beyond {@code unnamed.length}
+ */
+ public LuaTable(LuaValue[] named, LuaValue[] unnamed, Varargs lastarg) {
+ int nn = (named!=null? named.length: 0);
+ int nu = (unnamed!=null? unnamed.length: 0);
+ int nl = (lastarg!=null? lastarg.narg(): 0);
+ presize(nu+nl, nn-(nn>>1));
+ for ( int i=0; i {@code
+ * LuaValue a = LuaValue.valueOf( 5 );
+ * LuaValue b = LuaValue.valueOf( 4 );
+ * LuaValue c = a.div(b);
+ * }
+ * Note that in this example, c will be a {@link LuaDouble}, but would be a {@link LuaInteger}
+ * if the value of a were changed to 8, say.
+ * In general the value of c in practice will vary depending on both the types and values of a and b
+ * as well as any metatable/metatag processing that occurs.
+ * {@code
+ * LuaValue globals = JsePlatform.standardGlobals();
+ * LuaValue sqrt = globals.get("math").get("sqrt");
+ * LuaValue print = globals.get("print");
+ * LuaValue d = sqrt.call( a );
+ * print.call( LuaValue.valueOf("sqrt(5):"), a );
+ * }
+ * {@code
+ * LuaValue modf = globals.get("math").get("modf");
+ * Varargs r = modf.invoke( d );
+ * print.call( r.arg(1), r.arg(2) );
+ * }
+ * {@code
+ * LoadState.load( new FileInputStream("main.lua"), "main.lua", globals ).call();
+ * }
+ * {@code
+ * globals.get("require").call(LuaValue.valueOf("main"));
+ * }
+ * For this to work the file must be in the current directory, or in the class path,
+ * dependening on the platform.
+ * See {@link JsePlatform} and {@link JmePlatform} for details.
+ *
+ *
+ * {@code
+ * LuaValue k = LuaValue.NIL;
+ * while ( true ) {
+ * Varargs n = table.next(k);
+ * if ( (k = n.arg1()).isnil() )
+ * break;
+ * LuaValue v = n.arg(2)
+ * process( k, v )
+ * }}
+ * @param index {@link LuaInteger} value identifying a key to start from,
+ * or {@link NIL} to start at the beginning
+ * @return {@link Varargs} containing {key,value} for the next entry,
+ * or {@link NIL} if there are no more.
+ * @throws LuaError if {@code this} is not a table, or the supplied key is invalid.
+ * @see LuaTable
+ * @see #inext()
+ * @see #valueOf(int)
+ * @see Varargs#arg1()
+ * @see Varargs#arg(int)
+ * @see #isnil()
+ */
+ public Varargs next(LuaValue index) { return typerror("table"); }
+
+ /** Find the next integer-key,value pair if {@code this} is a table,
+ * return {@link NIL} if there are no more, or throw a {@link LuaError} if not a table.
+ * {@code
+ * LuaValue k = LuaValue.NIL;
+ * while ( true ) {
+ * Varargs n = table.inext(k);
+ * if ( (k = n.arg1()).isnil() )
+ * break;
+ * LuaValue v = n.arg(2)
+ * process( k, v )
+ * }
+ * }
+ * @param index {@link LuaInteger} value identifying a key to start from,
+ * or {@link NIL} to start at the beginning
+ * @return {@link Varargs} containing {@code (key,value)} for the next entry,
+ * or {@link NONE} if there are no more.
+ * @throws LuaError if {@code this} is not a table, or the supplied key is invalid.
+ * @see LuaTable
+ * @see #next()
+ * @see #valueOf(int)
+ * @see Varargs#arg1()
+ * @see Varargs#arg(int)
+ * @see #isnil()
+ */
+ public Varargs inext(LuaValue index) { return typerror("table"); }
+
+ /**
+ * Load a library instance by setting its environment to {@code this}
+ * and calling it, which should iniitalize the library instance and
+ * install itself into this instance.
+ * @param library The callable {@link LuaValue} to load into {@code this}
+ * @return {@link LuaValue} containing the result of the initialization call.
+ */
+ public LuaValue load(LuaValue library) { library.setfenv(this); return library.call(); }
+
+ // varargs references
+ public LuaValue arg(int index) { return index==1? this: NIL; }
+ public int narg() { return 1; };
+ public LuaValue arg1() { return this; }
+
+ /**
+ * Get the metatable for this {@link LuaValue}
+ * {@code
+ * LuaValue _G = JsePlatform.standardGlobals();
+ * LoadState.load( new ByteArrayInputStream("print 'hello'".getBytes()), "main.lua", _G ).call();
+ * }
+ * @see LuaCompiler
+ * @see LuaJC
+ * @see JsePlatform
+ * @see JmePlatform
+ * @see BaseLib
+ * @see LuaValue
+ * @see LuaCompiler
+ * @see Prototype
+ */
+public class LuaC extends Lua implements LuaCompiler {
+
+ public static final LuaC instance = new LuaC();
+
+ /** Install the compiler so that LoadState will first
+ * try to use it when handed bytes that are
+ * not already a compiled lua chunk.
+ */
+ public static void install() {
+ org.luaj.vm2.LoadState.compiler = instance;
+ }
+
+ protected static void _assert(boolean b) {
+ if (!b)
+ throw new LuaError("compiler assert failed");
+ }
+
+ public static final int MAXSTACK = 250;
+ static final int LUAI_MAXUPVALUES = 60;
+ static final int LUAI_MAXVARS = 200;
+ static final int NO_REG = MAXARG_A;
+
+
+ /* OpMode - basic instruction format */
+ static final int
+ iABC = 0,
+ iABx = 1,
+ iAsBx = 2;
+
+ /* OpArgMask */
+ static final int
+ OpArgN = 0, /* argument is not used */
+ OpArgU = 1, /* argument is used */
+ OpArgR = 2, /* argument is a register or a jump offset */
+ OpArgK = 3; /* argument is a constant or register/constant */
+
+
+ static void SET_OPCODE(InstructionPtr i,int o) {
+ i.set( ( i.get() & (MASK_NOT_OP)) | ((o << POS_OP) & MASK_OP) );
+ }
+
+ static void SETARG_A(InstructionPtr i,int u) {
+ i.set( ( i.get() & (MASK_NOT_A)) | ((u << POS_A) & MASK_A) );
+ }
+
+ static void SETARG_B(InstructionPtr i,int u) {
+ i.set( ( i.get() & (MASK_NOT_B)) | ((u << POS_B) & MASK_B) );
+ }
+
+ static void SETARG_C(InstructionPtr i,int u) {
+ i.set( ( i.get() & (MASK_NOT_C)) | ((u << POS_C) & MASK_C) );
+ }
+
+ static void SETARG_Bx(InstructionPtr i,int u) {
+ i.set( ( i.get() & (MASK_NOT_Bx)) | ((u << POS_Bx) & MASK_Bx) );
+ }
+
+ static void SETARG_sBx(InstructionPtr i,int u) {
+ SETARG_Bx( i, u + MAXARG_sBx );
+ }
+
+ static int CREATE_ABC(int o, int a, int b, int c) {
+ return ((o << POS_OP) & MASK_OP) |
+ ((a << POS_A) & MASK_A) |
+ ((b << POS_B) & MASK_B) |
+ ((c << POS_C) & MASK_C) ;
+ }
+
+ static int CREATE_ABx(int o, int a, int bc) {
+ return ((o << POS_OP) & MASK_OP) |
+ ((a << POS_A) & MASK_A) |
+ ((bc << POS_Bx) & MASK_Bx) ;
+ }
+
+ // vector reallocation
+
+ static LuaValue[] realloc(LuaValue[] v, int n) {
+ LuaValue[] a = new LuaValue[n];
+ if ( v != null )
+ System.arraycopy(v, 0, a, 0, Math.min(v.length,n));
+ return a;
+ }
+
+ static Prototype[] realloc(Prototype[] v, int n) {
+ Prototype[] a = new Prototype[n];
+ if ( v != null )
+ System.arraycopy(v, 0, a, 0, Math.min(v.length,n));
+ return a;
+ }
+
+ static LuaString[] realloc(LuaString[] v, int n) {
+ LuaString[] a = new LuaString[n];
+ if ( v != null )
+ System.arraycopy(v, 0, a, 0, Math.min(v.length,n));
+ return a;
+ }
+
+ static LocVars[] realloc(LocVars[] v, int n) {
+ LocVars[] a = new LocVars[n];
+ if ( v != null )
+ System.arraycopy(v, 0, a, 0, Math.min(v.length,n));
+ return a;
+ }
+
+ static int[] realloc(int[] v, int n) {
+ int[] a = new int[n];
+ if ( v != null )
+ System.arraycopy(v, 0, a, 0, Math.min(v.length,n));
+ return a;
+ }
+
+ static byte[] realloc(byte[] v, int n) {
+ byte[] a = new byte[n];
+ if ( v != null )
+ System.arraycopy(v, 0, a, 0, Math.min(v.length,n));
+ return a;
+ }
+
+ public int nCcalls;
+ Hashtable strings;
+
+ protected LuaC() {}
+
+ private LuaC(Hashtable strings) {
+ this.strings = strings;
+ }
+
+ /** Load into a Closure or LuaFunction, with the supplied initial environment */
+ public LuaFunction load(InputStream stream, String name, LuaValue env) throws IOException {
+ Prototype p = compile( stream, name );
+ return new LuaClosure( p, env );
+ }
+
+ /** Compile a prototype or load as a binary chunk */
+ public static Prototype compile(InputStream stream, String name) throws IOException {
+ int firstByte = stream.read();
+ return ( firstByte == '\033' )?
+ LoadState.loadBinaryChunk(firstByte, stream, name):
+ (new LuaC(new Hashtable())).luaY_parser(firstByte, stream, name);
+ }
+
+ /** Parse the input */
+ private Prototype luaY_parser(int firstByte, InputStream z, String name) {
+ LexState lexstate = new LexState(this, z);
+ FuncState funcstate = new FuncState();
+ // lexstate.buff = buff;
+ lexstate.setinput( this, firstByte, z, (LuaString) LuaValue.valueOf(name) );
+ lexstate.open_func(funcstate);
+ /* main func. is always vararg */
+ funcstate.f.is_vararg = LuaC.VARARG_ISVARARG;
+ funcstate.f.source = (LuaString) LuaValue.valueOf(name);
+ lexstate.next(); /* read first token */
+ lexstate.chunk();
+ lexstate.check(LexState.TK_EOS);
+ lexstate.close_func();
+ LuaC._assert (funcstate.prev == null);
+ LuaC._assert (funcstate.f.nups == 0);
+ LuaC._assert (lexstate.fs == null);
+ return funcstate.f;
+ }
+
+ // look up and keep at most one copy of each string
+ public LuaString newTString(byte[] bytes, int offset, int len) {
+ LuaString tmp = LuaString.valueOf(bytes, offset, len);
+ LuaString v = (LuaString) strings.get(tmp);
+ if ( v == null ) {
+ // must copy bytes, since bytes could be from reusable buffer
+ byte[] copy = new byte[len];
+ System.arraycopy(bytes, offset, copy, 0, len);
+ v = LuaString.valueOf(copy);
+ strings.put(v, v);
+ }
+ return v;
+ }
+
+ public String pushfstring(String string) {
+ return string;
+ }
+
+ public LuaFunction load(Prototype p, String filename, LuaValue env) {
+ return new LuaClosure( p, env );
+ }
+
+}
diff --git a/luaj-2.0.3/src/core/org/luaj/vm2/lib/BaseLib.java b/luaj-2.0.3/src/core/org/luaj/vm2/lib/BaseLib.java
new file mode 100644
index 0000000000..717d0a50e0
--- /dev/null
+++ b/luaj-2.0.3/src/core/org/luaj/vm2/lib/BaseLib.java
@@ -0,0 +1,430 @@
+/*******************************************************************************
+* 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.lib;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+
+import org.luaj.vm2.LoadState;
+import org.luaj.vm2.Lua;
+import org.luaj.vm2.LuaError;
+import org.luaj.vm2.LuaString;
+import org.luaj.vm2.LuaTable;
+import org.luaj.vm2.LuaThread;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.Varargs;
+
+/**
+ * Subclass of {@link LibFunction} which implements the lua basic library functions.
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * LuaThread.setGlobals(_G);
+ * _G.load(new BaseLib());
+ * _G.get("print").call(LuaValue.valueOf("hello, world"));
+ * }
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * _G.load(new CoroutineLib());
+ * }
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * _G.load(new DebugLib());
+ * }
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * _G.load(new JseIoLib());
+ * LuaThread.setGlobals(_G);
+ * _G.load(new JseBaseLib());
+ * _G.load(new PackageLib());
+ * _G.load(new JseIoLib());
+ * _G.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
+ * }
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
+ *
+ *
+ * {@code
+ * import org.luaj.vm2.LuaValue;
+ * import org.luaj.vm2.lib.OneArgFunction;
+ *
+ * public class hyperbolic extends OneArgFunction {
+ *
+ * public hyperbolic() {}
+ *
+ * public LuaValue call(LuaValue libname) {
+ * LuaValue library = tableOf();
+ * library.set( "sinh", new sinh() );
+ * library.set( "cosh", new cosh() );
+ * env.set( "hyperbolic", library );
+ * return library;
+ * }
+ *
+ * static class sinh extends OneArgFunction {
+ * public LuaValue call(LuaValue x) {
+ * return LuaValue.valueOf(Math.sinh(x.checkdouble()));
+ * }
+ * }
+ *
+ * static class cosh extends OneArgFunction {
+ * public LuaValue call(LuaValue x) {
+ * return LuaValue.valueOf(Math.cosh(x.checkdouble()));
+ * }
+ * }
+ *}
+ *}
+ * The default constructor is used to instantiate the library
+ * in response to {@code require 'hyperbolic'} statement,
+ * provided it is on Javas class path.
+ * This instance is then invoked with the name supplied to require()
+ * as the only argument, and library should initialized whatever global
+ * data it needs to and place it into the environment if needed.
+ * In this case, it creates two function, 'sinh', and 'cosh', and puts
+ * them into a global table called 'hyperbolic.'
+ * It placed the library table into the globals via the {@link #env}
+ * local variable which corresponds to the globals that apply when the
+ * library is loaded.
+ * {@code
+ * local t = require('hyperbolic')
+ * print( 't', t )
+ * print( 'hyperbolic', hyperbolic )
+ * for k,v in pairs(t) do
+ * print( 'k,v', k,v )
+ * end
+ * print( 'sinh(.5)', hyperbolic.sinh(.5) )
+ * print( 'cosh(.5)', hyperbolic.cosh(.5) )
+ * }
+ * {@code
+ * t table: 3dbbd23f
+ * hyperbolic table: 3dbbd23f
+ * k,v cosh function: 3dbbd128
+ * k,v sinh function: 3dbbd242
+ * sinh(.5) 0.5210953
+ * cosh(.5) 1.127626
+ * }
+ *
+ *
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * LuaThread.setGlobals(_G);
+ * _G.load(new BaseLib());
+ * _G.load(new PackageLib());
+ * _G.load(new MathLib());
+ * System.out.println( _G.get("math").get("sqrt").call( LuaValue.valueOf(2) ) );
+ * }
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
+ *
+ *
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * LuaThread.setGlobals(_G);
+ * _G.load(new BaseLib());
+ * _G.load(new PackageLib());
+ * _G.load(new OsLib());
+ * System.out.println( _G.get("os").get("time").call() );
+ * }
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * LuaThread.setGlobals(_G);
+ * _G.load(new BaseLib());
+ * _G.load(new PackageLib());
+ * System.out.println( _G.get("require").call(LuaValue.valueOf("hyperbolic")) );
+ * }
+ * In practice, the first 4 lines of the above are minimal requirements to get
+ * and initialize a globals table capable of basic reqire, print, and other functions,
+ * so it is much more convenient to use the {@link JsePlatform} and {@link JmePlatform}
+ * utility classes instead.
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * LuaThread.setGlobals(_G);
+ * _G.load(new BaseLib());
+ * _G.load(new PackageLib());
+ * _G.load(new StringLib());
+ * System.out.println( _G.get("string").get("upper").call( LuaValue.valueOf("abcde") ) );
+ * }
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * LuaThread.setGlobals(_G);
+ * _G.load(new BaseLib());
+ * _G.load(new PackageLib());
+ * _G.load(new TableLib());
+ * LuaValue tbl = LuaValue.listOf( new LuaValue[] {
+ * LuaValue.valueOf( "abc" ),
+ * LuaValue.valueOf( "def" ) } );
+ * LuaValue sep = LuaValue.valueOf( "-" );
+ * System.out.println( _G.get("table").get("concat").call( tbl, sep ) );
+ * }
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * LuaThread.setGlobals(_G);
+ * _G.load(new BaseLib());
+ * _G.load(new PackageLib());
+ * _G.load(new JmeIoLib());
+ * _G.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
+ * }
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
+ *
+ *
+ * {@code
+ * LuaValue _G = JmePlatform.standardGlobals();
+ * _G.get("print").call(LuaValue.valueOf("hello, world"));
+ * }
+ * {@code
+ * LoadState.load( getClass().getResourceAsStream("main.lua"), "main.lua", _G ).call();
+ * }
+ * {@code
+ * _G.get("require").call(LuaValue.valueOf("main"));
+ * }
+ * For this to succeed, the file "main.lua" must be a resource in the class path.
+ * See {@link BaseLib} for details on finding scripts using {@link ResourceFinder}.
+ *
+ *
+ * In addition, the {@link LuaC} compiler is installed so lua files may be loaded in their source form.
+ *
+ *
+ *
+ *
+ * The method {@link CoerceJavaToLua#coerce(Object)} looks as the type and dimesioning
+ * of the argument and tries to guess the best fit for corrsponding lua scalar,
+ * table, or table of tables.
+ *
+ * @see CoerceJavaToLua#coerce(Object)
+ * @see LuajavaLib
+ */
+public class CoerceJavaToLua {
+
+ static interface Coercion {
+ public LuaValue coerce( Object javaValue );
+ };
+
+ static final Map COERCIONS = new HashMap();
+
+ static {
+ Coercion boolCoercion = new Coercion() {
+ public LuaValue coerce( Object javaValue ) {
+ Boolean b = (Boolean) javaValue;
+ return b.booleanValue()? LuaValue.TRUE: LuaValue.FALSE;
+ }
+ } ;
+ Coercion intCoercion = new Coercion() {
+ public LuaValue coerce( Object javaValue ) {
+ Number n = (Number) javaValue;
+ return LuaInteger.valueOf( n.intValue() );
+ }
+ } ;
+ Coercion charCoercion = new Coercion() {
+ public LuaValue coerce( Object javaValue ) {
+ Character c = (Character) javaValue;
+ return LuaInteger.valueOf( c.charValue() );
+ }
+ } ;
+ Coercion doubleCoercion = new Coercion() {
+ public LuaValue coerce( Object javaValue ) {
+ Number n = (Number) javaValue;
+ return LuaDouble.valueOf( n.doubleValue() );
+ }
+ } ;
+ Coercion stringCoercion = new Coercion() {
+ public LuaValue coerce( Object javaValue ) {
+ return LuaString.valueOf( javaValue.toString() );
+ }
+ } ;
+ COERCIONS.put( Boolean.class, boolCoercion );
+ COERCIONS.put( Byte.class, intCoercion );
+ COERCIONS.put( Character.class, charCoercion );
+ COERCIONS.put( Short.class, intCoercion );
+ COERCIONS.put( Integer.class, intCoercion );
+ COERCIONS.put( Long.class, doubleCoercion );
+ COERCIONS.put( Float.class, doubleCoercion );
+ COERCIONS.put( Double.class, doubleCoercion );
+ COERCIONS.put( String.class, stringCoercion );
+ }
+
+ /**
+ * Coerse a Java object to a corresponding lua value.
+ *
+ *
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * LuaThread.setGlobals(_G);
+ * _G.load(new JseBaseLib());
+ * _G.get("print").call(LuaValue.valueOf("hello, world"));
+ * }
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * LuaThread.setGlobals(_G);
+ * _G.load(new JseBaseLib());
+ * _G.load(new PackageLib());
+ * _G.load(new JseIoLib());
+ * _G.get("io").get("write").call(LuaValue.valueOf("hello, world\n"));
+ * }
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * LuaThread.setGlobals(_G);
+ * _G.load(new JseBaseLib());
+ * _G.load(new PackageLib());
+ * _G.load(new JseMathLib());
+ * System.out.println( _G.get("math").get("sqrt").call( LuaValue.valueOf(2) ) );
+ * }
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
+ *
+ *
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * LuaThread.setGlobals(_G);
+ * _G.load(new JseBaseLib());
+ * _G.load(new PackageLib());
+ * _G.load(new JseOsLib());
+ * System.out.println( _G.get("os").get("time").call() );
+ * }
+ * Doing so will ensure the library is properly initialized
+ * and loaded into the globals table.
+ * {@code
+ * LuaValue _G = JsePlatform.standardGlobals();
+ * _G.get("print").call(LuaValue.valueOf("hello, world"));
+ * }
+ * {@code
+ * LoadState.load( new FileInputStream("main.lua"), "main.lua", _G ).call();
+ * }
+ * {@code
+ * _G.get("require").call(LuaValue.valueOf("main"));
+ * }
+ * For this to succeed, the file "main.lua" must be in the current directory or a resource.
+ * See {@link JseBaseLib} for details on finding scripts using {@link ResourceFinder}.
+ *
+ *
+ * In addition, the {@link LuaC} compiler is installed so lua files may be loaded in their source form.
+ * {@code
+ * LuaTable _G = new LuaTable();
+ * LuaThread.setGlobals(_G);
+ * LuaC.install();
+ * _G.load(new BaseLib());
+ * _G.load(new PackageLib());
+ * _G.load(new LuajavaLib());
+ * _G.get("loadstring").call( LuaValue.valueOf(
+ * "sys = luajava.bindClass('java.lang.System')\n"+
+ * "print ( sys:currentTimeMillis() )\n" ) ).call();
+ * }
+ * This example is not intended to be realistic - only to show how the {@link LuajavaLib}
+ * may be initialized by hand. In practice, the {@code luajava} library is available
+ * on all JSE platforms via the call to {@link JsePlatform#standardGlobals()}
+ * and the luajava api's are simply invoked from lua.
+ *