org.luaj.vm2.LuaInteger Java Examples

The following examples show how to use org.luaj.vm2.LuaInteger. 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 Project: VideoOS-Android-SDK   Author: VideoOS   File: LexState.java    License: GNU General Public License v3.0 6 votes vote down vote up
void fornum(LuaString varname, int line) {
/* fornum -> NAME = exp1,exp1[,exp1] forbody */
      FuncState fs = this.fs;
      int base = fs.freereg;
      this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_INDEX);
      this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_LIMIT);
      this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_STEP);
      this.new_localvar(varname);
      this.checknext('=');
      this.exp1(); /* initial value */
      this.checknext(',');
      this.exp1(); /* limit */
      if (this.testnext(','))
          this.exp1(); /* optional step */
      else { /* default step = 1 */
          fs.codeABx(Lua.OP_LOADK, fs.freereg, fs.numberK(LuaInteger.valueOf(1)));
          fs.reserveregs(1);
      }
      this.forbody(base, line, 1, true);
  }
 
Example #2
Source Project: XPrivacyLua   Author: M66B   File: LexState.java    License: GNU General Public License v3.0 6 votes vote down vote up
void fornum(LuaString varname, int line) {
	/* fornum -> NAME = exp1,exp1[,exp1] forbody */
	FuncState fs = this.fs;
	int base = fs.freereg;
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_INDEX);
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_LIMIT);
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_STEP);
	this.new_localvar(varname);
	this.checknext('=');
	this.exp1(); /* initial value */
	this.checknext(',');
	this.exp1(); /* limit */
	if (this.testnext(','))
		this.exp1(); /* optional step */
	else { /* default step = 1 */
		fs.codeABx(Lua.OP_LOADK, fs.freereg, fs.numberK(LuaInteger.valueOf(1)));
		fs.reserveregs(1);
	}
	this.forbody(base, line, 1, true);
}
 
Example #3
Source Project: HtmlNative   Author: hsllany   File: LexState.java    License: Apache License 2.0 6 votes vote down vote up
void fornum(LuaString varname, int line) {
	/* fornum -> NAME = exp1,exp1[,exp1] forbody */
	FuncState fs = this.fs;
	int base = fs.freereg;
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_INDEX);
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_LIMIT);
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_STEP);
	this.new_localvar(varname);
	this.checknext('=');
	this.exp1(); /* initial value */
	this.checknext(',');
	this.exp1(); /* limit */
	if (this.testnext(','))
		this.exp1(); /* optional step */
	else { /* default step = 1 */
		fs.codeABx(Lua.OP_LOADK, fs.freereg, fs.numberK(LuaInteger.valueOf(1)));
		fs.reserveregs(1);
	}
	this.forbody(base, line, 1, true);
}
 
Example #4
Source Project: luaj   Author: luaj   File: LexState.java    License: MIT License 6 votes vote down vote up
void fornum(LuaString varname, int line) {
	/* fornum -> NAME = exp1,exp1[,exp1] forbody */
	FuncState fs = this.fs;
	int base = fs.freereg;
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_INDEX);
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_LIMIT);
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_STEP);
	this.new_localvar(varname);
	this.checknext('=');
	this.exp1(); /* initial value */
	this.checknext(',');
	this.exp1(); /* limit */
	if (this.testnext(','))
		this.exp1(); /* optional step */
	else { /* default step = 1 */
		fs.codeK(fs.freereg, fs.numberK(LuaInteger.valueOf(1)));
		fs.reserveregs(1);
	}
	this.forbody(base, line, 1, true);
}
 
Example #5
Source Project: luaj   Author: luaj   File: LuaJavaCoercionTest.java    License: 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 #6
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: FuncState.java    License: 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 Project: VideoOS-Android-SDK   Author: VideoOS   File: LuaUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * convert a table to map
 *
 * @param table
 * @return
 */
public static HashMap<String, String> toMap(LuaTable table) {
    if (table != null) {
        final HashMap<String, String> result = new HashMap<String, String>();
        final LuaValue[] keys = table.keys();
        for (LuaValue key : keys) {
            LuaValue luaValue = table.get(key);
            String value = null;
            if (luaValue.istable()) {
                value = JsonUtil.toString(luaValue);
            } else {
                if (luaValue instanceof LuaBoolean) {
                    value = String.valueOf(luaValue.optboolean(false));
                } else if (luaValue instanceof LuaInteger) {
                    value = String.valueOf(luaValue.optint(0));
                } else if (luaValue instanceof LuaDouble) {
                    value = String.valueOf(luaValue.optdouble(0));
                } else if (luaValue instanceof LuaString) {
                    value = String.valueOf(luaValue.optstring(null));
                } else {
                    value = String.valueOf(luaValue);
                }
            }
            if (value != null) {
                result.put(key.optjstring(null), value);
            }
        }
        return result;
    }
    return null;
}
 
Example #8
Source Project: XPrivacyLua   Author: M66B   File: FuncState.java    License: 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 #9
Source Project: HtmlNative   Author: hsllany   File: FuncState.java    License: 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 #10
Source Project: HtmlNative   Author: hsllany   File: LHttp.java    License: Apache License 2.0 5 votes vote down vote up
LResponse() {
    super();
    set("header", new ZeroArgFunction() {
        @Override
        public LuaValue call() {
            if (mHeader == null) {
                return LuaValue.NIL;
            }
            return LuaString.valueOf(mHeader);
        }
    });

    set("body", new ZeroArgFunction() {
        @Override
        public LuaValue call() {
            if (mBody == null) {
                return LuaValue.NIL;
            }
            return LuaString.valueOf(mBody);
        }
    });

    set("status", new ZeroArgFunction() {
        @Override
        public LuaValue call() {
            return LuaInteger.valueOf(mStatusCode);
        }
    });
}
 
Example #11
Source Project: Bytecoder   Author: mirkosertic   File: LuaTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testVarArgs() {
    final Globals theGlobals = new Globals();
    LuaC.install(theGlobals);
    final Varargs theArguments = LuaValue.varargsOf(new LuaValue[]{
            LuaInteger.valueOf(100),
            LuaInteger.valueOf(200)
    });
}
 
Example #12
Source Project: Bytecoder   Author: mirkosertic   File: LuaTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCall() throws IOException {
    final Globals theGlobals = new Globals();
    LuaC.install(theGlobals);
    final Prototype thePrototype = theGlobals.compilePrototype(new StringReader("function add(a,b) return a + b end"), "script");
    new LuaClosure(thePrototype, theGlobals).call();
    final LuaValue theFunction = theGlobals.get("add");
    Assert.assertFalse(theFunction.isnil());
    final Varargs theArguments = LuaValue.varargsOf(new LuaValue[] {
            LuaInteger.valueOf(100),
            LuaInteger.valueOf(200)
    });
    final LuaInteger theResult = (LuaInteger) theFunction.invoke(theArguments);
    Assert.assertEquals("300", theResult.tojstring());
}
 
Example #13
Source Project: Bytecoder   Author: mirkosertic   File: LuaTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCallStringResult() throws IOException {
    final Globals theGlobals = new Globals();
    LuaC.install(theGlobals);
    final Prototype thePrototype = theGlobals.compilePrototype(new StringReader("function add(a,b) return 'hello' end"), "script");
    new LuaClosure(thePrototype, theGlobals).call();
    final Varargs theArguments = LuaValue.varargsOf(new LuaValue[] {
            LuaInteger.valueOf(100),
            LuaInteger.valueOf(200)
    });
    final LuaValue theFunction = theGlobals.get("add");
    final LuaValue theValue = (LuaValue) theFunction.invoke(theArguments);
    Assert.assertTrue(theValue.isstring());
    Assert.assertEquals("hello", theValue.tojstring());
}
 
Example #14
Source Project: luaj   Author: luaj   File: FuncState.java    License: 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 #15
Source Project: luaj   Author: luaj   File: LuaJavaCoercionTest.java    License: 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 #16
Source Project: luaj   Author: luaj   File: LuaJavaCoercionTest.java    License: MIT License 5 votes vote down vote up
public void testLuaTableToJavaIntArray() {
	LuaTable t = new LuaTable();
	t.set(1, LuaInteger.valueOf(222) );
	t.set(2, LuaInteger.valueOf(333) );
	int[] i = null;
	Object o = CoerceLuaToJava.coerce(t, int[].class);
	assertEquals( int[].class, o.getClass() );
	i = (int[]) o;
	assertEquals( 2, i.length );
	assertEquals( 222, i[0] );
	assertEquals( 333, i[1] );
}
 
Example #17
Source Project: claudb   Author: tonivade   File: RedisBinding.java    License: 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 #18
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: CoerceJavaToLua.java    License: 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 #19
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: CoerceJavaToLua.java    License: 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 #20
Source Project: VideoOS-Android-SDK   Author: VideoOS   File: LexState.java    License: GNU General Public License v3.0 4 votes vote down vote up
public LuaValue nval() {
    return (_nval == null ? LuaInteger.valueOf(info) : _nval);
}
 
Example #21
Source Project: XPrivacyLua   Author: M66B   File: CoerceJavaToLua.java    License: 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 #22
Source Project: XPrivacyLua   Author: M66B   File: CoerceJavaToLua.java    License: 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 #23
Source Project: XPrivacyLua   Author: M66B   File: LexState.java    License: GNU General Public License v3.0 4 votes vote down vote up
public LuaValue nval() {
	return (_nval == null? LuaInteger.valueOf(info): _nval);
}
 
Example #24
Source Project: HtmlNative   Author: hsllany   File: CoerceJavaToLua.java    License: 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 #25
Source Project: HtmlNative   Author: hsllany   File: CoerceJavaToLua.java    License: 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 #26
Source Project: HtmlNative   Author: hsllany   File: LexState.java    License: Apache License 2.0 4 votes vote down vote up
public LuaValue nval() {
	return (_nval == null? LuaInteger.valueOf(info): _nval);
}
 
Example #27
Source Project: luaj   Author: luaj   File: CoerceJavaToLua.java    License: MIT License 4 votes vote down vote up
public LuaValue coerce( Object javaValue ) {
	Number n = (Number) javaValue;
	return LuaInteger.valueOf( n.intValue() );
}
 
Example #28
Source Project: luaj   Author: luaj   File: CoerceJavaToLua.java    License: MIT License 4 votes vote down vote up
public LuaValue coerce( Object javaValue ) {
	Character c = (Character) javaValue;
	return LuaInteger.valueOf( c.charValue() );
}
 
Example #29
Source Project: luaj   Author: luaj   File: LexState.java    License: MIT License 4 votes vote down vote up
public LuaValue nval() {
	return (_nval == null? LuaInteger.valueOf(info): _nval);
}
 
Example #30
Source Project: luaj   Author: luaj   File: LuaJavaCoercionTest.java    License: MIT License 4 votes vote down vote up
public void testJavaIntToLuaInt() {
	Integer i = Integer.valueOf(777);
	LuaValue v = CoerceJavaToLua.coerce(i);
	assertEquals( LuaInteger.class, v.getClass() );
	assertEquals( 777, v.toint() );
}