org.luaj.vm2.LuaValue Java Examples

The following examples show how to use org.luaj.vm2.LuaValue. 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: 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 #2
Source File: LuajavaLib.java    From luaj with MIT License 6 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	String name = method.getName();
	LuaValue func = lobj.get(name);
	if ( func.isnil() )
		return null;
	boolean isvarargs = ((method.getModifiers() & METHOD_MODIFIERS_VARARGS) != 0);
	int n = args!=null? args.length: 0;
	LuaValue[] v;
	if ( isvarargs ) {
		Object o = args[--n];
		int m = Array.getLength( o );
		v = new LuaValue[n+m];
		for ( int i=0; i<n; i++ )
			v[i] = CoerceJavaToLua.coerce(args[i]);
		for ( int i=0; i<m; i++ )
			v[i+n] = CoerceJavaToLua.coerce(Array.get(o,i));
	} else {
		v = new LuaValue[n];
		for ( int i=0; i<n; i++ )
			v[i] = CoerceJavaToLua.coerce(args[i]);
	}
	LuaValue result = func.invoke(v).arg1();
	return CoerceLuaToJava.coerce(result, method.getReturnType());
}
 
Example #3
Source File: UDBaseListOrRecyclerView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 调用 Callback 方法
 *
 * @param cell
 * @param position
 * @return
 */
public LuaValue onCellClicked(LuaValue cell, int position) {
    int section = getSectionByPosition(position);
    int row = getRowInSectionByPosition(position);
    LuaValue cellData = getCell(getId(position, section, row));
    if (cellData != null) {
         LuaValue callback = cellData.get("Callback");
        if (callback.isfunction()) {
            return LuaUtil.callFunction(callback, cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row));
        } else if (callback.istable()) {
            return LuaUtil.callFunction(LuaUtil.getFunction(callback, "Click", "click"), cell, LuaUtil.toLuaInt(section), LuaUtil.toLuaInt(row));
        }
    }
    return NIL;
}
 
Example #4
Source File: BaseLib.java    From luaj with MIT License 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 #5
Source File: LuaConversion.java    From Cubes with MIT License 5 votes vote down vote up
public static Object convertToJava(Class<?> c, LuaValue o) {
  if (o == null || o.isnil()) return null;
  LuaConverter luaConverter = converter(c);
  if (luaConverter == null) {
    if (o instanceof LuaObject) {
      luaConverter = map.get(Object.class);
    } else {
      throw new ConversionError("Cannot convert Lua to Java: " + c.getName());
    }
  }
  return luaConverter.toJava(o, c);
}
 
Example #6
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 #7
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 #8
Source File: VenvyNotificationMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue postNotification(U target, Varargs args) {
    if (args.narg() > 0) {
        String tag = LuaUtil.getString(args, 2);
        if (TextUtils.isEmpty(tag)) {
            return LuaValue.NIL;
        }
        LuaTable table = LuaUtil.getTable(args, 3);
        Map<String, String> messageMap = LuaUtil.toMap(table);
        NotificationInfo info = new NotificationInfo();
        info.messageInfo = messageMap;
        target.postNotification(tag, info);
    }
    return LuaValue.NIL;
}
 
Example #9
Source File: LVLoginPlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
    if (mPlatform != null && mPlatform.getPlatformLoginInterface() != null) {
        PlatformUserInfo platformUserInfo = mPlatform.getPlatformLoginInterface().getLoginUser();
        if (platformUserInfo != null) {
            return JsonUtil.toLuaTable(platformUserInfo.toString());
        }
    }
    return LuaValue.NIL;
}
 
Example #10
Source File: TimerMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 启动延时
 *
 * @param udTimer
 * @param varargs
 * @return
 */
@LuaViewApi(since = VmVersion.V_500)
public LuaValue delay(U udTimer, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setDelay(udTimer, varargs);
    } else {
        return getDelay(udTimer, varargs);
    }
}
 
Example #11
Source File: LexState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
boolean str2d(String str, SemInfo seminfo) {
    if (str.indexOf('n') >= 0 || str.indexOf('N') >= 0)
        seminfo.r = LuaValue.ZERO;
    else if (str.indexOf('x') >= 0 || str.indexOf('X') >= 0)
        seminfo.r = strx2number(str, seminfo);
    else
        seminfo.r = LuaValue.valueOf(Double.parseDouble(str.trim()));
    return true;
}
 
Example #12
Source File: LVCopyPlugin.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);
    String copyStringToPasteBoard = luaValueToString(target);
    if (!TextUtils.isEmpty(copyStringToPasteBoard)) {
        ClipboardManager systemService = (ClipboardManager) App.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
        systemService.setPrimaryClip(ClipData.newPlainText("text", copyStringToPasteBoard));
        return LuaValue.NIL;
    } else {
        return LuaValue.NIL;
    }
}
 
Example #13
Source File: CoerceLuaToJava.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public int score(LuaValue value) {
	switch ( value.type() ) {
	case LuaValue.TTABLE:
		return value.length()==0? 0: componentCoercion.score( value.get(1) );
	case LuaValue.TUSERDATA:
		return inheritanceLevels( componentType, value.touserdata().getClass().getComponentType() );
	case LuaValue.TNIL:
		return SCORE_NULL_VALUE;
	default: 
		return SCORE_UNCOERCIBLE;
	}
}
 
Example #14
Source File: VenvyMqttMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue mqttCallback(U target, Varargs varargs) {
    final LuaFunction callback = varargs.optfunction(2, null);
    if (callback != null && callback.isfunction()) {
        return target.setMqttCallback(callback);
    }
    return LuaValue.NIL;
}
 
Example #15
Source File: IoLib.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
public static LuaValue freadnumber(File f) throws IOException {
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	freadchars(f," \t\r\n",null);
	freadchars(f,"-+",baos);
	//freadchars(f,"0",baos);
	//freadchars(f,"xX",baos);
	freadchars(f,"0123456789",baos);
	freadchars(f,".",baos);
	freadchars(f,"0123456789",baos);
	//freadchars(f,"eEfFgG",baos);
	// freadchars(f,"+-",baos);
	//freadchars(f,"0123456789",baos);
	String s = baos.toString();
	return s.length()>0? valueOf( Double.parseDouble(s) ): NIL;
}
 
Example #16
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 target = args.arg(fixIndex + 1);  //key
    String result = luaValueToString(target);
    return LuaValue.valueOf(VenvyBase64.encode(result.getBytes()));
}
 
Example #17
Source File: LVTextView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LVTextView(Globals globals, LuaValue metaTable, Varargs varargs) {
        super(globals.getContext());
        this.mLuaUserdata = new UDTextView(this, globals, metaTable, varargs);
        this.setIncludeFontPadding(false);//设置默认TextView不包含字体的padding,否则adjustSize的时候拿到的高度有问题
        this.setGravity(Gravity.CENTER_VERTICAL);//默认竖直居中
        this.setLines(1);//默认一行
        this.setTextSize(UDFontSize.FONTSIZE_SMALL);
//        this.setEllipsize(TextUtils.TruncateAt.END);//默认在最后有3个点
    }
 
Example #18
Source File: JsonUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 将JSONObject转成LuaTable
 *
 * @param jsonString
 * @return
 */
public static LuaValue toLuaTable(String jsonString) {
    LuaValue luaTable = LuaValue.NIL;
    try {
        luaTable = toLuaTable(new JSONObject(jsonString));
    } catch (Exception e) {
        try {
            luaTable = toLuaTable(new JSONArray(jsonString));
        } catch (Exception ex1) {
            VenvyLog.e(JsonUtil.class.getName(), ex1);
        }
    }
    return luaTable;
}
 
Example #19
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 #20
Source File: BaseLib.java    From luaj with MIT License 5 votes vote down vote up
public Varargs invoke(Varargs args) {
	LuaValue ld = args.arg1();
	if (!ld.isstring() && !ld.isfunction()) {
		throw new LuaError("bad argument #1 to 'load' (string or function expected, got " + ld.typename() + ")");
	}
	String source = args.optjstring(2, ld.isstring()? ld.tojstring(): "=(load)");
	String mode = args.optjstring(3, "bt");
	LuaValue env = args.optvalue(4, globals);
	return loadStream(ld.isstring()? ld.strvalue().toInputStream():
		new StringInputStream(ld.checkfunction()), source, mode, env);
}
 
Example #21
Source File: TimerMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 取消定时器
 *
 * @param udTimer
 * @param varargs
 * @return
 */
public LuaValue callback(U udTimer, Varargs varargs) {
    if (varargs.narg() > 1) {
        return setCallback(udTimer, varargs);
    } else {
        return getCallback(udTimer, varargs);
    }
}
 
Example #22
Source File: Bit32Lib.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
static LuaValue lrotate(int x, int disp) {
	if (disp < 0) {
		return rrotate(x, -disp);
	} else {
		disp = disp & 31;
		return bitsToValue((x << disp) | (x >>> (32 - disp)));
	}
}
 
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: LVDevicePlugin.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Varargs invoke(Varargs args) {
    if (mPlatform != null && mPlatform.getPlatformInfo() != null) {
        if (mPlatform.getPlatformInfo().getCustomerPackageName() != null) {
            return LuaValue.valueOf(mPlatform.getPlatformInfo().getCustomerPackageName());
        }
    }
    return LuaValue.valueOf(VenvyDeviceUtil.getPackageName(App.getContext()));
}
 
Example #25
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 #26
Source File: VenvyNotificationMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue registerNotification(U target, Varargs args) {
    if (args.narg() > 0) {
        final String tag = LuaUtil.getString(args, 2);
        final LuaFunction callback = args.optfunction(3, null);
        if (TextUtils.isEmpty(tag)) {
            return LuaValue.NIL;
        }
        if (callback != null && callback.isfunction()) {
            return target.registerNotification(callback, tag);
        }
    }
    return LuaValue.NIL;
}
 
Example #27
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
 */
@Deprecated
public LuaValue scrollBy(U view, Varargs varargs) {
    final int dx = DimenUtil.dpiToPx(varargs.arg(2));
    ;
    final int dy = DimenUtil.dpiToPx(varargs.arg(3));
    final boolean smooth = varargs.optboolean(4, false);
    if (smooth) {
        return view.smoothScrollBy(dx, dy);
    } else {
        return view.scrollBy(dx, dy);
    }
}
 
Example #28
Source File: BaseLib.java    From luaj with MIT License 5 votes vote down vote up
/**
 * Load from a named file, returning the chunk or nil,error of can't load
 * @param env
 * @param mode
 * @return Varargs containing chunk, or NIL,error-text on error
 */
public Varargs loadFile(String filename, String mode, LuaValue env) {
	InputStream is = globals.finder.findResource(filename);
	if ( is == null )
		return varargsOf(NIL, valueOf("cannot open "+filename+": No such file or directory"));
	try {
		return loadStream(is, "@"+filename, mode, env);
	} finally {
		try {
			is.close();
		} catch ( Exception e ) {
			e.printStackTrace();
		}
	}
}
 
Example #29
Source File: LuaUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public static Varargs invokeFunction(LuaValue target, LuaValue arg1, LuaValue arg2) {
    try {
        return (target != null && target.isfunction()) ? target.invoke(arg1, arg2) : LuaValue.NIL;
    } catch (Exception e) {
        return LuaValue.NIL;
    }
}
 
Example #30
Source File: ScriptEngineTests.java    From luaj with MIT License 4 votes vote down vote up
public void testCompiledFunctionIsNotClosure() throws ScriptException {
          CompiledScript cs = ((Compilable)e).compile("return 'foo'");
          LuaValue value = ((LuaScriptEngine.LuajCompiledScript)cs).function;
          assertFalse(value.isclosure());
}