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

The following examples show how to use org.luaj.vm2.Varargs#arg() . 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: LVCachePlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
    int fixIndex = VenvyLVLibBinder.fixIndex(args);
    LuaValue luaKey = args.arg(fixIndex + 1);
    String key = luaValueToString(luaKey);
    SharedPreferences spf = App.getContext().getSharedPreferences(cacheFileName, Activity.MODE_PRIVATE);
    final Map<String, ?> spfValues = spf.getAll();
    if (spfValues == null) {
        return null;
    }
    LuaTable table = new LuaTable();
    Set<String> keys = spfValues.keySet();
    for (String s : keys) {
        //包含指定key
        if (s.contains(key)) {
            String value = (String) spfValues.get(s);
            if (value == null) {
                value = "";
            }
            table.set(LuaValue.valueOf(s), LuaValue.valueOf(value));
        }
    }
    return table;
}
 
Example 2
Source File: LuaUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
/**
 * get value of given type, from varargs in position [poslist]
 *
 * @param type
 * @param varargs
 * @param poslist
 * @return
 */
private static Object getValue(int type, Varargs varargs, Object defaultValue, int... poslist) {
    Object result = null;
    if (varargs != null) {
        if (poslist != null && poslist.length > 0) {
            LuaValue value = null;
            for (int i = 0; i < poslist.length; i++) {
                if (varargs.narg() >= poslist[i]) {
                    value = varargs.arg(poslist[i]);
                    result = parseValue(type, value);
                }
                if (result != null) {
                    break;
                }
            }
        }
    }
    return result != null ? result : defaultValue;
}
 
Example 3
Source File: UDApplet.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
    int fixIndex = VenvyLVLibBinder.fixIndex(args);
    LuaValue target = args.arg(fixIndex + 2);  //key
    LuaValue data = args.arg(fixIndex + 3);  //data
    String msg = luaValueToString(target);

    Bundle bundle = new Bundle();
    bundle.putString(CONSTANT_MSG, msg);
    bundle.putBoolean(CONSTANT_NEED_RETRY, true);
    bundle.putString(CONSTANT_DATA, luaValueToString(data));
    ObservableManager.getDefaultObserable().sendToTarget(VenvyObservableTarget.TAG_SHOW_VISION_ERROR_LOGIC, bundle);


    return LuaValue.valueOf(msg);
}
 
Example 4
Source File: UIImageViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue setPlaceHolderImage(U view, Varargs varargs) {
    if (varargs.isstring(2)) {
        final String url = varargs.optjstring(2, null);
        final LuaFunction callback = varargs.optfunction(3, null);
        return view.setPlaceHolderImage(url, callback);
    } else if (varargs.arg(2) instanceof UDData) {//data
        final UDData data = (UDData) varargs.arg(2);
        return view.setPlaceHolderBytes(data != null ? Base64.decode(data.bytes(), Base64.NO_WRAP) : null);
    }
    return view;
}
 
Example 5
Source File: LVCompressPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public LuaValue invoke(Varargs args) {
    int fixIndex = VenvyLVLibBinder.fixIndex(args);
    LuaValue target = args.arg(fixIndex + 1);  //key
    String zipString = luaValueToString(target);
    zipString = VenvyGzipUtil.unCompress(zipString);
    return LuaValue.valueOf(zipString == null ? "" : zipString);
}
 
Example 6
Source File: DebugLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaValue func = args.checkfunction(1);
	int up = args.checkint(2);
	LuaValue value = args.arg(3);
	if ( func instanceof LuaClosure ) {
		LuaClosure c = (LuaClosure) func;
		LuaString name = findupvalue(c, up);
		if ( name != null ) {
			c.upValues[up-1].setValue(value);
			return name;
		}
	}
	return NIL;
}
 
Example 7
Source File: LVUrlPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public LuaValue invoke(Varargs args) {
    int fixIndex = VenvyLVLibBinder.fixIndex(args);

    LuaValue contextValue = args.arg(fixIndex + 1);
    String encodeValue = luaValueToString(contextValue);

    try {
        return LuaValue.valueOf(URLDecoder.decode(encodeValue, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        return LuaValue.NIL;
    }

}
 
Example 8
Source File: DebugLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaValue func = args.checkfunction(1);
	int up = args.checkint(2);
	LuaValue value = args.arg(3);
	if ( func instanceof LuaClosure ) {
		LuaClosure c = (LuaClosure) func;
		LuaString name = findupvalue(c, up);
		if ( name != null ) {
			c.upValues[up-1].setValue(value);
			return name;
		}
	}
	return NIL;
}
 
Example 9
Source File: UIImageViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue setImage(U view, Varargs varargs) {
    if (varargs.isstring(2)) {
        final String url = varargs.optjstring(2, null);
        final LuaFunction callback = varargs.optfunction(3, null);
        return view.setImageUrl(url, callback);
    } else if (varargs.arg(2) instanceof UDData) {//data
        final UDData data = (UDData) varargs.arg(2);
        return view.setImageBytes(data != null ? Base64.decode(data.bytes(), Base64.NO_WRAP) : null);
    }
    return view;
}
 
Example 10
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) {
    int fixIndex = VenvyLVLibBinder.fixIndex(args);
    LuaValue key = args.arg(fixIndex + 2);  // key
    LuaValue fileName = args.arg(fixIndex + 3);  // file sp 文件名
    String fileNameStr = luaValueToString(fileName);
    if (TextUtils.isEmpty(fileNameStr)) {
        //  没有传文件名,默认查询当前开发者ID对应的缓存数据
        String data = CacheConstants.getCacheByDeveloperId(platform.getContentViewGroup().getContext(), luaValueToString(key));
        return LuaValue.valueOf(data);
    } else {
        String jsonStr = CacheConstants.getVisionProgramId(platform.getContentViewGroup().getContext(), fileNameStr);
        return LuaValue.valueOf(jsonStr);
    }
}
 
Example 11
Source File: LuaJavaCoercionTest.java    From luaj with MIT License 5 votes vote down vote up
public void testExceptionMessage() {
	String script = "local c = luajava.bindClass( \""+SomeClass.class.getName()+"\" )\n" +
			"return pcall( c.someMethod, c )";
	Varargs vresult = globals.get("load").call(LuaValue.valueOf(script)).invoke(LuaValue.NONE);
	LuaValue status = vresult.arg1();
	LuaValue message = vresult.arg(2);
	assertEquals( LuaValue.FALSE, status );		
	int index = message.toString().indexOf( "this is some message" );
	assertTrue( "bad message: "+message, index>=0 );		
}
 
Example 12
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) {
    int fixIndex = VenvyLVLibBinder.fixIndex(args);
    LuaValue target = args.arg(fixIndex + 2);  //key
    String msg = luaValueToString(target);
    Bundle bundle = new Bundle();
    bundle.putString(CONSTANT_MSG, msg);
    bundle.putBoolean(CONSTANT_NEED_RETRY, false);
    ObservableManager.getDefaultObserable().sendToTarget(VenvyObservableTarget.TAG_SHOW_VISION_ERROR_LOGIC, bundle);
    return LuaValue.valueOf(msg);
}
 
Example 13
Source File: DebugLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
	int level = args.checkint(a++);
	int local = args.checkint(a++);
	LuaValue value = args.arg(a++);
	CallFrame f = callstack(thread).getCallFrame(level);
	return f != null? f.setLocal(local, value): NONE;
}
 
Example 14
Source File: LVReportPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
    int fixIndex = VenvyLVLibBinder.fixIndex(args);
    if (args.narg() > fixIndex) {
        LuaValue messageValue = args.arg(fixIndex + 1);//key
        String message = VenvyLVLibBinder.luaValueToString(messageValue);
        if (TextUtils.isEmpty(message)) {
            return LuaValue.NIL;
        }
        int level = LuaUtil.getInt(args, fixIndex + 2) == null ? 0 : LuaUtil.getInt(args, fixIndex + 2);
        boolean needReport = LuaUtil.getBoolean(args, fixIndex + 3) == null ? true : false;
        switch (level) {
            case 0:
                VenvyLog.i(message);
                if (true) {
                    Report.report(Report.ReportLevel.i, TAG, message);
                }
                break;
            case 1:
                VenvyLog.i(message);
                if (needReport) {
                    Report.report(Report.ReportLevel.w, TAG, message);
                }
                break;
            default:
                VenvyLog.i(message);
                if (true) {
                    Report.report(Report.ReportLevel.i, TAG, message);
                }
                break;
        }
    }
    return LuaValue.NIL;
}
 
Example 15
Source File: XLua.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
LuaLocals(Globals globals) {
    this.presize(globals.length(), 0);
    Varargs entry = globals.next(LuaValue.NIL);
    while (!entry.arg1().isnil()) {
        LuaValue key = entry.arg1();
        LuaValue value = entry.arg(2);
        super.rawset(key, value);
        entry = globals.next(entry.arg1());
    }
}
 
Example 16
Source File: DebugLib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public Varargs invoke(Varargs args) {
    int a = 1;
    LuaThread thread = args.isthread(a) ? args.checkthread(a++) : globals.running;
    LuaValue func = args.arg(a++);
    String what = args.optjstring(a++, "flnStu");
    DebugLib.CallStack callstack = callstack(thread);

    // find the stack info
    DebugLib.CallFrame frame;
    if (func.isnumber()) {
        frame = callstack.getCallFrame(func.toint());
        if (frame == null)
            return NONE;
        func = frame.f;
    } else if (func.isfunction()) {
        frame = callstack.findCallFrame(func);
    } else {
        return argerror(a - 2, "function or level");
    }

    // start a table
    DebugInfo ar = callstack.auxgetinfo(what, (LuaFunction) func, frame);
    LuaTable info = new LuaTable();
    if (what.indexOf('S') >= 0) {
        info.set(WHAT, LUA);
        info.set(SOURCE, valueOf(ar.source));
        info.set(SHORT_SRC, valueOf(ar.short_src));
        info.set(LINEDEFINED, valueOf(ar.linedefined));
        info.set(LASTLINEDEFINED, valueOf(ar.lastlinedefined));
    }
    if (what.indexOf('l') >= 0) {
        info.set(CURRENTLINE, valueOf(ar.currentline));
    }
    if (what.indexOf('u') >= 0) {
        info.set(NUPS, valueOf(ar.nups));
        info.set(NPARAMS, valueOf(ar.nparams));
        info.set(ISVARARG, ar.isvararg ? ONE : ZERO);
    }
    if (what.indexOf('n') >= 0) {
        info.set(NAME, LuaValue.valueOf(ar.name != null ? ar.name : "?"));
        info.set(NAMEWHAT, LuaValue.valueOf(ar.namewhat));
    }
    if (what.indexOf('t') >= 0) {
        info.set(ISTAILCALL, ZERO);
    }
    if (what.indexOf('L') >= 0) {
        LuaTable lines = new LuaTable();
        info.set(ACTIVELINES, lines);
        DebugLib.CallFrame cf;
        for (int l = 1; (cf = callstack.getCallFrame(l)) != null; ++l)
            if (cf.f == func)
                lines.insert(-1, valueOf(cf.currentline()));
    }
    if (what.indexOf('f') >= 0) {
        if (func != null)
            info.set(FUNC, func);
    }
    return info;
}
 
Example 17
Source File: UIViewPagerMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue setIndicator(U view, Varargs varargs) {
    final LuaValue indicator = varargs.arg(2);
    return view.setViewPagerIndicator(indicator);
}
 
Example 18
Source File: UIAnimatorMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue with(U udAnimator, Varargs varargs) {
    final UDView udView = (varargs.narg() > 1 && varargs.arg(2) instanceof UDView) ? (UDView) varargs.arg(2) : null;
    return udAnimator.with(udView);
}
 
Example 19
Source File: DebugLib.java    From luaj with MIT License 4 votes vote down vote up
public Varargs invoke(Varargs args) {
	int a=1;
	LuaThread thread = args.isthread(a)? args.checkthread(a++): globals.running;
	LuaValue func = args.arg(a++);
	String what = args.optjstring(a++, "flnStu");
	DebugLib.CallStack callstack = callstack(thread);

	// find the stack info
	DebugLib.CallFrame frame;
	if ( func.isnumber() ) {
		frame = callstack.getCallFrame(func.toint());
		if (frame == null)
			return NONE;
		func = frame.f;
	} else if ( func.isfunction() ) {
		frame = callstack.findCallFrame(func);
	} else {
		return argerror(a-2, "function or level");
	}

	// start a table
	DebugInfo ar = callstack.auxgetinfo(what, (LuaFunction) func, frame);
	LuaTable info = new LuaTable();
	if (what.indexOf('S') >= 0) {
		info.set(WHAT, LUA);
		info.set(SOURCE, valueOf(ar.source));
		info.set(SHORT_SRC, valueOf(ar.short_src));
		info.set(LINEDEFINED, valueOf(ar.linedefined));
		info.set(LASTLINEDEFINED, valueOf(ar.lastlinedefined));
	}
	if (what.indexOf('l') >= 0) {
		info.set( CURRENTLINE, valueOf(ar.currentline) );
	}
	if (what.indexOf('u') >= 0) {
		info.set(NUPS, valueOf(ar.nups));
		info.set(NPARAMS, valueOf(ar.nparams));
		info.set(ISVARARG, ar.isvararg? ONE: ZERO);
	}
	if (what.indexOf('n') >= 0) {
		info.set(NAME, LuaValue.valueOf(ar.name!=null? ar.name: "?"));
		info.set(NAMEWHAT, LuaValue.valueOf(ar.namewhat));
	}
	if (what.indexOf('t') >= 0) {
		info.set(ISTAILCALL, ZERO);
	}
	if (what.indexOf('L') >= 0) {
		LuaTable lines = new LuaTable();
		info.set(ACTIVELINES, lines);
		DebugLib.CallFrame cf;
		for (int l = 1; (cf=callstack.getCallFrame(l)) != null; ++l)
			if (cf.f == func)
				lines.insert(-1, valueOf(cf.currentline()));
	}
	if (what.indexOf('f') >= 0) {
		if (func != null)
			info.set( FUNC, func );
	}
	return info;
}
 
Example 20
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;
}