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

The following examples show how to use org.luaj.vm2.Varargs#checkjstring() . 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 VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
public Varargs invoke(Varargs args) {
    String s = args.checkjstring(1);
    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 2
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 3
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 4
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 5
Source File: PackageLib.java    From luaj with MIT License 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()));
}