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

The following examples show how to use org.luaj.vm2.Varargs#optjstring() . 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: BaseLib.java    From luaj with MIT License 6 votes vote down vote up
public Varargs invoke(Varargs args) {
	String s = args.optjstring(1, "collect");
	if ( "collect".equals(s) ) {
		System.gc();
		return ZERO;
	} else if ( "count".equals(s) ) {
		Runtime rt = Runtime.getRuntime();
		long used = rt.totalMemory() - rt.freeMemory();
		return varargsOf(valueOf(used/1024.), valueOf(used%1024));
	} else if ( "step".equals(s) ) {
		System.gc();
		return LuaValue.TRUE;
	} else {
		argerror(1, "invalid option '" + s + "'");
	}
	return NIL;
}
 
Example 2
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 3
Source File: BaseLib.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
public Varargs invoke(Varargs args) {
    String s = args.optjstring(1, "collect");
    if ("collect".equals(s)) {
        System.gc();
        return ZERO;
    } else if ("count".equals(s)) {
        Runtime rt = Runtime.getRuntime();
        long used = rt.totalMemory() - rt.freeMemory();
        return varargsOf(valueOf(used / 1024.), valueOf(used % 1024));
    } else if ("step".equals(s)) {
        System.gc();
        return LuaValue.TRUE;
    } else {
        this.argerror("gc op");
    }
    return NIL;
}
 
Example 4
Source File: UIImageViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue setImage(U view, Varargs varargs) {
    if (varargs.isstring(2)) {
        final String url = varargs.optjstring(2, null);
        final LuaFunction callback = varargs.optfunction(3, null);
        return view.setImageUrl(url, callback);
    } else if (varargs.arg(2) instanceof UDData) {//data
        final UDData data = (UDData) varargs.arg(2);
        return view.setImageBytes(data != null ? Base64.decode(data.bytes(), Base64.NO_WRAP) : null);
    }
    return view;
}
 
Example 5
Source File: DebugLib.java    From XPrivacyLua 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 6
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 7
Source File: BaseLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
    LuaValue ld = args.arg1();
    args.argcheck(ld.isstring() || ld.isfunction(), 1, "ld must be string or function");
    String source = args.optjstring(2, ld.isstring() ? ld.tojstring() : "=(load)");
    String mode = args.optjstring(3, "bt");
    LuaValue env = args.optvalue(4, globals);
    return loadStream(ld.isstring() ? ld.strvalue().toInputStream() : new
            StringInputStream(ld.checkfunction()), source, mode, env);
}
 
Example 8
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 9
Source File: PackageLib.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
public Varargs invoke(Varargs args) {
	String name = args.checkjstring(1);
	String path = args.checkjstring(2);
	String sep = args.optjstring(3, ".");
	String rep = args.optjstring(4, FILE_SEP);
	
	// check the path elements
	int e = -1;
	int n = path.length();
	StringBuffer sb = null;
	name = name.replace(sep.charAt(0), rep.charAt(0));
	while ( e < n ) {
		
		// find next template
		int b = e+1;
		e = path.indexOf(';',b);
		if ( e < 0 )
			e = path.length();
		String template = path.substring(b,e);
	
		// create filename
		int q = template.indexOf('?');
		String filename = template;
		if ( q >= 0 ) {
			filename = template.substring(0,q) + name + template.substring(q+1);
		}
		
		// try opening the file
		InputStream is = globals.finder.findResource(filename);
		if (is != null) {
			try { is.close(); } catch ( java.io.IOException ioe ) {}
			return valueOf(filename);
		}
		
		// report error
		if ( sb == null )
			sb = new StringBuffer();
		sb.append( "\n\t"+filename );
	}
	return varargsOf(NIL, valueOf(sb.toString()));
}
 
Example 10
Source File: IoLib.java    From luaj with MIT License 4 votes vote down vote up
public Varargs _io_lines(Varargs args) {
	String filename = args.optjstring(1, null);
	File infile = filename==null? input(): ioopenfile(FTYPE_NAMED, filename,"r");
	checkopen(infile);
	return lines(infile, filename != null, args.subargs(2));
}
 
Example 11
Source File: UIImageViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue setScaleType(U view, Varargs varargs) {
    final String scaleTypeName = varargs.optjstring(2, ImageView.ScaleType.FIT_XY.name());//默认FIT_XY
    final ImageView.ScaleType scaleType = UDImageScaleType.parse(scaleTypeName);
    return view.setScaleType(scaleType);
}
 
Example 12
Source File: UITextViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue setFontName(U view, Varargs varargs) {
    final String fontName = varargs.optjstring(2, null);
    return view.setFont(fontName);
}
 
Example 13
Source File: UITextViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue setEllipsize(U view, Varargs varargs) {
    //TODO 这里需要统一
    final String ellipsizeName = varargs.optjstring(2, TextUtils.TruncateAt.END.name());
    final TextUtils.TruncateAt ellipsize = UDEllipsize.parse(ellipsizeName);
    return view.setEllipsize(ellipsize);
}
 
Example 14
Source File: VenvyLVSvgeImageView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public void svga(final Varargs varargs) {
    if (varargs.isstring(2)) {
        final String url = varargs.optjstring(2, null);
        mReadyToPlay = varargs.optfunction(3, null);
        if (iSvgaImageView == null) {
            return;
        }
        iSvgaImageView.parse(url, new ISvgaParseCompletion() {
            @Override
            public void onComplete(Object videoItem) {
                try {
                    Class videoItemClass = videoItem.getClass();
                    Field fpsField = videoItemClass.getDeclaredField("FPS");
                    Field framesField = videoItemClass.getDeclaredField("frames");
                    if (fpsField != null) {
                        fps = fpsField.getInt(videoItem);
                        frames = framesField.getInt(videoItem);
                    }
                    if (mReadyToPlay != null) {
                        LuaUtil.callFunction(mReadyToPlay);
                    } else {
                        iSvgaImageView.startAnimation();
                    }
                } catch (Exception e) {
                    VenvyLog.e(VenvyLVSvgeImageView.class.getName(), e);
                }
            }

            @Override
            public void onError() {

            }
        });

        iSvgaImageView.setCallback(new SVGACallback() {
            @Override
            public void onPause() {
                LuaUtil.callFunction(mOnPause);
            }

            @Override
            public void onFinished() {
                LuaUtil.callFunction(mOnFinished);
            }

            @Override
            public void onRepeat() {
                LuaUtil.callFunction(mOnRepeat);
            }

            @Override
            public void onStep(int i, double v) {
                LuaUtil.callFunction(mOnStep, LuaValue.valueOf(i));
            }
        });

    }
}
 
Example 15
Source File: DebugLib.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running; 
	LuaValue func = args.arg(a++);
	String what = args.optjstring(a++, "flnStu");
	DebugLib.CallStack callstack = callstack(thread);

	// find the stack info
	DebugLib.CallFrame frame;
	if ( func.isnumber() ) {
		frame = callstack.getCallFrame(func.toint());
		if (frame == null)
			return NONE;
		func = frame.f;
	} else if ( func.isfunction() ) {
		frame = callstack.findCallFrame(func);
	} else {
		return argerror(a-2, "function or level");
	}

	// start a table
	DebugInfo ar = callstack.auxgetinfo(what, (LuaFunction) func, frame);
	LuaTable info = new LuaTable();
	if (what.indexOf('S') >= 0) {
		info.set(WHAT, LUA);
		info.set(SOURCE, valueOf(ar.source));
		info.set(SHORT_SRC, valueOf(ar.short_src));
		info.set(LINEDEFINED, valueOf(ar.linedefined));
		info.set(LASTLINEDEFINED, valueOf(ar.lastlinedefined));
	}
	if (what.indexOf('l') >= 0) {
		info.set( CURRENTLINE, valueOf(ar.currentline) );
	}
	if (what.indexOf('u') >= 0) {
		info.set(NUPS, valueOf(ar.nups));
		info.set(NPARAMS, valueOf(ar.nparams));
		info.set(ISVARARG, ar.isvararg? ONE: ZERO);
	}
	if (what.indexOf('n') >= 0) {
		info.set(NAME, LuaValue.valueOf(ar.name!=null? ar.name: "?"));
		info.set(NAMEWHAT, LuaValue.valueOf(ar.namewhat));
	}
	if (what.indexOf('t') >= 0) {
		info.set(ISTAILCALL, ZERO);
	}
	if (what.indexOf('L') >= 0) {
		LuaTable lines = new LuaTable();
		info.set(ACTIVELINES, lines);
		DebugLib.CallFrame cf;
		for (int l = 1; (cf=callstack.getCallFrame(l)) != null; ++l)
			if (cf.f == func)
				lines.insert(-1, valueOf(cf.currentline()));
	}
	if (what.indexOf('f') >= 0) {
		if (func != null)
			info.set( FUNC, func );
	}
	return info;
}
 
Example 16
Source File: PackageLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public Varargs invoke(Varargs args) {
    String name = args.checkjstring(1);
    String path = args.checkjstring(2);
    String sep = args.optjstring(3, ".");
    String rep = args.optjstring(4, FILE_SEP);

    // check the path elements
    int e = -1;
    int n = path.length();
    StringBuffer sb = null;
    name = name.replace(sep.charAt(0), rep.charAt(0));
    while (e < n) {

        // find next template
        int b = e + 1;
        e = path.indexOf(';', b);
        if (e < 0)
            e = path.length();
        String template = path.substring(b, e);

        // create filename
        int q = template.indexOf('?');
        String filename = template;
        if (q >= 0) {
            filename = template.substring(0, q) + name + template.substring(q + 1);
        }

        // try opening the file
        InputStream is = globals.getLuaResourceFinder().findResource(filename);//modify by song
        if (is != null) {
            try {
                is.close();
            } catch (java.io.IOException ioe) {
            }
            return valueOf(filename);
        }

        // report error
        if (sb == null)
            sb = new StringBuffer();
        sb.append("\n\t" + filename);
    }
    return varargsOf(NIL, valueOf(sb.toString()));
}
 
Example 17
Source File: PackageLib.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
public Varargs invoke(Varargs args) {
	String name = args.checkjstring(1);
	String path = args.checkjstring(2);
	String sep = args.optjstring(3, ".");
	String rep = args.optjstring(4, FILE_SEP);
	
	// check the path elements
	int e = -1;
	int n = path.length();
	StringBuffer sb = null;
	name = name.replace(sep.charAt(0), rep.charAt(0));
	while ( e < n ) {
		
		// find next template
		int b = e+1;
		e = path.indexOf(';',b);
		if ( e < 0 )
			e = path.length();
		String template = path.substring(b,e);
	
		// create filename
		int q = template.indexOf('?');
		String filename = template;
		if ( q >= 0 ) {
			filename = template.substring(0,q) + name + template.substring(q+1);
		}
		
		// try opening the file
		InputStream is = globals.finder.findResource(filename);
		if (is != null) {
			try { is.close(); } catch ( java.io.IOException ioe ) {}
			return valueOf(filename);
		}
		
		// report error
		if ( sb == null )
			sb = new StringBuffer();
		sb.append( "\n\t"+filename );
	}
	return varargsOf(NIL, valueOf(sb.toString()));
}
 
Example 18
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running; 
	LuaValue func = args.arg(a++);
	String what = args.optjstring(a++, "flnStu");
	DebugLib.CallStack callstack = callstack(thread);

	// find the stack info
	DebugLib.CallFrame frame;
	if ( func.isnumber() ) {
		frame = callstack.getCallFrame(func.toint());
		if (frame == null)
			return NONE;
		func = frame.f;
	} else if ( func.isfunction() ) {
		frame = callstack.findCallFrame(func);
	} else {
		return argerror(a-2, "function or level");
	}

	// start a table
	DebugInfo ar = callstack.auxgetinfo(what, (LuaFunction) func, frame);
	LuaTable info = new LuaTable();
	if (what.indexOf('S') >= 0) {
		info.set(WHAT, LUA);
		info.set(SOURCE, valueOf(ar.source));
		info.set(SHORT_SRC, valueOf(ar.short_src));
		info.set(LINEDEFINED, valueOf(ar.linedefined));
		info.set(LASTLINEDEFINED, valueOf(ar.lastlinedefined));
	}
	if (what.indexOf('l') >= 0) {
		info.set( CURRENTLINE, valueOf(ar.currentline) );
	}
	if (what.indexOf('u') >= 0) {
		info.set(NUPS, valueOf(ar.nups));
		info.set(NPARAMS, valueOf(ar.nparams));
		info.set(ISVARARG, ar.isvararg? ONE: ZERO);
	}
	if (what.indexOf('n') >= 0) {
		info.set(NAME, LuaValue.valueOf(ar.name!=null? ar.name: "?"));
		info.set(NAMEWHAT, LuaValue.valueOf(ar.namewhat));
	}
	if (what.indexOf('t') >= 0) {
		info.set(ISTAILCALL, ZERO);
	}
	if (what.indexOf('L') >= 0) {
		LuaTable lines = new LuaTable();
		info.set(ACTIVELINES, lines);
		DebugLib.CallFrame cf;
		for (int l = 1; (cf=callstack.getCallFrame(l)) != null; ++l)
			if (cf.f == func)
				lines.insert(-1, valueOf(cf.currentline()));
	}
	if (what.indexOf('f') >= 0) {
		if (func != null)
			info.set( FUNC, func );
	}
	return info;
}
 
Example 19
Source File: DataMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 将二进制数据转成Json,使用给定的编码,默认utf-8
 *
 * @param data
 * @param varargs
 * @return
 */
public LuaValue toJson(U data, Varargs varargs) {
    final String encode = varargs.optjstring(2, UDData.DEFAULT_ENCODE);
    final String json = data.toJson(encode);
    return json != null ? valueOf(json) : NIL;
}
 
Example 20
Source File: DataMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 将二进制数据转成table,使用给定的编码,默认utf-8
 *
 * @param data
 * @param varargs
 * @return
 */
public LuaValue toTable(U data, Varargs varargs) {
    final String encode = varargs.optjstring(2, UDData.DEFAULT_ENCODE);
    return data.toTable(encode);
}