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

The following examples show how to use org.luaj.vm2.Varargs#isstring() . 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: PackageLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
public Varargs invoke(Varargs args) {
            LuaString name = args.checkstring(1);
//            InputStream is = null;

            // get package path
            LuaValue path = package_.get(_PATH);
            if (!path.isstring())
                return valueOf("package.path is not a string");

            // get the searchpath function.
            Varargs v = package_.get(_SEARCHPATH).invoke(varargsOf(name, path));

            // Did we get a result?
            if (!v.isstring(1))
                return v.arg(2).tostring();
            LuaString filename = v.arg1().strvalue();

            // Try to load the file.
            v = globals.loadfile(filename.tojstring());
            if (v.arg1().isfunction())
                return LuaValue.varargsOf(v.arg1(), filename);

            // report error
            return varargsOf(NIL, valueOf("'" + filename + "': " + v.arg(2).tojstring()));
        }
 
Example 2
Source File: PackageLib.java    From luaj with MIT License 6 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaString name = args.checkstring(1);
			
	// get package path
	LuaValue path = package_.get(_PATH);
	if ( ! path.isstring() )
		return valueOf("package.path is not a string");

	// get the searchpath function.
	Varargs v = package_.get(_SEARCHPATH).invoke(varargsOf(name, path));
	
	// Did we get a result?
	if (!v.isstring(1))
		return v.arg(2).tostring();
	LuaString filename = v.arg1().strvalue();

	// Try to load the file.
	v = globals.loadfile(filename.tojstring());
	if ( v.arg1().isfunction() )
		return LuaValue.varargsOf(v.arg1(), filename);
	
	// report error
	return varargsOf(NIL, valueOf("'"+filename+"': "+v.arg(2).tojstring()));
}
 
Example 3
Source File: PackageLib.java    From XPrivacyLua with GNU General Public License v3.0 6 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaString name = args.checkstring(1);
	InputStream is = null;
			
	// get package path
	LuaValue path = package_.get(_PATH);
	if ( ! path.isstring() ) 
		return valueOf("package.path is not a string");

	// get the searchpath function.
	Varargs v = package_.get(_SEARCHPATH).invoke(varargsOf(name, path));
	
	// Did we get a result?
	if (!v.isstring(1))
		return v.arg(2).tostring();
	LuaString filename = v.arg1().strvalue();

	// Try to load the file.
	v = globals.loadfile(filename.tojstring()); 
	if ( v.arg1().isfunction() )
		return LuaValue.varargsOf(v.arg1(), filename);
	
	// report error
	return varargsOf(NIL, valueOf("'"+filename+"': "+v.arg(2).tojstring()));
}
 
Example 4
Source File: PackageLib.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaString name = args.checkstring(1);
	InputStream is = null;
			
	// get package path
	LuaValue path = package_.get(_PATH);
	if ( ! path.isstring() ) 
		return valueOf("package.path is not a string");

	// get the searchpath function.
	Varargs v = package_.get(_SEARCHPATH).invoke(varargsOf(name, path));
	
	// Did we get a result?
	if (!v.isstring(1))
		return v.arg(2).tostring();
	LuaString filename = v.arg1().strvalue();

	// Try to load the file.
	v = globals.loadfile(filename.tojstring()); 
	if ( v.arg1().isfunction() )
		return LuaValue.varargsOf(v.arg1(), filename);
	
	// report error
	return varargsOf(NIL, valueOf("'"+filename+"': "+v.arg(2).tojstring()));
}
 
Example 5
Source File: LuaMappingCubes.java    From Cubes with MIT License 5 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
  BlocksItems.load();
  if (args.isstring(1)) {
    LuaUserdata u = BlocksItems.itemUserdata.get(args.checkjstring(1));
    return u != null ? u : NIL;
  } else {
    return BlocksItems.itemTable;
  }
}
 
Example 6
Source File: LuaMappingCubes.java    From Cubes with MIT License 5 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
  BlocksItems.load();
  if (args.isstring(1)) {
    LuaUserdata u = BlocksItems.blockUserdata.get(args.checkjstring(1));
    return u != null ? u : NIL;
  } else {
    return BlocksItems.blockTable;
  }
}
 
Example 7
Source File: BaseLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	args.argcheck(args.isstring(1) || args.isnil(1), 1, "filename must be string or nil");
	String filename = args.isstring(1)? args.tojstring(1): null;
	String mode = args.optjstring(2, "bt");
	LuaValue env = args.optvalue(3, globals);
	return filename == null?
		loadStream( globals.STDIN, "=stdin", mode, env ):
		loadFile( filename, mode, env );
}
 
Example 8
Source File: BaseLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	args.argcheck(args.isstring(1) || args.isnil(1), 1, "filename must be string or nil");
	String filename = args.isstring(1)? args.tojstring(1): null;
	Varargs v = filename == null?
			loadStream( globals.STDIN, "=stdin", "bt", globals ):
			loadFile( args.checkjstring(1), "bt", globals );
	return v.isnil(1)? error(v.tojstring(2)): v.arg1().invoke();
}
 
Example 9
Source File: PackageLib.java    From luaj with MIT License 5 votes vote down vote up
public LuaValue call( LuaValue arg ) {
	LuaString name = arg.checkstring();
	LuaValue loaded = package_.get(_LOADED);
	LuaValue result = loaded.get(name);
	if ( result.toboolean() ) {
		if ( result == _SENTINEL )
			error("loop or previous error loading module '"+name+"'");
		return result;
	}
	
	/* else must load it; iterate over available loaders */
	LuaTable tbl = package_.get(_SEARCHERS).checktable();
	StringBuffer sb = new StringBuffer();
	Varargs loader = null;
	for ( int i=1; true; i++ ) {
		LuaValue searcher = tbl.get(i);
		if ( searcher.isnil() ) {
			error( "module '"+name+"' not found: "+name+sb );
	    }
					
	    /* call loader with module name as argument */
		loader = searcher.invoke(name);
		if ( loader.isfunction(1) )
			break;
		if ( loader.isstring(1) )
			sb.append( loader.tojstring(1) );
	}
	
	// load the module using the loader
	loaded.set(name, _SENTINEL);
	result = loader.arg1().call(name, loader.arg(2));
	if ( ! result.isnil() )
		loaded.set( name, result );
	else if ( (result = loaded.get(name)) == _SENTINEL )
		loaded.set( name, result = LuaValue.TRUE );
	return result;
}
 
Example 10
Source File: BaseLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
    args.argcheck(args.isstring(1) || args.isnil(1), 1, "filename must be string or nil");
    String filename = args.isstring(1) ? args.tojstring(1) : null;
    String mode = args.optjstring(2, "bt");
    LuaValue env = args.optvalue(3, globals);
    return filename == null ? loadStream(globals.STDIN, "=stdin", mode, env) : loadFile
            (filename, mode, env);
}
 
Example 11
Source File: BaseLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
    args.argcheck(args.isstring(1) || args.isnil(1), 1, "filename must be string or nil");
    String filename = args.isstring(1) ? args.tojstring(1) : null;
    Varargs v = filename == null ? loadStream(globals.STDIN, "=stdin", "bt", globals) :
            loadFile(args.checkjstring(1), "bt", globals);
    return v.isnil(1) ? error(v.tojstring(2)) : v.arg1().invoke();
}
 
Example 12
Source File: PackageLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public LuaValue call( LuaValue arg ) {
	LuaString name = arg.checkstring();
	LuaValue loaded = package_.get(_LOADED);
	LuaValue result = loaded.get(name);
	if ( result.toboolean() ) {
		if ( result == _SENTINEL )
			error("loop or previous error loading module '"+name+"'");
		return result;
	}
	
	/* else must load it; iterate over available loaders */
	LuaTable tbl = package_.get(_SEARCHERS).checktable();
	StringBuffer sb = new StringBuffer();
	Varargs loader = null;
	for ( int i=1; true; i++ ) {
		LuaValue searcher = tbl.get(i);
		if ( searcher.isnil() ) {
			error( "module '"+name+"' not found: "+name+sb );				
	    }
					
	    /* call loader with module name as argument */
		loader = searcher.invoke(name);
		if ( loader.isfunction(1) )
			break;
		if ( loader.isstring(1) )
			sb.append( loader.tojstring(1) );
	}
	
	// load the module using the loader
	loaded.set(name, _SENTINEL);
	result = loader.arg1().call(name, loader.arg(2));
	if ( ! result.isnil() )
		loaded.set( name, result );
	else if ( (result = loaded.get(name)) == _SENTINEL ) 
		loaded.set( name, result = LuaValue.TRUE );
	return result;
}
 
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) {
	args.argcheck(args.isstring(1) || args.isnil(1), 1, "filename must be string or nil");
	String filename = args.isstring(1)? args.tojstring(1): null;
	String mode = args.optjstring(2, "bt");
	LuaValue env = args.optvalue(3, globals);
	return filename == null? 
		loadStream( globals.STDIN, "=stdin", mode, env ):
		loadFile( filename, mode, env );
}
 
Example 14
Source File: BaseLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	args.argcheck(args.isstring(1) || args.isnil(1), 1, "filename must be string or nil");
	String filename = args.isstring(1)? args.tojstring(1): null;
	Varargs v = filename == null? 
			loadStream( globals.STDIN, "=stdin", "bt", globals ):
			loadFile( args.checkjstring(1), "bt", globals );
	return v.isnil(1)? error(v.tojstring(2)): v.arg1().invoke();			
}
 
Example 15
Source File: PackageLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue call( LuaValue arg ) {
	LuaString name = arg.checkstring();
	LuaValue loaded = package_.get(_LOADED);
	LuaValue result = loaded.get(name);
	if ( result.toboolean() ) {
		if ( result == _SENTINEL )
			error("loop or previous error loading module '"+name+"'");
		return result;
	}
	
	/* else must load it; iterate over available loaders */
	LuaTable tbl = package_.get(_SEARCHERS).checktable();
	StringBuffer sb = new StringBuffer();
	Varargs loader = null;
	for ( int i=1; true; i++ ) {
		LuaValue searcher = tbl.get(i);
		if ( searcher.isnil() ) {
			error( "module '"+name+"' not found: "+name+sb );				
	    }
					
	    /* call loader with module name as argument */
		loader = searcher.invoke(name);
		if ( loader.isfunction(1) )
			break;
		if ( loader.isstring(1) )
			sb.append( loader.tojstring(1) );
	}
	
	// load the module using the loader
	loaded.set(name, _SENTINEL);
	result = loader.arg1().call(name, loader.arg(2));
	if ( ! result.isnil() )
		loaded.set( name, result );
	else if ( (result = loaded.get(name)) == _SENTINEL ) 
		loaded.set( name, result = LuaValue.TRUE );
	return result;
}
 
Example 16
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 17
Source File: UIImageViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue setPlaceHolderImage(U view, Varargs varargs) {
    if (varargs.isstring(2)) {
        final String url = varargs.optjstring(2, null);
        final LuaFunction callback = varargs.optfunction(3, null);
        return view.setPlaceHolderImage(url, callback);
    } else if (varargs.arg(2) instanceof UDData) {//data
        final UDData data = (UDData) varargs.arg(2);
        return view.setPlaceHolderBytes(data != null ? Base64.decode(data.bytes(), Base64.NO_WRAP) : null);
    }
    return view;
}
 
Example 18
Source File: BaseLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
    args.argcheck(args.isstring(1) || args.isnil(1), 1, "filename must be string or nil");
    String filename = args.isstring(1) ? args.tojstring(1) : null;
    String mode = args.optjstring(2, "bt");
    LuaValue env = args.optvalue(3, globals);
    return filename == null ?
            loadStream(globals.STDIN, "=stdin", mode, env) :
            loadFile(filename, mode, env);
}
 
Example 19
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 20
Source File: PackageLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue call(LuaValue arg) {
         LuaString name = arg.checkstring();
         LuaValue loaded = package_.get(_LOADED);
         LuaValue result = loaded.get(name);
         if (result.toboolean()) {
             if (result == _SENTINEL)
                 error("loop or previous error loading module '" + name + "'");
             return result;
         }/* else if (globals != null && (result = globals.lazyLoad(name.checkjstring())) != null){//TODO add by song, 如果是加载自定义的内容则使用globals加载
             loaded.set(name, _SENTINEL);
             return result;
         }*/

/* else must load it; iterate over available loaders */
         LuaTable tbl = package_.get(_SEARCHERS).checktable();
         StringBuffer sb = new StringBuffer();
         Varargs loader = null;
         for (int i = 1; true; i++) {
             LuaValue searcher = tbl.get(i);
             if (searcher.isnil()) {
                 error("module '" + name + "' not found: " + name + sb);
             }

    /* call loader with module name as argument */
             loader = searcher.invoke(name);
             if (loader.isfunction(1))
                 break;
             if (loader.isstring(1))
                 sb.append(loader.tojstring(1));
         }

         // load the module using the loader
         loaded.set(name, _SENTINEL);
         try {
             result = loader.arg1().call(name, loader.arg(2));
             if (!result.isnil())
                 loaded.set(name, result);
             else if ((result = loaded.get(name)) == _SENTINEL)
                 loaded.set(name, result = LuaValue.TRUE);

             return result;
         } catch (Exception e) {
             return NIL;
         }
     }