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

The following examples show how to use org.luaj.vm2.Varargs#narg() . 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: LVPreLoadPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
@Override
public LuaValue invoke(Varargs args) {
    int fixIndex = VenvyLVLibBinder.fixIndex(args);
    if (args.narg() > fixIndex) {
        LuaTable table = LuaUtil.getTable(args, fixIndex + 1);
        Map<String, String> map = LuaUtil.toMap(table);
        if (map == null || map.size() <= 0) {
            return LuaValue.NIL;
        }
        String[] preLoadUrls = new String[map.size()];
        for (Map.Entry<String, String> entry : map.entrySet()) {
            preLoadUrls[Integer.valueOf(entry.getKey()) - 1] = entry.getValue();
        }
        mPlatform.preloadMedia(preLoadUrls, null);
    }
    return LuaValue.NIL;
}
 
Example 2
Source File: VenvyUDHttpRequestCallback.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
private LuaValue startConnect(Varargs args, LVHttpBridge lvHttpBridge, RequestType requestType) {
    final int fixIndex = VenvyLVLibBinder.fixIndex(args);
    int requestId = -1;
    if (args.narg() > fixIndex) {
        String url = LuaUtil.getString(args, 2);
        LuaTable table = LuaUtil.getTable(args, 3);
        LuaFunction callback = LuaUtil.getFunction(args, 4);
        switch (requestType) {
            case GET:
                requestId = lvHttpBridge.get(url, table, callback);
                break;
            case POST:
                requestId = lvHttpBridge.post(url, table, callback);
                break;
            case PUT:
                requestId = lvHttpBridge.put(url, table, callback);
                break;
            case DELETE:
                requestId = lvHttpBridge.delete(url, table, callback);
                break;
        }
    }
    return LuaValue.valueOf(requestId);
}
 
Example 3
Source File: LVPreLoadPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
@Override
public LuaValue invoke(Varargs args) {
    int fixIndex = VenvyLVLibBinder.fixIndex(args);
    if (args.narg() > fixIndex) {
        LuaTable table = LuaUtil.getTable(args, fixIndex + 1);
        Map<String, String> map = LuaUtil.toMap(table);
        if (map == null || map.size() <= 0) {
            return LuaValue.NIL;
        }
        String[] preLoadUrls = new String[map.size()];
        for (Map.Entry<String, String> entry : map.entrySet()) {
            preLoadUrls[Integer.valueOf(entry.getKey()) - 1] = entry.getValue();
        }
        mPlatform.preloadImage(preLoadUrls, null);
    }
    return LuaValue.NIL;
}
 
Example 4
Source File: LVLoginPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
    final int fixIndex = VenvyLVLibBinder.fixIndex(args);
    if (args.narg() > fixIndex) {
        if (mPlatform != null && mPlatform.getPlatformLoginInterface() != null) {
            final LuaFunction callback = LuaUtil.getFunction(args, fixIndex + 1);
            mPlatform.getPlatformLoginInterface().login(new IPlatformLoginInterface.LoginCallback() {
                @Override
                public void loginSuccess(PlatformUserInfo platformUserInfo) {
                    LuaUtil.callFunction(callback, JsonUtil.toLuaTable(platformUserInfo.toString()));
                }

                @Override
                public void loginError(LoginException loginException) {
                    LuaUtil.callFunction(callback, LuaValue.NIL);
                }
            });
        }
    }
    return LuaValue.NIL;
}
 
Example 5
Source File: LVLoginPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
    final int fixIndex = VenvyLVLibBinder.fixIndex(args);
    if (args.narg() > fixIndex) {
        if (mPlatform != null && mPlatform.getPlatformLoginInterface() != null) {
            Integer value = LuaUtil.getInt(args, fixIndex + 1);
            String currentUrl = LuaUtil.getString(args, fixIndex + 2);
            String ssid = LuaUtil.getString(args, fixIndex + 3);
            IPlatformLoginInterface.ScreenChangedInfo screenChanged = new IPlatformLoginInterface.ScreenChangedInfo();
            screenChanged.url = currentUrl;
            screenChanged.ssid = ssid;
            screenChanged.screenType = value != null ? value : 1;
            mPlatform.getPlatformLoginInterface().screenChanged(screenChanged);
        }
    }
    return LuaValue.NIL;
}
 
Example 6
Source File: TimerMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 重复次数
 * TODO 修改次数控制
 * @param udTimer
 * @param varargs
 * @return
 */
@LuaViewApi(since = VmVersion.V_511)
@Deprecated
public LuaValue repeatCount(U udTimer, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setRepeatCount(udTimer, varargs);
    } else {
        return getRepeatCount(udTimer, varargs);
    }
}
 
Example 7
Source File: UIViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置left坐标
 *
 * @param view    UIView
 * @param varargs
 * @return
 */
public LuaValue left(U view, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setLeft(view, varargs);
    } else {
        return getLeft(view, varargs);
    }
}
 
Example 8
Source File: UITextViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 字体大小
 *
 * @param view    UDTextView
 * @param varargs Varargs
 * @return LuaValue
 */
@Deprecated
public LuaValue textSize(U view, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setTextSize(view, varargs);
    } else {
        return getTextSize(view, varargs);
    }
}
 
Example 9
Source File: UIHorizontalScrollViewMethodMapper.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 showScrollIndicator(U view, Varargs varargs) {
    if (varargs.narg() > 1) {
        Boolean value = LuaUtil.getBoolean(varargs, false);
        return view.showScrollIndicator(value != null ? value : false);
    }
    return LuaValue.NIL;
}
 
Example 10
Source File: UIViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置View阴影颜色
 *
 * @param view
 * @param varargs
 * @return
 */
@Deprecated
public LuaValue shadowColor(U view, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setShadowColor(view, varargs);
    } else {
        return getShadowColor(view, varargs);
    }
}
 
Example 11
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
 */
@Deprecated
public Varargs initParams(U view, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setInitParams(view, varargs);
    } else {
        return getInitParams(view, varargs);
    }
}
 
Example 12
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 13
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
    LuaThread t = args.narg() > 0 ? args.checkthread(1) : globals.running;
    return varargsOf(
            t.hookfunc != null ? t.hookfunc : NIL,
            valueOf((t.hookcall ? "c" : "") + (t.hookline ? "l" : "") + (t.hookrtrn ? "r" : "")),
            valueOf(t.hookcount));
}
 
Example 14
Source File: IoLib.java    From luaj with MIT License 5 votes vote down vote up
private Varargs ioread(File f, Varargs args) throws IOException {
	int i,n=args.narg();
	if (n == 0) return freadline(f,false);
	LuaValue[] v = new LuaValue[n];
	LuaValue ai,vi;
	LuaString fmt;
	for ( i=0; i<n; ) {
		item: switch ( (ai = args.arg(i+1)).type() ) {
			case LuaValue.TNUMBER:
				vi = freadbytes(f,ai.toint());
				break item;
			case LuaValue.TSTRING:
				fmt = ai.checkstring();
				if ( fmt.m_length >= 2 && fmt.m_bytes[fmt.m_offset] == '*' ) {
					switch ( fmt.m_bytes[fmt.m_offset+1] ) {
					case 'n': vi = freadnumber(f); break item;
					case 'l': vi = freadline(f,false); break item;
					case 'L': vi = freadline(f,true); break item;
					case 'a': vi = freadall(f); break item;
					}
				}
			default:
				return argerror( i+1, "(invalid format)" );
		}
		if ( (v[i++] = vi).isnil() )
			break;
	}
	return i==0? NIL: varargsOf(v, 0, i);
}
 
Example 15
Source File: UITextViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获得文字行数
 *
 * @param view
 * @param varargs
 * @return
 */
public LuaValue lines(U view, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setLines(view, varargs);
    } else {
        return getLines(view, varargs);
    }
}
 
Example 16
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
 */
@Deprecated
public Varargs rotationXY(U view, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setRotationXY(view, varargs);
    } else {
        return getRotationXY(view, varargs);
    }
}
 
Example 17
Source File: TableLib.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaTable t = args.checktable(1);
	switch (args.narg()) {
	case 1: return t.unpack();
	case 2: return t.unpack(args.checkint(2));
	default: return t.unpack(args.checkint(2), args.checkint(3));
	}
}
 
Example 18
Source File: LVEventPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
@Override
        public Varargs invoke(Varargs args) {
            final int fixIndex = VenvyLVLibBinder.fixIndex(args);
            if (mPlatform == null || mPlatform.getContentViewGroup() == null) {
                return LuaValue.FALSE;
            }
            if (args.narg() > fixIndex) {
                final String urlString = LuaUtil.getString(args, fixIndex + 1);
                final LuaTable table = LuaUtil.getTable(args, fixIndex + 2);
                if (TextUtils.isEmpty(urlString)) {
                    return LuaValue.FALSE;
                }
                Uri uri = Uri.parse(new String(VenvyBase64.decode(urlString)));
                PostInfo info = VenvyRouterManager.getInstance().setUri(uri);
                Set<String> params = uri.getQueryParameterNames();
                HashMap<String, String> map = new HashMap<>();
                if (table != null) {
                    map.put("data", JsonUtil.toString(table));
                }
                if (params != null && params.size() > 0) {
                    for (String key : params) {
                        String value = uri.getQueryParameter(key);
                        if (!TextUtils.isEmpty(value)) {
                            map.put(key, value);
                        }
                    }
                }
                if(!map.keySet().contains("miniAppId")){
                    // 如果过来的uri中不带miniAppId,则需要尝试去table中找miniAppId put进 map里
                    try {
                        JSONObject jsonObject = new JSONObject(JsonUtil.toString(table));
                        JSONObject miniAppInfo = jsonObject.optJSONObject("miniAppInfo");
                        if(miniAppInfo != null){
                            String miniAppId = miniAppInfo.optString("miniAppId");
                            if(!TextUtils.isEmpty(miniAppId)){
                                map.put("miniAppId",miniAppId);
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

                if (map.size() > 0) {
                    info.withSerializable("data", map);
                }
                String protocolHost = uri.getHost();
                if (protocolHost.equalsIgnoreCase("defaultLuaView")) {
                    // A类容器内部跳转
                    info.withTargetViewParent(mPlatform.getContentViewGroup()).withTargetPlatform("platform", mPlatform).navigation();

                } else if (protocolHost.equalsIgnoreCase("topLuaView")) {
                    // 标签小程序 - [top level]
//                    Bundle bundle = new Bundle();
//                    bundle.putString(VenvyObservableTarget.Constant.CONSTANT_LUA_NAME, info.getBundle().getString("template"));
//                    bundle.putString(VenvyObservableTarget.Constant.CONSTANT_ID, info.getBundle().getString("id"));
                    ObservableManager.getDefaultObserable().sendToTarget(VenvyObservableTarget.TAG_ADD_LUA_SCRIPT_TO_TOP_LEVEL, info.getBundle());

                } else if (protocolHost.equalsIgnoreCase("applets")) {
                    String type = info.getBundle().getString("type");
                    String appType = info.getBundle().getString("appType");
                    if (TextUtils.isEmpty(appType)) {
                        VenvyLog.d("appType is null");
                        // appType为空默认指定为lua
                        appType = String.valueOf(VenvyObservableTarget.Constant.CONSTANT_APP_TYPE_LUA);
                    }
                    VenvyLog.d("type is " + type + " , appType is " + appType);
                    if (TextUtils.isEmpty(type)) {
                        // B类小程序内部跳转
                        info.withTargetViewParent(mPlatform.getContentViewGroup()).withTargetPlatform("platform", mPlatform).navigation();
                        ObservableManager.getDefaultObserable().sendToTarget(VenvyObservableTarget.TAG_ADD_LUA_SCRIPT_TO_VISION_PROGRAM, null);

                    } else {
                        // 发起一个视联网小程序
                        Bundle bundle = new Bundle();
                        bundle.putString(VenvyObservableTarget.KEY_APPLETS_ID, info.getBundle().getString("appletId"));
                        bundle.putString(VenvyObservableTarget.KEY_ORIENTATION_TYPE, type);
                        bundle.putString(VenvyObservableTarget.Constant.CONSTANT_APP_TYPE, appType);
                        if (table != null) {
                            bundle.putString(VenvyObservableTarget.Constant.CONSTANT_DATA, JsonUtil.toString(table));
                        }
                        ObservableManager.getDefaultObserable().sendToTarget(VenvyObservableTarget.TAG_LAUNCH_VISION_PROGRAM, bundle);
                    }


                }
                return LuaValue.TRUE;
            }
            return LuaValue.FALSE;
        }
 
Example 19
Source File: IoLib.java    From XPrivacyLua with GNU General Public License v3.0 4 votes vote down vote up
private static Varargs iowrite(File f, Varargs args) throws IOException {
	for ( int i=1, n=args.narg(); i<=n; i++ )
		f.write( args.checkstring(i) );
	return f;
}
 
Example 20
Source File: UIButtonMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 获取按钮点击是否高亮
 *
 * @param view
 * @param varargs
 * @return
 */
@Deprecated
public LuaValue showsTouchWhenHighlighted(U view, Varargs varargs) {
    return varargs.narg() > 1 ?
            view.setHighlightColor(0) :
            valueOf(view.getHighlightColor() == 0);
}