當前位置: 首頁>>代碼示例>>Java>>正文


Java LuaValue.TNUMBER屬性代碼示例

本文整理匯總了Java中org.luaj.vm2.LuaValue.TNUMBER屬性的典型用法代碼示例。如果您正苦於以下問題:Java LuaValue.TNUMBER屬性的具體用法?Java LuaValue.TNUMBER怎麽用?Java LuaValue.TNUMBER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.luaj.vm2.LuaValue的用法示例。


在下文中一共展示了LuaValue.TNUMBER屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: score

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() );
	}
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:16,代碼來源:CoerceLuaToJava.java

示例2: coerce

public Object coerce(LuaValue value) {
	switch ( value.type() ) {
	case LuaValue.TNUMBER:
		return value.isint()? (Object)new Integer(value.toint()): (Object)new Double(value.todouble());
	case LuaValue.TBOOLEAN:
		return value.toboolean()? Boolean.TRUE: Boolean.FALSE;
	case LuaValue.TSTRING:
		return value.tojstring();
	case LuaValue.TUSERDATA:
		return value.optuserdata(targetType, null);
	case LuaValue.TNIL:
		return null;
	default:
		return value;
	}
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:16,代碼來源:CoerceLuaToJava.java

示例3: parseValue

/**
 * parse a value to given type
 *
 * @param type
 * @param value
 * @return
 */
private static Object parseValue(int type, LuaValue value) {
    switch (type) {
        case LuaValue.TBOOLEAN:
            if (isBoolean(value)) return value.checkboolean();
            break;
        case LuaValue.TNUMBER:
            if (isNumber(value)) return value.checknumber();
            break;
        case LuaValue.TSTRING:
            if (isString(value)) return value.checkjstring();
            break;
        case LuaValue.TTABLE:
            if (isTable(value)) return value.checktable();
            break;
        case LuaValue.TFUNCTION:
            if (isFunction(value)) return value.checkfunction();
            break;
        case LuaValue.TUSERDATA:
            if (isUserdata(value)) return value.checkuserdata();
            break;
        case LuaValue.TVALUE:
            return value;
    }
    return null;
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:32,代碼來源:LuaUtil.java

示例4: ioread

private Varargs ioread(File f, Varargs args) throws IOException {
	int i,n=args.narg();
	LuaValue[] v = new LuaValue[n];
	LuaValue ai,vi;
	LuaString fmt;
	for ( i=0; i<n; ) {
		item: switch ( (ai = args.arg(i+1)).type() ) {
			case LuaValue.TNUMBER:
				vi = freadbytes(f,ai.toint());
				break item;
			case LuaValue.TSTRING:
				fmt = ai.checkstring();
				if ( fmt.m_length == 2 && fmt.m_bytes[fmt.m_offset] == '*' ) {
					switch ( fmt.m_bytes[fmt.m_offset+1] ) {
					case 'n': vi = freadnumber(f); break item;
					case 'l': vi = freadline(f); break item;
					case 'a': vi = freadall(f); break item;
					}
				}
			default: 
				return argerror( i+1, "(invalid format)" ); 
		}
		if ( (v[i++] = vi).isnil() )
			break;
	}
	return i==0? NIL: varargsOf(v, 0, i);
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:27,代碼來源:IoLib.java

示例5: add_value

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());
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:28,代碼來源:StringLib.java

示例6: add_value

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() );
}
 
開發者ID:hsllany,項目名稱:HtmlNative,代碼行數:28,代碼來源:StringLib.java

示例7: dumpConstants

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]);
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:52,代碼來源:DumpState.java

示例8: isNumber

/**
 * is number
 *
 * @param target
 * @return
 */
public static boolean isNumber(final LuaValue target) {
    return target != null && target.type() == LuaValue.TNUMBER;
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:9,代碼來源:LuaUtil.java


注:本文中的org.luaj.vm2.LuaValue.TNUMBER屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。