Java Code Examples for org.luaj.vm2.LuaValue#isint()

The following examples show how to use org.luaj.vm2.LuaValue#isint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utilities.java    From Lukkit with MIT License 6 votes vote down vote up
/**
 * Gets the Java object from a LuaValue.
 *
 * @param value the LuaValue
 * @return the Java object
 */
public static Object getObjectFromLuavalue(LuaValue value) {
    if (value.istable()) {
        return convertTable(value.checktable());
    } else if (value.isint()) {
        return value.checkint();
    } else if (value.islong()) {
        return value.checklong();
    } else if (value.isnumber()) {
        return value.checkdouble();
    } else if (value.isstring()) {
        return value.checkjstring();
    } else if (value.isboolean()) {
        return value.checkboolean();
    } else if (value.isnil()) {
        return null;
    } else {
        return value.checkuserdata();
    }
}
 
Example 2
Source File: CoerceLuaToJava.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
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;
    }
}
 
Example 3
Source File: CoerceLuaToJava.java    From luaj with MIT License 6 votes vote down vote up
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;
	}
}
 
Example 4
Source File: CoerceLuaToJava.java    From XPrivacyLua with GNU General Public License v3.0 6 votes vote down vote up
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;
	}
}
 
Example 5
Source File: CoerceLuaToJava.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
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;
	}
}
 
Example 6
Source File: JavaArray.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
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<Array.getLength(m_instance)?
			CoerceJavaToLua.coerce(Array.get(m_instance,key.toint()-1)):
			NIL;
	}
	return super.get(key);
}
 
Example 7
Source File: JavaArray.java    From luaj with MIT License 5 votes vote down vote up
public void set(LuaValue key, LuaValue value) {
	if ( key.isint() ) {
		int i = key.toint() - 1;
		if ( i>=0 && i<Array.getLength(m_instance) )
			Array.set(m_instance,i,CoerceLuaToJava.coerce(value, m_instance.getClass().getComponentType()));
		else if ( m_metatable==null || ! settable(this,key,value) )
				error("array index out of bounds");
	}
	else
		super.set(key, value);
}
 
Example 8
Source File: JavaArray.java    From luaj with MIT License 5 votes vote down vote up
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<Array.getLength(m_instance)?
			CoerceJavaToLua.coerce(Array.get(m_instance,key.toint()-1)):
			NIL;
	}
	return super.get(key);
}
 
Example 9
Source File: JavaArray.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public void set(LuaValue key, LuaValue value) {
	if ( key.isint() ) {
		int i = key.toint() - 1;
		if ( i>=0 && i<Array.getLength(m_instance) )
			Array.set(m_instance,i,CoerceLuaToJava.coerce(value, m_instance.getClass().getComponentType()));
		else if ( m_metatable==null || ! settable(this,key,value) )
				error("array index out of bounds");
	}
	else
		super.set(key, value);
}
 
Example 10
Source File: JavaArray.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
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<Array.getLength(m_instance)?
			CoerceJavaToLua.coerce(Array.get(m_instance,key.toint()-1)):
			NIL;
	}
	return super.get(key);
}
 
Example 11
Source File: JavaArray.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public void set(LuaValue key, LuaValue value) {
	if ( key.isint() ) {
		int i = key.toint() - 1;
		if ( i>=0 && i<Array.getLength(m_instance) )
			Array.set(m_instance,i,CoerceLuaToJava.coerce(value, m_instance.getClass().getComponentType()));
		else if ( m_metatable==null || ! settable(this,key,value) )
				error("array index out of bounds");
	}
	else
		super.set(key, value);
}
 
Example 12
Source File: JavaArray.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
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<Array.getLength(m_instance)?
			CoerceJavaToLua.coerce(Array.get(m_instance,key.toint()-1)):
			NIL;
	}
	return super.get(key);
}
 
Example 13
Source File: JavaArray.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public void set(LuaValue key, LuaValue value) {
	if ( key.isint() ) {
		int i = key.toint() - 1;
		if ( i>=0 && i<Array.getLength(m_instance) )
			Array.set(m_instance,i, CoerceLuaToJava.coerce(value, m_instance.getClass().getComponentType()));
		else if ( m_metatable==null || ! settable(this,key,value) )
				error("array index out of bounds");
	}
	else
		super.set(key, value);
}
 
Example 14
Source File: DumpState.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
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]);
}
 
Example 15
Source File: DumpState.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
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]);
}
 
Example 16
Source File: DumpState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
void dumpConstants( Prototype f) throws IOException {
	 LuaValue[] k = f.k;
	int i, n = k.length;
	dumpInt(n);
	for (i = 0; i < n; i++) {
		 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 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]);
}
 
Example 17
Source File: DumpState.java    From luaj with MIT License 4 votes vote down vote up
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]);
}