本文整理匯總了Java中org.luaj.vm2.LuaValue.type方法的典型用法代碼示例。如果您正苦於以下問題:Java LuaValue.type方法的具體用法?Java LuaValue.type怎麽用?Java LuaValue.type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.luaj.vm2.LuaValue
的用法示例。
在下文中一共展示了LuaValue.type方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: coerce
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
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<n; i++ )
Array.set(a, i, componentCoercion.coerce(value.get(i+1)));
return a;
}
case LuaValue.TUSERDATA:
return value.touserdata();
case LuaValue.TNIL:
return null;
default:
return null;
}
}
示例2: score
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public int score(LuaValue value) {
switch ( value.type() ) {
case LuaValue.TNUMBER:
return inheritanceLevels( targetType, value.isint()? Integer.class: Double.class );
case LuaValue.TBOOLEAN:
return inheritanceLevels( targetType, Boolean.class );
case LuaValue.TSTRING:
return inheritanceLevels( targetType, String.class );
case LuaValue.TUSERDATA:
return inheritanceLevels( targetType, value.touserdata().getClass() );
case LuaValue.TNIL:
return SCORE_NULL_VALUE;
default:
return inheritanceLevels( targetType, value.getClass() );
}
}
示例3: call
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public LuaValue call(LuaValue value, LuaValue table) {
LuaValue mt = table.opttable(null);
switch ( value.type() ) {
case TNIL: LuaNil.s_metatable = mt; break;
case TNUMBER: LuaNumber.s_metatable = mt; break;
case TBOOLEAN: LuaBoolean.s_metatable = mt; break;
case TSTRING: LuaString.s_metatable = mt; break;
case TFUNCTION: LuaFunction.s_metatable = mt; break;
case TTHREAD: LuaThread.s_metatable = mt; break;
default: value.setmetatable( mt );
}
return value;
}
示例4: score
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public int score( LuaValue value ) {
switch ( value.type() ) {
case LuaValue.TBOOLEAN:
return 0;
}
return 1;
}
示例5: add_value
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
public void add_value( Buffer lbuf, int soffset, int end, LuaValue repl ) {
switch ( repl.type() ) {
case LuaValue.TSTRING:
case LuaValue.TNUMBER:
add_s( lbuf, repl.strvalue(), soffset, end );
return;
case LuaValue.TFUNCTION:
repl = repl.invoke( push_captures( true, soffset, end ) ).arg1();
break;
case LuaValue.TTABLE:
// Need to call push_onecapture here for the error checking
repl = repl.get( push_onecapture( 0, soffset, end ) );
break;
default:
error( "bad argument: string/function/table expected" );
return;
}
if ( !repl.toboolean() ) {
repl = s.substring( soffset, end );
} else if ( ! repl.isstring() ) {
error( "invalid replacement value (a "+repl.typename()+")" );
}
lbuf.append( repl.strvalue() );
}
示例6: buildState
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* Print the state of a {@link LuaClosure} that is being executed
*
* @param cl the {@link LuaClosure}
* @param pc the program counter
* @param stack the stack of {@link LuaValue}
* @param top the top of the stack
* @param varargs any {@link Varargs} value that may apply
*/
public LuaPrint buildState(LuaClosure cl, int pc, LuaValue[] stack, int top, Varargs varargs) {
// print opcode into buffer
StringBuffer previous = ps;
ps = new StringBuffer();
buildOpCode(cl.p, pc);
LogUtil.i(ps);
ps = previous;
format(ps.toString(), 50);
// print stack
ps.append('[');
for (int i = 0; i < stack.length; i++) {
LuaValue v = stack[i];
if (v == null)
ps.append(STRING_FOR_NULL);
else switch (v.type()) {
case LuaValue.TSTRING:
LuaString s = v.checkstring();
ps.append(s.length() < 48 ?
s.tojstring() :
s.substring(0, 32).tojstring() + "...+" + (s.length() - 32) + "b");
break;
case LuaValue.TFUNCTION:
ps.append(v.tojstring());
break;
case LuaValue.TUSERDATA:
Object o = v.touserdata();
if (o != null) {
String n = o.getClass().getName();
n = n.substring(n.lastIndexOf('.') + 1);
ps.append(n + ": " + Integer.toHexString(o.hashCode()));
} else {
ps.append(v.toString());
}
break;
default:
ps.append(v.tojstring());
}
if (i + 1 == top)
ps.append(']');
ps.append(" | ");
}
ps.append(varargs);
ps.append("\n");
return this;
}
示例7: dumpConstants
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
void dumpConstants(final Prototype f) throws IOException {
final LuaValue[] k = f.k;
int i, n = k.length;
dumpInt(n);
for (i = 0; i < n; i++) {
final LuaValue o = k[i];
switch ( o.type() ) {
case LuaValue.TNIL:
writer.write(LuaValue.TNIL);
break;
case LuaValue.TBOOLEAN:
writer.write(LuaValue.TBOOLEAN);
dumpChar(o.toboolean() ? 1 : 0);
break;
case LuaValue.TNUMBER:
switch (NUMBER_FORMAT) {
case NUMBER_FORMAT_FLOATS_OR_DOUBLES:
writer.write(LuaValue.TNUMBER);
dumpDouble(o.todouble());
break;
case NUMBER_FORMAT_INTS_ONLY:
if ( ! ALLOW_INTEGER_CASTING && ! o.isint() )
throw new java.lang.IllegalArgumentException("not an integer: "+o);
writer.write(LuaValue.TNUMBER);
dumpInt(o.toint());
break;
case NUMBER_FORMAT_NUM_PATCH_INT32:
if ( o.isint() ) {
writer.write(LuaValue.TINT);
dumpInt(o.toint());
} else {
writer.write(LuaValue.TNUMBER);
dumpDouble(o.todouble());
}
break;
default:
throw new IllegalArgumentException("number format not supported: "+NUMBER_FORMAT);
}
break;
case LuaValue.TSTRING:
writer.write(LuaValue.TSTRING);
dumpString((LuaString)o);
break;
default:
throw new IllegalArgumentException("bad type for " + o);
}
}
n = f.p.length;
dumpInt(n);
for (i = 0; i < n; i++)
dumpFunction(f.p[i]);
}
示例8: isString
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* is string
*
* @param target
* @return
*/
public static boolean isString(final LuaValue target) {
return target != null && target.type() == LuaValue.TSTRING;
}
示例9: isNumber
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* is number
*
* @param target
* @return
*/
public static boolean isNumber(final LuaValue target) {
return target != null && target.type() == LuaValue.TNUMBER;
}
示例10: isFunction
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* is function
*
* @param target
* @return
*/
public static boolean isFunction(final LuaValue target) {
return target != null && target.type() == LuaValue.TFUNCTION;
}
示例11: isUserdata
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* is userdata
*
* @param target
* @return
*/
public static boolean isUserdata(final LuaValue target) {
return target != null && target.type() == LuaValue.TUSERDATA;
}
示例12: isNone
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* is none
*
* @param target
* @return
*/
public static boolean isNone(final LuaValue target) {
return target != null && target.type() == LuaValue.TNONE;
}
示例13: isValid
import org.luaj.vm2.LuaValue; //導入方法依賴的package包/類
/**
* 判斷是否空或者nil
*
* @param target
* @return
*/
public static boolean isValid(final LuaValue target) {
return target != null && target.type() != LuaValue.TNIL;
}