Java Code Examples for org.luaj.vm2.Varargs#checkint()

The following examples show how to use org.luaj.vm2.Varargs#checkint() . 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: DebugLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaClosure f1 = args.checkclosure(1);
	int n1 = args.checkint(2);
	LuaClosure f2 = args.checkclosure(3);
	int n2 = args.checkint(4);
	if (n1 < 1 || n1 > f1.upValues.length)
		argerror("index out of range");
	if (n2 < 1 || n2 > f2.upValues.length)
		argerror("index out of range");
	f1.upValues[n1-1] = f2.upValues[n2-1];
	return NONE;
}
 
Example 2
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaClosure f1 = args.checkclosure(1);
	int n1 = args.checkint(2);
	LuaClosure f2 = args.checkclosure(3);
	int n2 = args.checkint(4);
	if (n1 < 1 || n1 > f1.upValues.length)
		argerror("index out of range");
	if (n2 < 1 || n2 > f2.upValues.length)
		argerror("index out of range");
	f1.upValues[n1-1] = f2.upValues[n2-1];
	return NONE;
}
 
Example 3
Source File: StringLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	int n = args.narg();
	byte[] bytes = new byte[n];
	for ( int i=0, a=1; i<n; i++, a++ ) {
		int c = args.checkint(a);
		if (c<0 || c>=256) argerror(a, "invalid value for string.char [0; 255]: " + c);
		bytes[i] = (byte) c;
	}
	return LuaString.valueUsing( bytes );
}
 
Example 4
Source File: DebugLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaValue func = args.checkfunction(1);
	int up = args.checkint(2);
	if ( func instanceof LuaClosure ) {
		LuaClosure c = (LuaClosure) func;
		LuaString name = findupvalue(c, up);
		if ( name != null ) {
			return varargsOf(name, c.upValues[up-1].getValue() );
		}
	}
	return NIL;
}
 
Example 5
Source File: Bit32Lib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
static Varargs btest( Varargs args ) {
	int bits = -1;
	for ( int i = 1; i <= args.narg(); i++ ) {
		bits &= args.checkint(i);
	}
	return valueOf( bits != 0 );
}
 
Example 6
Source File: LuaMappingWorld.java    From Cubes with MIT License 5 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
  int x = args.checkint(1);
  int y = args.checkint(2);
  int z = args.checkint(3);
  Block block = (Block) args.checkuserdata(4, Block.class);
  int meta = args.optint(5, 0);
  world.setBlock(block, x, y, z, meta);
  return NIL;
}
 
Example 7
Source File: DebugLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaValue func = args.checkfunction(1);
	int up = args.checkint(2);
	if ( func instanceof LuaClosure ) {
		LuaClosure c = (LuaClosure) func;
		LuaString name = findupvalue(c, up);
		if ( name != null ) {
			return varargsOf(name, c.upValues[up-1].getValue() );
		}
	}
	return NIL;
}
 
Example 8
Source File: StringLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	int n = args.narg();
	byte[] bytes = new byte[n];
	for ( int i=0, a=1; i<n; i++, a++ ) {
		int c = args.checkint(a);
		if (c<0 || c>=256) argerror(a, "invalid value");
		bytes[i] = (byte) c;
	}
	return LuaString.valueUsing( bytes );
}
 
Example 9
Source File: LuaMappingWorld.java    From Cubes with MIT License 5 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
  int x1 = args.checkint(1);
  int y1 = args.checkint(2);
  int z1 = args.checkint(3);
  int x2 = args.checkint(4);
  int y2 = args.checkint(5);
  int z2 = args.checkint(6);
  Block block = (Block) args.checkuserdata(7, Block.class);
  int meta = args.optint(8, 0);
  world.setBlocks(block, x1, y1, z1, x2, y2, z2, meta);
  return NIL;
}
 
Example 10
Source File: Bit32Lib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
static Varargs band( Varargs args ) {
	int result = -1;
	for ( int i = 1; i <= args.narg(); i++ ) {
		result &= args.checkint(i);
	}
	return bitsToValue( result );
}
 
Example 11
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
    int a = 1;
    LuaThread thread = args.isthread(a) ? args.checkthread(a++) : globals.running;
    int level = args.checkint(a++);
    int local = args.checkint(a++);
    CallFrame f = callstack(thread).getCallFrame(level);
    return f != null ? f.getLocal(local) : NONE;
}
 
Example 12
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaValue func = args.checkfunction(1);
	int up = args.checkint(2);
	if ( func instanceof LuaClosure ) {
		LuaClosure c = (LuaClosure) func;
		LuaString name = findupvalue(c, up);
		if ( name != null ) {
			return varargsOf(name, c.upValues[up-1].getValue() );
		}
	}
	return NIL;
}
 
Example 13
Source File: BaseLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	int n = args.narg()-1; 				
	if ( args.arg1().equals(valueOf("#")) )
		return valueOf(n);
	int i = args.checkint(1);
	if ( i == 0 || i < -n )
		argerror(1,"index out of range");
	return args.subargs(i<0? n+i+2: i+1);
}
 
Example 14
Source File: Bit32Lib.java    From luaj with MIT License 5 votes vote down vote up
static Varargs bor( Varargs args ) {
	int result = 0;
	for ( int i = 1; i <= args.narg(); i++ ) {
		result |= args.checkint(i);
	}
	return bitsToValue( result );
}
 
Example 15
Source File: DebugLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaValue func = args.checkfunction(1);
	int up = args.checkint(2);
	if ( func instanceof LuaClosure ) {
		LuaClosure c = (LuaClosure) func;
		if ( c.upValues != null && up > 0 && up <= c.upValues.length ) {
			return valueOf(c.upValues[up-1].hashCode());
		}
	}
	return NIL;
}
 
Example 16
Source File: Bit32Lib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
static Varargs btest( Varargs args ) {
	int bits = -1;
	for ( int i = 1; i <= args.narg(); i++ ) {
		bits &= args.checkint(i);
	}
	return valueOf( bits != 0 );
}
 
Example 17
Source File: StringLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaString s = args.checkstring( 1 );
	int n = args.checkint( 2 );
	final byte[] bytes = new byte[ s.length() * n ];
	int len = s.length();
	for ( int offset = 0; offset < bytes.length; offset += len ) {
		s.copyInto( 0, bytes, offset, len );
	}
	return LuaString.valueUsing( bytes );
}
 
Example 18
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
    LuaValue func = args.checkfunction(1);
    int up = args.checkint(2);
    LuaValue value = args.arg(3);
    if (func instanceof LuaClosure) {
        LuaClosure c = (LuaClosure) func;
        LuaString name = findupvalue(c, up);
        if (name != null) {
            c.upValues[up - 1].setValue(value);
            return name;
        }
    }
    return NIL;
}
 
Example 19
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
    int a = 1;
    LuaThread thread = args.isthread(a) ? args.checkthread(a++) : globals.running;
    int level = args.checkint(a++);
    int local = args.checkint(a++);
    LuaValue value = args.arg(a++);
    CallFrame f = callstack(thread).getCallFrame(level);
    return f != null ? f.setLocal(local, value) : NONE;
}
 
Example 20
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running; 
	int level = args.checkint(a++);
	int local = args.checkint(a++);
	CallFrame f = callstack(thread).getCallFrame(level);
	return f != null? f.getLocal(local): NONE;
}