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

The following examples show how to use org.luaj.vm2.Varargs#optint() . 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 6 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread t = args.isthread(a)? args.checkthread(a++): globals.running;
	LuaValue func    = args.optfunction(a++, null);
	String str       = args.optjstring(a++,"");
	int count        = args.optint(a++,0);
	boolean call=false,line=false,rtrn=false;
	for ( int i=0; i<str.length(); i++ )
		switch ( str.charAt(i) ) {
			case 'c': call=true; break;
			case 'l': line=true; break;
			case 'r': rtrn=true; break;
		}
	LuaThread.State s = t.state;
	s.hookfunc = func;
	s.hookcall = call;
	s.hookline = line;
	s.hookcount = count;
	s.hookrtrn = rtrn;
	return NONE;
}
 
Example 2
Source File: VenvyLVSvgeImageView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
public void startAnimation(Varargs varargs) {
    if (iSvgaImageView == null) {
        return;
    }
    if (varargs == null) {
        iSvgaImageView.startAnimation();
    } else {
        int length = varargs.optint(2, -1);
        int location = varargs.optint(3, -1);
        if (length != -1 && location != -1) {
            boolean isReverse = varargs.optboolean(4, false);
            iSvgaImageView.startAnimation(length, location, isReverse);
        } else {
            iSvgaImageView.startAnimation();
        }
    }
}
 
Example 3
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;
    String message = args.optjstring(a++, null);
    int level = args.optint(a++, 1);
    String tb = callstack(thread).traceback(level);
    return valueOf(message != null ? message + "\n" + tb : tb);
}
 
Example 4
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; 
	String message = args.optjstring(a++, null);
	int level = args.optint(a++,1);
	String tb = callstack(thread).traceback(level);
	return valueOf(message!=null? message+"\n"+tb: tb);
}
 
Example 5
Source File: StringLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaString src = args.checkstring( 1 );
	final int srclen = src.length();
	LuaString p = args.checkstring( 2 );
	LuaValue repl = args.arg( 3 );
	int max_s = args.optint( 4, srclen + 1 );
	final boolean anchor = p.length() > 0 && p.charAt( 0 ) == '^';
	
	Buffer lbuf = new Buffer( srclen );
	MatchState ms = new MatchState( args, src, p );
	
	int soffset = 0;
	int n = 0;
	while ( n < max_s ) {
		ms.reset();
		int res = ms.match( soffset, anchor ? 1 : 0 );
		if ( res != -1 ) {
			n++;
			ms.add_value( lbuf, soffset, res, repl );
		}
		if ( res != -1 && res > soffset )
			soffset = res;
		else if ( soffset < srclen )
			lbuf.append( (byte) src.luaByte( soffset++ ) );
		else
			break;
		if ( anchor )
			break;
	}
	lbuf.append( src.substring( soffset, srclen ) );
	return varargsOf(lbuf.tostring(), valueOf(n));
}
 
Example 6
Source File: TableLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaTable table = args.checktable(1);
	int size = table.length();
	int pos = args.optint(2, size);
	if (pos != size && (pos < 1 || pos > size + 1)) {
		argerror(2, "position out of bounds: " + pos + " not between 1 and " + (size + 1));
	}
	return table.remove(pos);
}
 
Example 7
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 8
Source File: DebugLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
	String message = args.optjstring(a++, null);
	int level = args.optint(a++,1);
	String tb = callstack(thread).traceback(level);
	return valueOf(message!=null? message+"\n"+tb: tb);
}
 
Example 9
Source File: StringLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaString src = args.checkstring( 1 );
	final int srclen = src.length();
	LuaString p = args.checkstring( 2 );
	int lastmatch = -1; /* end of last match */
	LuaValue repl = args.arg( 3 );
	int max_s = args.optint( 4, srclen + 1 );
	final boolean anchor = p.length() > 0 && p.charAt( 0 ) == '^';
	
	Buffer lbuf = new Buffer( srclen );
	MatchState ms = new MatchState( args, src, p );
	
	int soffset = 0;
	int n = 0;
	while ( n < max_s ) {
		ms.reset();
		int res = ms.match( soffset, anchor ? 1 : 0 );
		if ( res != -1 && res != lastmatch ) {  /* match? */
			n++;
			ms.add_value( lbuf, soffset, res, repl );  /* add replacement to buffer */
			soffset = lastmatch = res;
		}
		else if ( soffset < srclen ) /* otherwise, skip one character */
			lbuf.append( (byte) src.luaByte( soffset++ ) );
		else break;   /* end of subject */
		if ( anchor ) break;
	}
	lbuf.append( src.substring( soffset, srclen ) );
	return varargsOf(lbuf.tostring(), valueOf(n));
}
 
Example 10
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 11
Source File: StringLib.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
/**
 * This utility method implements both string.find and string.match.
 */
static Varargs str_find_aux( Varargs args, boolean find ) {
	LuaString s = args.checkstring( 1 );
	LuaString pat = args.checkstring( 2 );
	int init = args.optint( 3, 1 );
	
	if ( init > 0 ) {
		init = Math.min( init - 1, s.length() );
	} else if ( init < 0 ) {
		init = Math.max( 0, s.length() + init );
	}
	
	boolean fastMatch = find && ( args.arg(4).toboolean() || pat.indexOfAny( SPECIALS ) == -1 );
	
	if ( fastMatch ) {
		int result = s.indexOf( pat, init );
		if ( result != -1 ) {
			return varargsOf( valueOf(result+1), valueOf(result+pat.length()) );
		}
	} else {
		MatchState ms = new MatchState( args, s, pat );
		
		boolean anchor = false;
		int poff = 0;
		if ( pat.luaByte( 0 ) == '^' ) {
			anchor = true;
			poff = 1;
		}
		
		int soff = init;
		do {
			int res;
			ms.reset();
			if ( ( res = ms.match( soff, poff ) ) != -1 ) {
				if ( find ) {
					return varargsOf( valueOf(soff+1), valueOf(res), ms.push_captures( false, soff, res ));
				} else {
					return ms.push_captures( true, soff, res );
				}
			}
		} while ( soff++ < s.length() && !anchor );
	}
	return NIL;
}
 
Example 12
Source File: StringLib.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
/**
 * This utility method implements both string.find and string.match.
 */
static Varargs str_find_aux( Varargs args, boolean find ) {
	LuaString s = args.checkstring( 1 );
	LuaString pat = args.checkstring( 2 );
	int init = args.optint( 3, 1 );
	
	if ( init > 0 ) {
		init = Math.min( init - 1, s.length() );
	} else if ( init < 0 ) {
		init = Math.max( 0, s.length() + init );
	}
	
	boolean fastMatch = find && ( args.arg(4).toboolean() || pat.indexOfAny( SPECIALS ) == -1 );
	
	if ( fastMatch ) {
		int result = s.indexOf( pat, init );
		if ( result != -1 ) {
			return varargsOf( valueOf(result+1), valueOf(result+pat.length()) );
		}
	} else {
		MatchState ms = new MatchState( args, s, pat );
		
		boolean anchor = false;
		int poff = 0;
		if ( pat.luaByte( 0 ) == '^' ) {
			anchor = true;
			poff = 1;
		}
		
		int soff = init;
		do {
			int res;
			ms.reset();
			if ( ( res = ms.match( soff, poff ) ) != -1 ) {
				if ( find ) {
					return varargsOf( valueOf(soff+1), valueOf(res), ms.push_captures( false, soff, res ));
				} else {
					return ms.push_captures( true, soff, res );
				}
			}
		} while ( soff++ < s.length() && !anchor );
	}
	return NIL;
}
 
Example 13
Source File: StringLib.java    From luaj with MIT License 4 votes vote down vote up
/**
 * This utility method implements both string.find and string.match.
 */
static Varargs str_find_aux( Varargs args, boolean find ) {
	LuaString s = args.checkstring( 1 );
	LuaString pat = args.checkstring( 2 );
	int init = args.optint( 3, 1 );
	
	if ( init > 0 ) {
		init = Math.min( init - 1, s.length() );
	} else if ( init < 0 ) {
		init = Math.max( 0, s.length() + init );
	}
	
	boolean fastMatch = find && ( args.arg(4).toboolean() || pat.indexOfAny( SPECIALS ) == -1 );
	
	if ( fastMatch ) {
		int result = s.indexOf( pat, init );
		if ( result != -1 ) {
			return varargsOf( valueOf(result+1), valueOf(result+pat.length()) );
		}
	} else {
		MatchState ms = new MatchState( args, s, pat );
		
		boolean anchor = false;
		int poff = 0;
		if ( pat.length() > 0 && pat.luaByte( 0 ) == '^' ) {
			anchor = true;
			poff = 1;
		}
		
		int soff = init;
		do {
			int res;
			ms.reset();
			if ( ( res = ms.match( soff, poff ) ) != -1 ) {
				if ( find ) {
					return varargsOf( valueOf(soff+1), valueOf(res), ms.push_captures( false, soff, res ));
				} else {
					return ms.push_captures( true, soff, res );
				}
			}
		} while ( soff++ < s.length() && !anchor );
	}
	return NIL;
}
 
Example 14
Source File: UITextViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue setTextAlign(U view, Varargs varargs) {
    final int alignment = varargs.optint(2, 0);
    return view.setTextAlign(alignment);
}
 
Example 15
Source File: UITextViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue setGravity(U view, Varargs varargs) {
    final int gravity = varargs.optint(2, 0);
    return view.setGravity(gravity);
}
 
Example 16
Source File: StringLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
/**
 * This utility method implements both string.find and string.match.
 */
static Varargs str_find_aux(Varargs args, boolean find) {
    LuaString s = args.checkstring(1);
    LuaString pat = args.checkstring(2);
    int init = args.optint(3, 1);

    if (init > 0) {
        init = Math.min(init - 1, s.length());
    } else if (init < 0) {
        init = Math.max(0, s.length() + init);
    }

    boolean fastMatch = find && (args.arg(4).toboolean() || pat.indexOfAny(SPECIALS) == -1);

    if (fastMatch) {
        int result = s.indexOf(pat, init);
        if (result != -1) {
            return varargsOf(valueOf(result + 1), valueOf(result + pat.length()));
        }
    } else {
        MatchState ms = new MatchState(args, s, pat);

        boolean anchor = false;
        int poff = 0;
        if (pat.luaByte(0) == '^') {
            anchor = true;
            poff = 1;
        }

        int soff = init;
        do {
            int res;
            ms.reset();
            if ((res = ms.match(soff, poff)) != -1) {
                if (find) {
                    return varargsOf(valueOf(soff + 1), valueOf(res), ms.push_captures(false, soff, res));
                } else {
                    return ms.push_captures(true, soff, res);
                }
            }
        } while (soff++ < s.length() && !anchor);
    }
    return NIL;
}
 
Example 17
Source File: StringLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 3 votes vote down vote up
/**
 * string.gsub (s, pattern, repl [, n])
 * Returns a copy of s in which all (or the first n, if given) occurrences of the
 * pattern have been replaced by a replacement string specified by repl, which
 * may be a string, a table, or a function. gsub also returns, as its second value,
 * the total number of matches that occurred.
 * <p>
 * If repl is a string, then its value is used for replacement.
 * The character % works as an escape character: any sequence in repl of the form %n,
 * with n between 1 and 9, stands for the value of the n-th captured substring (see below).
 * The sequence %0 stands for the whole match. The sequence %% stands for a single %.
 * <p>
 * If repl is a table, then the table is queried for every match, using the first capture
 * as the key; if the pattern specifies no captures, then the whole match is used as the key.
 * <p>
 * If repl is a function, then this function is called every time a match occurs,
 * with all captured substrings passed as arguments, in order; if the pattern specifies
 * no captures, then the whole match is passed as a sole argument.
 * <p>
 * If the value returned by the table query or by the function call is a string or a number,
 * then it is used as the replacement string; otherwise, if it is false or nil,
 * then there is no replacement (that is, the original match is kept in the string).
 * <p>
 * Here are some examples:
 * x = string.gsub("hello world", "(%w+)", "%1 %1")
 * --> x="hello hello world world"
 * <p>
 * x = string.gsub("hello world", "%w+", "%0 %0", 1)
 * --> x="hello hello world"
 * <p>
 * x = string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1")
 * --> x="world hello Lua from"
 * <p>
 * x = string.gsub("home = $HOME, user = $USER", "%$(%w+)", os.getenv)
 * --> x="home = /home/roberto, user = roberto"
 * <p>
 * x = string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s)
 * return loadstring(s)()
 * end)
 * --> x="4+5 = 9"
 * <p>
 * local t = {name="lua", version="5.1"}
 * x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t)
 * --> x="lua-5.1.tar.gz"
 */
static Varargs gsub(Varargs args) {
    LuaString src = args.checkstring(1);
     int srclen = src.length();
    LuaString p = args.checkstring(2);
    LuaValue repl = args.arg(3);
    int max_s = args.optint(4, srclen + 1);
     boolean anchor = p.length() > 0 && p.charAt(0) == '^';

    Buffer lbuf = new Buffer(srclen);
    MatchState ms = new MatchState(args, src, p);

    int soffset = 0;
    int n = 0;
    while (n < max_s) {
        ms.reset();
        int res = ms.match(soffset, anchor ? 1 : 0);
        if (res != -1) {
            n++;
            ms.add_value(lbuf, soffset, res, repl);
        }
        if (res != -1 && res > soffset)
            soffset = res;
        else if (soffset < srclen)
            lbuf.append((byte) src.luaByte(soffset++));
        else
            break;
        if (anchor)
            break;
    }
    lbuf.append(src.substring(soffset, srclen));
    return varargsOf(lbuf.tostring(), valueOf(n));
}
 
Example 18
Source File: UIScrollViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 2 votes vote down vote up
/**
 * scroll one page
 *
 * @param view
 * @param varargs
 * @return
 */
@Deprecated
public LuaValue pageScroll(U view, Varargs varargs) {
    final int direction = varargs.optint(2, 0);
    return view.pageScroll(direction);
}
 
Example 19
Source File: UIScrollViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 2 votes vote down vote up
/**
 * scroll whole page
 *
 * @param view
 * @param varargs
 * @return
 */
@Deprecated
public LuaValue fullScroll(U view, Varargs varargs) {
    final int direction = varargs.optint(2, 0);
    return view.fullScroll(direction);
}
 
Example 20
Source File: UIHorizontalScrollViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 2 votes vote down vote up
/**
 * scroll whole page
 *
 * @param view
 * @param varargs
 * @return
 */
@Deprecated
public LuaValue fullScroll(U view, Varargs varargs) {
    final int direction = varargs.optint(2, 0);
    return view.fullScroll(direction);
}