Java Code Examples for org.luaj.vm2.LuaValue#varargsOf()

The following examples show how to use org.luaj.vm2.LuaValue#varargsOf() . 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 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 3
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 4
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 5
Source File: UDApplet.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
    Pair<Float, Float> pair = VisionUtil.getVisionProgramSize(platform.isNvgShow());

    LuaValue[] luaValue = new LuaValue[]{LuaValue.valueOf(pair.first), LuaValue.valueOf(pair.second)};
    return LuaValue.varargsOf(luaValue);
}
 
Example 6
Source File: LVViewManagerPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
    final int fixIndex = VenvyLVLibBinder.fixIndex(args);
    if (args.narg() > fixIndex) {
        String text = LuaUtil.getString(args, fixIndex + 1);
        final Float width = LuaUtil.getFloat(args, fixIndex + 2);
        Float size = LuaUtil.getFloat(args, fixIndex + 3);
        float mathWidth = 0f;
        float mathHeight = 0f;
        if (!TextUtils.isEmpty(text)) {
            Paint paint = new Paint();
            if (size != null) {
                paint.setTextSize(size);
            }
            float widthMeasureSpec = paint.measureText(text);
            Rect bounds = new Rect();
            paint.getTextBounds(text, 0, text.length(), bounds);
            float hightMeasureSpec = bounds.height();
            if (width >= widthMeasureSpec) {
                mathWidth = widthMeasureSpec;
            } else {
                mathWidth = width;
            }
            int charNumInThisLine = paint.breakText(text, 0, text.length(), true, mathWidth, null);
            if (charNumInThisLine >= text.length()) {
                mathHeight = (float) (hightMeasureSpec * (Math.ceil(text.length() / charNumInThisLine)));
            } else {
                mathHeight = (float) (hightMeasureSpec * (Math.ceil(text.length() / charNumInThisLine) + 1));
            }
        }
        LuaValue[] luaValue = new LuaValue[]{LuaValue.valueOf(mathWidth), LuaValue.valueOf(mathHeight)};
        return LuaValue.varargsOf(luaValue);
    }
    return valueOf(0);
}
 
Example 7
Source File: LuaTest.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Test
public void testVarArgs() {
    final Globals theGlobals = new Globals();
    LuaC.install(theGlobals);
    final Varargs theArguments = LuaValue.varargsOf(new LuaValue[]{
            LuaInteger.valueOf(100),
            LuaInteger.valueOf(200)
    });
}
 
Example 8
Source File: LuaTest.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Test
public void testCall() throws IOException {
    final Globals theGlobals = new Globals();
    LuaC.install(theGlobals);
    final Prototype thePrototype = theGlobals.compilePrototype(new StringReader("function add(a,b) return a + b end"), "script");
    new LuaClosure(thePrototype, theGlobals).call();
    final LuaValue theFunction = theGlobals.get("add");
    Assert.assertFalse(theFunction.isnil());
    final Varargs theArguments = LuaValue.varargsOf(new LuaValue[] {
            LuaInteger.valueOf(100),
            LuaInteger.valueOf(200)
    });
    final LuaInteger theResult = (LuaInteger) theFunction.invoke(theArguments);
    Assert.assertEquals("300", theResult.tojstring());
}
 
Example 9
Source File: LuaTest.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Test
public void testCallStringResult() throws IOException {
    final Globals theGlobals = new Globals();
    LuaC.install(theGlobals);
    final Prototype thePrototype = theGlobals.compilePrototype(new StringReader("function add(a,b) return 'hello' end"), "script");
    new LuaClosure(thePrototype, theGlobals).call();
    final Varargs theArguments = LuaValue.varargsOf(new LuaValue[] {
            LuaInteger.valueOf(100),
            LuaInteger.valueOf(200)
    });
    final LuaValue theFunction = theGlobals.get("add");
    final LuaValue theValue = (LuaValue) theFunction.invoke(theArguments);
    Assert.assertTrue(theValue.isstring());
    Assert.assertEquals("hello", theValue.tojstring());
}