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

The following examples show how to use org.luaj.vm2.LuaValue#optint() . 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 4 votes vote down vote up
public LuaValue call(LuaValue arg1, LuaValue arg2) {
    throw new LuaError(arg1.isnil() ? null : arg1.tojstring(), arg2.optint(1));
}
 
Example 2
Source File: UDSpannableString.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
private void initSpannableStringBuilder(LuaValue text, LuaValue config) {
    SpannableStringBuilder spannableStringBuilder = getSpannableStringBuilder();
    if (text != null && text.isstring()) {
        spannableStringBuilder = spannableStringBuilder.append(text.tojstring());
    }

    if (spannableStringBuilder.length() > 0) {
        if (config != null && config.istable()) {
             int end = spannableStringBuilder.length();
             int fontSize = DimenUtil.spToPx(config.get("fontSize").optint(-1));
             Integer fontColor = ColorUtil.parse(LuaUtil.getValue(config, "fontColor"));
             String fontName = config.get("fontName").optjstring(null);

             LuaValue weightValue = config.get("fontWeight");
             int fontWeight = LuaUtil.isNumber(weightValue) ? weightValue.optint(UDFontWeight.WEIGHT_NORMAL_INT) : UDFontWeight.getValue(weightValue.optjstring(UDFontWeight.WEIGHT_NORMAL));

             LuaValue styleValue = config.get("fontStyle");
             int fontStyle = LuaUtil.isNumber(styleValue) ? styleValue.optint(Typeface.NORMAL) : UDFontStyle.getValue(styleValue.optjstring(UDFontStyle.STYLE_NORMAL));

             Integer backgroundColor = ColorUtil.parse(LuaUtil.getValue(config, "backgroundColor"));
             boolean strikethrough = config.get("strikethrough").optboolean(false);
             boolean underline = config.get("underline").optboolean(false);

            if (fontSize != -1) {//字体大小
                spannableStringBuilder.setSpan(new AbsoluteSizeSpan(fontSize), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (fontColor != null) {//字体颜色
                spannableStringBuilder.setSpan(new ForegroundColorSpan(fontColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (fontName != null && getLuaResourceFinder() != null) {//字体
                spannableStringBuilder.setSpan(new CustomTypefaceSpan(fontName, getLuaResourceFinder().findTypeface(fontName)), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (fontWeight != -1 && fontWeight > UDFontWeight.WEIGHT_NORMAL_INT) {//文字Weight
                spannableStringBuilder.setSpan(new WeightStyleSpan(fontWeight), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (fontStyle != -1 && (fontStyle >= Typeface.NORMAL && fontStyle <= Typeface.BOLD_ITALIC)) {//文字样式
                spannableStringBuilder.setSpan(new StyleSpan(fontStyle), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (backgroundColor != null) {//背景色
                spannableStringBuilder.setSpan(new BackgroundColorSpan(backgroundColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (strikethrough) {//删除线
                spannableStringBuilder.setSpan(new StrikethroughSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (underline) {//下划线
                spannableStringBuilder.setSpan(new UnderlineSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
}
 
Example 3
Source File: BaseLib.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue call(LuaValue arg1, LuaValue arg2) {
	throw arg1.isnil()? new LuaError(null, arg2.optint(1)): 
		arg1.isstring()? new LuaError(arg1.tojstring(), arg2.optint(1)): 
			new LuaError(arg1);
}
 
Example 4
Source File: BaseLib.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
public LuaValue call(LuaValue arg1, LuaValue arg2) {
    throw arg1.isnil() ? new LuaError(null, arg2.optint(1)) : arg1.isstring() ? new
            LuaError(arg1.tojstring(), arg2.optint(1)) : new LuaError(arg1);
}
 
Example 5
Source File: BaseLib.java    From luaj with MIT License 4 votes vote down vote up
public LuaValue call(LuaValue arg1, LuaValue arg2) {
	if (arg1.isnil()) throw new LuaError(NIL);
	if (!arg1.isstring() || arg2.optint(1) == 0) throw new LuaError(arg1);
	throw new LuaError(arg1.tojstring(), arg2.optint(1));
}
 
Example 6
Source File: LuaUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 2 votes vote down vote up
/**
 * java 从 0 开始
 *
 * @param pos
 * @return
 */
public static int toJavaInt(LuaValue pos) {
    return pos.optint(1) - 1;
}