/*******************************************************************************
* 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.Varargs;
/**
* Base class for all concrete lua type values.
* <p>
* 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}.
* <p>
* 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.
* <p>
* 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.
* <p>
* Operations are performed on values directly via their Java methods.
* For example, the following code divides two numbers:
* <pre> {@code
* LuaValue a = LuaValue.valueOf( 5 );
* LuaValue b = LuaValue.valueOf( 4 );
* LuaValue c = a.div(b);
* } </pre>
* 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.
* <p>
* Field access and function calls are similar, with common overloads to simplify Java usage:
* <pre> {@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 );
* } </pre>
* <p>
* To supply variable arguments or get multiple return values, use
* {@link #invoke(Varargs)} or {@link #invokemethod(LuaValue, Varargs)} methods:
* <pre> {@code
* LuaValue modf = globals.get("math").get("modf");
* Varargs r = modf.invoke( d );
* print.call( r.arg(1), r.arg(2) );
* } </pre>
* <p>
* To load and run a script, {@link LoadState} is used:
* <pre> {@code
* LoadState.load( new FileInputStream("main.lua"), "main.lua", globals ).call();
* } </pre>
* <p>
* although {@code require} could also be used:
* <pre> {@code
* globals.get("require").call(LuaValue.valueOf("main"));
* } </pre>
* For this to work the file must be in the current directory, or in the class path,
* dependening on the platform.
* See {@link org.luaj.vm2.lib.jse.JsePlatform} and {@link org.luaj.vm2.lib.jme.JmePlatform} for details.
* <p>
* 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.
* <p>
* There are several methods for preinitializing tables, such as:
* <ul>
* <li>{@link #listOf(LuaValue[])} for unnamed elements</li>
* <li>{@link #tableOf(LuaValue[])} for named elements</li>
* <li>{@link #tableOf(LuaValue[], LuaValue[], Varargs)} for mixtures</li>
* </ul>
* <p>
* 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}
* <p>
* 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 org.luaj.vm2.lib.jse.JsePlatform
* @see org.luaj.vm2.lib.jme.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 = {};
/** The variable name of the environment. */
public static LuaString ENV = valueOf("_ENV");
/** LuaString constant with value "__index" for use as metatag */
public static final LuaString INDEX = valueOf("__index");
/**
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
android_luaj (178个子文件)
gradlew.bat 2KB
fileSnapshots.bin 2.66MB
fileHashes.bin 265KB
localClassSetAnalysis.bin 155KB
taskArtifacts.bin 94KB
localJarClasspathSnapshot.bin 21KB
outputFileStates.bin 20KB
.gitignore 105B
.gitignore 8B
build.gradle 784B
build.gradle 521B
settings.gradle 16B
gradlew 5KB
app.iml 11KB
LuaTest.iml 938B
gradle-wrapper.jar 52KB
LuaValue.java 147KB
LuaParserTokenManager.java 59KB
LexState.java 55KB
LuaParser.java 49KB
StringLib.java 35KB
LuaTable.java 33KB
JavaBuilder.java 32KB
Varargs.java 32KB
LuaString.java 31KB
FuncState.java 29KB
DebugLib.java 27KB
LuaClosure.java 20KB
IoLib.java 19KB
OsLib.java 18KB
Globals.java 17KB
ProtoInfo.java 16KB
BaseLib.java 15KB
Lua.java 15KB
LoadState.java 14KB
JavaGen.java 14KB
PackageLib.java 14KB
ScriptEngine.java 13KB
CoerceLuaToJava.java 13KB
LuaDouble.java 12KB
SimpleCharStream.java 11KB
Print.java 11KB
SimpleScriptContext.java 10KB
WeakTable.java 10KB
MathLib.java 10KB
AbstractScriptEngine.java 10KB
JseIoLib.java 9KB
DumpState.java 9KB
LuaInteger.java 9KB
ScriptEngineFactory.java 9KB
LuaThread.java 8KB
LuaScriptEngine.java 8KB
LibFunction.java 8KB
Exp.java 8KB
LuajavaLib.java 7KB
Buffer.java 7KB
Stat.java 7KB
Bit32Lib.java 7KB
SimpleBindings.java 7KB
CoerceJavaToLua.java 7KB
LuajClassLoader.java 7KB
ScriptContext.java 6KB
ParseException.java 6KB
BasicBlock.java 6KB
LuaC.java 6KB
TableLib.java 6KB
Constants.java 5KB
LuaJC.java 5KB
CoroutineLib.java 5KB
JsePlatform.java 5KB
Visitor.java 5KB
JseMathLib.java 5KB
JseProcess.java 5KB
Prototype.java 5KB
JavaMethod.java 5KB
JavaClass.java 5KB
LuaParserConstants.java 5KB
JseOsLib.java 5KB
LuajContext.java 5KB
JseBaseLib.java 5KB
Bindings.java 5KB
ScriptException.java 4KB
TokenMgrError.java 4KB
LuaError.java 4KB
LuaUserdata.java 4KB
CompiledScript.java 4KB
Token.java 4KB
LuaScriptEngineFactory.java 4KB
LuaNil.java 4KB
JavaConstructor.java 4KB
UpvalInfo.java 4KB
DefaultLauncher.java 4KB
VarInfo.java 3KB
Str.java 3KB
NameScope.java 3KB
MainActivity.java 3KB
JavaMember.java 3KB
NameResolver.java 3KB
TailcallVarargs.java 3KB
VarArgFunction.java 3KB
共 178 条
- 1
- 2
资源评论
dn小小
- 粉丝: 17
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功