org.luaj.vm2.Varargs Java Examples

The following examples show how to use org.luaj.vm2.Varargs. 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: LuaGeneration.java    From Cubes with MIT License 6 votes vote down vote up
public static LuaValue[] convertParamsToLua(Object instance, Object[] objects, final Callable supercall) {
  LuaValue[] parameters = new LuaValue[objects.length + 2];
  parameters[0] = LuaConversion.convertToLua(instance);
  for (int i = 0; i < objects.length; i++) {
    parameters[i + 1] = LuaConversion.convertToLua(objects[i]);
  }
  parameters[parameters.length - 1] = new VarArgFunction() {
    @Override
    public Varargs invoke(Varargs args) {
      try {
        Object o = supercall.call();
        return LuaConversion.convertToLua(o);
      } catch (Exception e) {
        throw new DynamicDelegationError("Supercall threw exception - called from supplied delegation", e);
      }
    }
  };
  return parameters;
}
 
Example #2
Source File: UDSystem.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
    LuaTable table = new LuaTable();
    table.set("device", AndroidUtil.getDevice());
    table.set("brand", AndroidUtil.getBrand());
    table.set("product", AndroidUtil.getProduct());
    table.set("manufacturer", AndroidUtil.getManufacturer());

    //screen size
    int[] screenSize = AndroidUtil.getWindowSizeInDp(getContext());
    table.set("window_width", screenSize[0]);
    table.set("window_height", screenSize[1]);

    //action bar height
    int actionBarHeight = AndroidUtil.getActionBarHeightInDp(getContext());
    table.set("nav_height", actionBarHeight);
    int bottomNavHeight = AndroidUtil.getNavigationBarHeightInDp(getContext());
    table.set("bottom_nav_height", bottomNavHeight);
    int statusBarHeight = AndroidUtil.getStatusBarHeightInDp(getContext());
    table.set("status_bar_height", statusBarHeight);
    return table;
}
 
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: UDActionBar.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
     ActionBar actionBar = LuaViewUtil.getActionBar(getGlobals());
    if (actionBar != null) {
         CharSequence title = actionBar.getTitle();
        if (!TextUtils.isEmpty(title)) {
            return valueOf(title.toString());
        } else {
             View view = actionBar.getCustomView();
            if (view != null) {
                 Object tag = view.getTag(Constants.RES_LV_TAG);
                return tag instanceof LuaValue ? (LuaValue) tag : NIL;
            }
        }
    }
    return NIL;
}
 
Example #5
Source File: StringLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
/**
 * string.byte (s [, i [, j]])
 * <p>
 * Returns the internal numerical codes of the
 * characters s[i], s[i+1], ..., s[j]. The default value for i is 1; the
 * default value for j is i.
 * <p>
 * Note that numerical codes are not necessarily portable across platforms.
 *
 * @param args the calling args
 */
static Varargs byte_(Varargs args) {
    LuaString s = args.checkstring(1);
    int l = s.m_length;
    int posi = posrelat(args.optint(2, 1), l);
    int pose = posrelat(args.optint(3, posi), l);
    int n, i;
    if (posi <= 0) posi = 1;
    if (pose > l) pose = l;
    if (posi > pose) return NONE;  /* empty interval; return no values */
    n = (int) (pose - posi + 1);
    if (posi + n <= pose)  /* overflow? */
        error("string slice too long");
    LuaValue[] v = new LuaValue[n];
    for (i = 0; i < n; i++)
        v[i] = valueOf(s.luaByte(posi + i - 1));
    return varargsOf(v);
}
 
Example #6
Source File: UDData.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public UDData(Globals globals, LuaValue metatable, Varargs varargs) {
    super(new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE), globals, metatable, varargs);
    ByteArrayOutputStream byteArrayBuffer = (ByteArrayOutputStream) userdata();
    if (initParams != null) {
        try {
            for (int i = 0; i < initParams.narg(); i++) {
                Object obj = initParams.arg(i + 1);
                String str = String.valueOf(obj);
                byte[] data = str.getBytes(DEFAULT_ENCODE);
                byteArrayBuffer.write(data, 0, data.length);
            }
        } catch (UnsupportedEncodingException e) {
        }
    }
}
 
Example #7
Source File: VenvyLVSvgeImageView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public VenvyLVSvgeImageView(Globals globals, LuaValue metaTable, Varargs varargs) {
    super(globals.getContext());
    this.mLuaUserdata = new VenvyUDSvgaImageView(this, globals, metaTable, varargs);

    iSvgaImageView = VenvyImageFactory.createSvgaImage(getContext());
    if (iSvgaImageView != null && iSvgaImageView instanceof View) {
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        ((View) iSvgaImageView).setLayoutParams(params);
        addView((View) iSvgaImageView);
    }
}
 
Example #8
Source File: UIViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置位置
 *
 * @param view
 * @param varargs
 * @return
 */
public Varargs padding(U view, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setPadding(view, varargs);
    } else {
        return getPadding(view, varargs);
    }
}
 
Example #9
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 #10
Source File: BaseVarArgUICreator.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
    if (LuaViewConfig.isLibsLazyLoad()) {
        metatable = LuaViewManager.createMetatable(libClass);
    }

    ILVView view = createView(globals, metatable, args);
    if (globals.container != null && view instanceof View && ((View) view).getParent() == null) {
        LuaViewUtil.addView(globals.container, (View) view, args);
    }
    return view.getUserdata();
}
 
Example #11
Source File: SpannableStringMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Varargs invoke(int code, U target, Varargs varargs) {
    final int optcode = code - super.getAllFunctionNames().size();
    switch (optcode) {
        case 0:
            return append(target, varargs);
    }
    return super.invoke(code, target, varargs);
}
 
Example #12
Source File: NewIndexFunction.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
    LuaValue func = metatable.get(args.arg(2));
    if (func.isfunction()) {//函数调用
        func.invoke(varargsOf(args.arg(1), args.arg(3)));
    }
    return NONE;
}
 
Example #13
Source File: ReadOnlyLuaTable.java    From Cubes with MIT License 5 votes vote down vote up
public ReadOnlyLuaTable(LuaValue table) {
  presize(table.length(), 0);
  for (Varargs n = table.next(LuaValue.NIL); !n.arg1().isnil(); n = table
          .next(n.arg1())) {
    LuaValue key = n.arg1();
    LuaValue value = n.arg(2);
    super.rawset(key, value.istable() ? new ReadOnlyLuaTable(value) : value);
  }
}
 
Example #14
Source File: UIViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public Varargs getCenter(U view, Varargs varargs) {
    float x = 0.0f, y = 0.0f;
    if (view != null && view.getView() != null) {
        x = view.getX() + view.getWidth() / 2.0f;
        y = view.getY() + view.getHeight() / 2.0f;
    }
    return varargsOf(valueOf(DimenUtil.pxToDpi(x)), valueOf(DimenUtil.pxToDpi(y)));
}
 
Example #15
Source File: BaseLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	int n = args.narg()-1;
	if ( args.arg1().equals(valueOf("#")) )
		return valueOf(n);
	int i = args.checkint(1);
	if ( i == 0 || i < -n )
		argerror(1,"index out of range");
	return args.subargs(i<0? n+i+2: i+1);
}
 
Example #16
Source File: UIImageViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置图片Blur
 *
 * @param view    UDImageView
 * @param varargs Varargs
 * @return LuaValue
 */
public LuaValue imageBlur(U view, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setImageBlur(view, varargs);
    } else {
        return getImage(view, varargs);
    }
}
 
Example #17
Source File: VenvyAcrCloudMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue stopAcrRecognize(U target, Varargs args) {
    try {
        target.stopRecognize();
    } catch (Exception e) {
        VenvyLog.e(VenvyAcrCloudMapper.class.getName(), e);
    }
    return LuaValue.NIL;
}
 
Example #18
Source File: BaseLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs loadStream(InputStream is, String chunkname, String mode, LuaValue env) {
    try {
        if (is == null) {
            return varargsOf(NIL, valueOf("not found: " + chunkname));
        }
        return globals.load(is, chunkname, mode, env);
    } catch (Exception e) {
        return varargsOf(NIL, valueOf(e.getMessage()));
    }
}
 
Example #19
Source File: StringLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
MatchState(Varargs args, LuaString s, LuaString pattern) {
    this.s = s;
    this.p = pattern;
    this.args = args;
    this.level = 0;
    this.cinit = new int[MAX_CAPTURES];
    this.clen = new int[MAX_CAPTURES];
}
 
Example #20
Source File: UIRefreshLayoutViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Varargs invoke(int code, U target, Varargs varargs) {
    switch (code - super.getAllFunctionNames().size()) {
        case 0:
            return stopRefreshing(target, varargs);
        case 1:
            return setRefreshingOffset(target, varargs);
    }
    return super.invoke(code, target, varargs);
}
 
Example #21
Source File: StringLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaValue f = args.checkfunction(1);
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	try {
		DumpState.dump( ((LuaClosure)f).p, baos, args.optboolean(2, true) );
		return LuaString.valueUsing(baos.toByteArray());
	} catch (IOException e) {
		return error( e.getMessage() );
	}
}
 
Example #22
Source File: PackageLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
    LuaString name = args.checkstring(1);
    LuaValue val = package_.get(_PRELOAD).get(name);
    return val.isnil() ?
            valueOf("\n\tno field package.preload['" + name + "']") :
            val;
}
 
Example #23
Source File: VenvyKeyboardMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue keyboardCallback(U target, Varargs varargs) {
    final LuaFunction callback = varargs.optfunction(2, null);
    if (callback != null && callback.isfunction()) {
        return target.setKeyboardCallback(callback);
    }
    return LuaValue.NIL;
}
 
Example #24
Source File: UIViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置3D变换矩阵
 *
 * @param view
 * @param varargs
 * @return
 */
@Deprecated
public LuaValue transform3D(U view, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setTransform3D(view, varargs);
    } else {
        return getTransform3D(view, varargs);
    }
}
 
Example #25
Source File: TestLuaJC.java    From luaj with MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	if (args.length > 0)
		filename = args[0];
	System.out.println("filename: "+filename);
	try {
		
		// create an environment to run in
		globals = JsePlatform.standardGlobals();

		// print the chunk as a closure, and pretty-print the closure.
		LuaValue f = globals.loadfile(filename).arg1();
		Prototype p = f.checkclosure().p;
		Print.print(p);

		// load into a luajc java-bytecode based chunk by installing the LuaJC compiler first
		if ( ! (args.length>0 && args[0].equals("nocompile")) ) {
			LuaJC.install(globals);
			f = globals.loadfile(filename).arg1();
		}

		// call with arguments
		Varargs v = f.invoke(LuaValue.NONE);
		
		// print the result
		System.out.println("result: "+v);

		// Write out the files.
		// saveClasses();
		
	} catch ( Throwable e ) {
		e.printStackTrace();
	}
}
 
Example #26
Source File: DebugLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaValue func = args.checkfunction(1);
	int up = args.checkint(2);
	if ( func instanceof LuaClosure ) {
		LuaClosure c = (LuaClosure) func;
		if ( c.upValues != null && up > 0 && up <= c.upValues.length ) {
			return valueOf(c.upValues[up-1].hashCode());
		}
	}
	return NIL;
}
 
Example #27
Source File: UILoadingViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 颜色
 *
 * @param view
 * @param varargs
 * @return
 */
@LuaViewApi(revisions = {"支持alpha"})
public LuaValue color(U view, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setColor(view, varargs);
    } else {
        return getColor(view, varargs);
    }
}
 
Example #28
Source File: IoLib.java    From luaj with MIT License 5 votes vote down vote up
private static Varargs ioclose(File f) throws IOException {
	if ( f.isstdfile() )
		return errorresult("cannot close standard file");
	else {
		f.close();
		return successresult();
	}
}
 
Example #29
Source File: UIViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public Varargs scaleX(U view, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setScaleX(view, varargs);
    } else {
        return getScaleX(view, varargs);
    }
}
 
Example #30
Source File: VenvyActivityLifeCycleMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public Varargs onPageWillDisappear(U target, Varargs varargs) {
    return LuaValue.NIL;
}