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

The following examples show how to use org.luaj.vm2.LuaValue#toint() . 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: 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 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 (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;
    }
}
 
Example 3
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 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 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 7
Source File: CoerceLuaToJava.java    From luaj with MIT License 5 votes vote down vote up
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;
	}
}
 
Example 8
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 9
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 10
Source File: DefaultLauncher.java    From luaj with MIT License 5 votes vote down vote up
private Object[] launchChunk(LuaValue chunk, Object[] arg) {
	LuaValue args[] = new LuaValue[arg.length];
	for (int i = 0; i < args.length; ++i)
		args[i] = CoerceJavaToLua.coerce(arg[i]);
	Varargs results = chunk.invoke(LuaValue.varargsOf(args));

	final int n = results.narg();
	Object return_values[] = new Object[n];
	for (int i = 0; i < n; ++i) {
		LuaValue r = results.arg(i+1);
		switch (r.type()) {
		case LuaValue.TBOOLEAN:
			return_values[i] = r.toboolean();
			break;
		case LuaValue.TNUMBER:
			return_values[i] = r.todouble();
			break;
		case LuaValue.TINT:
			return_values[i] = r.toint();
			break;
		case LuaValue.TNIL:
			return_values[i] = null;
			break;
		case LuaValue.TSTRING:
			return_values[i] = r.tojstring();
			break;
		case LuaValue.TUSERDATA:
			return_values[i] = r.touserdata();
			break;
		default:
			return_values[i] = r;
		}
	}
	return return_values;
}
 
Example 11
Source File: CoerceLuaToJava.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
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;
	}
}
 
Example 12
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 13
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 14
Source File: CoerceLuaToJava.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
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;
	}
}
 
Example 15
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 16
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 17
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 18
Source File: LuaConversion.java    From Cubes with MIT License 4 votes vote down vote up
@Override
public Integer toJava(LuaValue l, Class<? extends Integer> c) {
  return l.toint();
}