Java Code Examples for org.luaj.vm2.LuaInteger#valueOf()

The following examples show how to use org.luaj.vm2.LuaInteger#valueOf() . 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: LuaJavaCoercionTest.java    From luaj with MIT License 6 votes vote down vote up
public void testIntArrayScoringTables() {
	int a = 5;
	LuaValue la = LuaInteger.valueOf(a);
	LuaTable tb = new LuaTable();
	tb.set( 1, la );
	LuaTable tc = new LuaTable();
	tc.set( 1, tb );
	
	int saa = CoerceLuaToJava.getCoercion(int.class).score(la);
	int sab = CoerceLuaToJava.getCoercion(int[].class).score(la);
	int sac = CoerceLuaToJava.getCoercion(int[][].class).score(la);
	assertTrue( saa < sab );
	assertTrue( saa < sac );
	int sba = CoerceLuaToJava.getCoercion(int.class).score(tb);
	int sbb = CoerceLuaToJava.getCoercion(int[].class).score(tb);
	int sbc = CoerceLuaToJava.getCoercion(int[][].class).score(tb);
	assertTrue( sbb < sba );
	assertTrue( sbb < sbc );
	int sca = CoerceLuaToJava.getCoercion(int.class).score(tc);
	int scb = CoerceLuaToJava.getCoercion(int[].class).score(tc);
	int scc = CoerceLuaToJava.getCoercion(int[][].class).score(tc);
	assertTrue( scc < sca );
	assertTrue( scc < scb );
}
 
Example 2
Source File: RedisBinding.java    From claudb with MIT License 5 votes vote down vote up
private LuaValue toLuaNumber(IntegerRedisToken value) {
  Integer integer = value.getValue();
  if (integer == null) {
    return LuaValue.NIL;
  }
  return LuaInteger.valueOf(integer);
}
 
Example 3
Source File: FuncState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
int numberK(LuaValue r) {
	if ( r instanceof LuaDouble ) {
		double d = r.todouble();
		int i = (int) d;
		if ( d == (double) i ) 
			r = LuaInteger.valueOf(i);
	}
	return this.addk(r);
}
 
Example 4
Source File: LuaJavaCoercionTest.java    From luaj with MIT License 5 votes vote down vote up
public void testLuaIntToJavaInt() {
	LuaInteger i = LuaInteger.valueOf(777);
	Object o = CoerceLuaToJava.coerce(i, int.class);
	assertEquals( Integer.class, o.getClass() );
	assertEquals( 777, ((Number)o).intValue() );
	o = CoerceLuaToJava.coerce(i, Integer.class);
	assertEquals( Integer.class, o.getClass() );
	assertEquals( new Integer(777), o );
}
 
Example 5
Source File: FuncState.java    From luaj with MIT License 5 votes vote down vote up
int numberK(LuaValue r) {
	if ( r instanceof LuaDouble ) {
		double d = r.todouble();
		int i = (int) d;
		if ( d == (double) i )
			r = LuaInteger.valueOf(i);
	}
	return this.addk(r);
}
 
Example 6
Source File: FuncState.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
int numberK(LuaValue r) {
	if ( r instanceof LuaDouble ) {
		double d = r.todouble();
		int i = (int) d;
		if ( d == (double) i ) 
			r = LuaInteger.valueOf(i);
	}
	return this.addk(r);
}
 
Example 7
Source File: FuncState.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
int numberK(LuaValue r) {
	if ( r instanceof LuaDouble ) {
		double d = r.todouble();
		int i = (int) d;
		if ( d == (double) i ) 
			r = LuaInteger.valueOf(i);
	}
	return this.addk(r);
}
 
Example 8
Source File: CoerceJavaToLua.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
public LuaValue coerce( Object javaValue ) {
	Character c = (Character) javaValue;
	return LuaInteger.valueOf( c.charValue() );
}
 
Example 9
Source File: LexState.java    From luaj with MIT License 4 votes vote down vote up
public LuaValue nval() {
	return (_nval == null? LuaInteger.valueOf(info): _nval);
}
 
Example 10
Source File: CoerceJavaToLua.java    From luaj with MIT License 4 votes vote down vote up
public LuaValue coerce( Object javaValue ) {
	Character c = (Character) javaValue;
	return LuaInteger.valueOf( c.charValue() );
}
 
Example 11
Source File: CoerceJavaToLua.java    From luaj with MIT License 4 votes vote down vote up
public LuaValue coerce( Object javaValue ) {
	Number n = (Number) javaValue;
	return LuaInteger.valueOf( n.intValue() );
}
 
Example 12
Source File: LexState.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
public LuaValue nval() {
	return (_nval == null? LuaInteger.valueOf(info): _nval);
}
 
Example 13
Source File: CoerceJavaToLua.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue coerce(Object javaValue) {
    Number n = (Number) javaValue;
    return LuaInteger.valueOf(n.intValue());
}
 
Example 14
Source File: CoerceJavaToLua.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
public LuaValue coerce( Object javaValue ) {
	Number n = (Number) javaValue;
	return LuaInteger.valueOf( n.intValue() );
}
 
Example 15
Source File: LexState.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue nval() {
	return (_nval == null? LuaInteger.valueOf(info): _nval);
}
 
Example 16
Source File: CoerceJavaToLua.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue coerce( Object javaValue ) {
	Character c = (Character) javaValue;
	return LuaInteger.valueOf( c.charValue() );
}
 
Example 17
Source File: CoerceJavaToLua.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue coerce( Object javaValue ) {
	Number n = (Number) javaValue;
	return LuaInteger.valueOf( n.intValue() );
}
 
Example 18
Source File: LexState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue nval() {
    return (_nval == null ? LuaInteger.valueOf(info) : _nval);
}
 
Example 19
Source File: CoerceJavaToLua.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue coerce(Object javaValue) {
    Character c = (Character) javaValue;
    return LuaInteger.valueOf(c.charValue());
}