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

The following examples show how to use org.luaj.vm2.LuaValue#optjstring() . 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: LuaViewUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * get text of given value
 *
 * @param inputValue
 * @return
 */
public static CharSequence getText(LuaValue inputValue) {
    LuaValue result = (inputValue != null && !inputValue.isnil()) ? inputValue : LuaValue.NIL;
    if (result instanceof UDSpannableString) {
        return ((UDSpannableString) result).getSpannableStringBuilder();
    } else {
        return result.optjstring("");
    }
}
 
Example 2
Source File: LuaUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * convert luavalue to charsequence
 *
 * @param luaValue
 * @return
 */
public static CharSequence toText(LuaValue luaValue) {
    if (LuaUtil.isString(luaValue)) {
        return luaValue.optjstring(null);
    } else if (LuaUtil.isUserdata(luaValue)) {
        if (luaValue instanceof UDSpannableString) {
            return ((UDSpannableString) luaValue).getSpannableStringBuilder();
        }
    }
    return null;
}
 
Example 3
Source File: VenvyLVLibBinder.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public static String luaValueToString(LuaValue luaValue) {
    String result = "";
    if (LuaUtil.isString(luaValue)) {
        result = luaValue.optjstring(null);
    }
    return result;
}
 
Example 4
Source File: LVCallbackPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
@Override
public LuaValue invoke(Varargs args) {
    int fixIndex = VenvyLVLibBinder.fixIndex(args);
    Integer type = LuaUtil.getInt(args, fixIndex + 1);//事件类型
    LuaValue adId = args.arg(fixIndex + 2);//广告ID
    LuaValue adName = args.arg(fixIndex + 3);//广告类型名
    LuaValue actionType = args.arg(fixIndex + 4);//处理类型
    WidgetInfo.WidgetActionType mWidgetActionType = WidgetInfo.WidgetActionType.findTypeById(actionType != null ? actionType.optint(0) : 0);
    LuaValue url = args.arg(fixIndex + 5);//外链Url
    if (type == null) {
        return LuaValue.NIL;
    }
    if (mPlatform == null) {
        return LuaValue.NIL;
    }
    String mAdId = adId != null ? adId.optjstring(null) : null;
    String mAdName = adName != null ? adName.optjstring(null) : null;
    String mUrl = url != null ? url.optjstring(null) : null;
    WidgetInfo widgetInfo = new WidgetInfo.Builder()
            .setAdId(mAdId).setWidgetActionType(mWidgetActionType)
            .setUrl(mUrl).setWidgetName(mAdName)
            .build();
    switch (type) {
        case 1:
            if (mPlatform.getPrepareShowListener() != null && mAdId != null) {
                mPlatform.getPrepareShowListener().prepareShow(widgetInfo);
            }
            break;

        case 2:
            if (mPlatform.getWidgetShowListener() != null && mAdId != null) {
                mPlatform.getWidgetShowListener().onShow(widgetInfo);
            }

            break;

        case 3:
            if (mPlatform.getWidgetClickListener() != null && mAdId != null) {
                mPlatform.getWidgetClickListener().onClick(widgetInfo);
            }
            break;

        case 4:
            if (mPlatform.getWidgetCloseListener() != null && mAdId != null) {
                mPlatform.getWidgetCloseListener().onClose(widgetInfo);
            }
            break;
        case 5:
            if (mPlatform.getWedgeListener() != null && mAdId != null) {
                mPlatform.getWedgeListener().goBack();
            }
            break;
    }

    return LuaValue.NIL;
}