Java Code Examples for org.luaj.vm2.LuaValue#NIL

The following examples show how to use org.luaj.vm2.LuaValue#NIL . 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: VenvyMqttMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
public LuaValue startMqtt(U target, Varargs args) {
    try {
        if (args.narg() > 0) {
            LuaTable table = LuaUtil.getTable(args, 2);
            LuaTable configTable = LuaUtil.getTable(args, 3);
            Map<String, String> topsMap = LuaUtil.toMap(table);
            if (topsMap != null && configTable != null) {
                SocketUserInfo info = new SocketUserInfo(configTable.get("username").tojstring(), configTable.get("password").tojstring(), configTable.get("host").tojstring(), configTable.get("port").tojstring(), configTable.get("clientId").tojstring());
                target.setMqttTopics(info, topsMap);
            }
        }
    } catch (Exception e) {
        VenvyLog.e(VenvyMqttMapper.class.getName(), e);
    }
    return LuaValue.NIL;
}
 
Example 2
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 3
Source File: LuaUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public static LuaValue callFunction(LuaValue target, LuaValue arg1, LuaValue arg2) {
    try {
        return (target != null && target.isfunction()) ? target.call(arg1, arg2) : LuaValue.NIL;
    } catch (Exception e) {
        e.printStackTrace();
        return LuaValue.NIL;
    }
}
 
Example 4
Source File: UIViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue mqttCallback(U view, Varargs varargs) {
    if (varargs.narg() > 1) {
        final LuaValue callbacks = varargs.optvalue(2, NIL);
        if (callbacks.isfunction()) {
            return view.setMqttCallback(callbacks);
        }
        return LuaValue.NIL;
    } else {
        return view.getMqttCallback();
    }
}
 
Example 5
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 6
Source File: LVWebViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@LuaViewApi(since = VmVersion.V_530)
public LuaValue loadUrl(U view, Varargs varargs) {
    String url = LuaUtil.getString(varargs, 2);
    if (TextUtils.isEmpty(url)) {
        return LuaValue.NIL;
    }
    return view.loadUrl(url);
}
 
Example 7
Source File: UDView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * get native view
 *
 * @return
 */
public LuaValue getNativeView() {
    View view = getView();
    if (view instanceof ILVNativeViewProvider) {
        view = ((ILVNativeViewProvider) view).getNativeView();
    }
    return view != null ? CoerceJavaToLua.coerce(view) : LuaValue.NIL;
}
 
Example 8
Source File: VenvyAcrCloudMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue stopAcrRecognize(U target, Varargs args) {
    try {
        target.stopRecognize();
    } catch (Exception e) {
        VenvyLog.e(VenvyAcrCloudMapper.class.getName(), e);
    }
    return LuaValue.NIL;
}
 
Example 9
Source File: VenvyMqttMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue stopMqtt(U target, Varargs args) {
    try {
        target.removeTopics();
    } catch (Exception e) {
        VenvyLog.e(VenvyMqttMapper.class.getName(), e);
    }
    return LuaValue.NIL;
}
 
Example 10
Source File: RedisBinding.java    From claudb with MIT License 5 votes vote down vote up
private LuaValue toLuaString(StringRedisToken value) {
  SafeString string = value.getValue();
  if (string == null) {
    return LuaValue.NIL;
  }
  return LuaString.valueOf(string.getBytes());
}
 
Example 11
Source File: UIEditTextMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public LuaValue maxLength(U view, Varargs varargs) {
    if (varargs.narg() >= 2) {
        return view.setMaxLength(LuaUtil.getInt(varargs, 2));
    } else {
        return LuaValue.NIL;
    }
}
 
Example 12
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);
    String zipString = luaValueToString(target);
    try {
        zipString = VenvyGzipUtil.compress(zipString);
        return LuaValue.valueOf(zipString == null ? "" : zipString);
    } catch (IOException e) {
        return LuaValue.NIL;
    }
}
 
Example 13
Source File: LuaViewCore.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 调用lua的某个全局函数
 *
 * @param funName
 * @param objs
 * @return
 */
public Object callLuaFunction(String funName, Object... objs) {
    if (mGlobals != null && funName != null) {
        LuaValue callback = mGlobals.get(funName);
        return LuaUtil.callFunction(callback, objs);
    }
    return LuaValue.NIL;
}
 
Example 14
Source File: LuaView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 调用window.callback下的某个函数
 *
 * @param funName
 * @param objs
 * @return
 */
public Varargs callWindowFunction(String funName, Object... objs) {
    if (funName != null) {
        UDView userdata = getUserdata();
        if (userdata != null) {
            LuaValue callbacks = userdata.getCallback();
            if (LuaUtil.isValid(callbacks)) {
                return LuaUtil.callFunction(callbacks.get(funName), objs);
            }
        }
    }
    return LuaValue.NIL;
}
 
Example 15
Source File: LuaUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public static LuaValue callFunction(LuaValue target, LuaValue arg1) {
    try {
        return (target != null && target.isfunction()) ? target.call(arg1) : LuaValue.NIL;
    } catch (Exception e) {
        e.printStackTrace();
        return LuaValue.NIL;
    }
}
 
Example 16
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;
}
 
Example 17
Source File: UIImageViewMethodMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public LuaValue getImage(U view, Varargs varargs) {
    String imageUrl = view.getImageUrl();
    return imageUrl != null ? valueOf(imageUrl) : LuaValue.NIL;
}
 
Example 18
Source File: CoerceJavaToLua.java    From luaj with MIT License 3 votes vote down vote up
/**
 * Coerse a Java object to a corresponding lua value. 
 * <p>
 * Integral types {@code boolean}, {@code byte},  {@code char}, and {@code int} 
 * will become {@link LuaInteger};
 * {@code long}, {@code float}, and {@code double} will become {@link LuaDouble};
 * {@code String} and {@code byte[]} will become {@link LuaString}; 
 * types inheriting from {@link LuaValue} will be returned without coercion;
 * other types will become {@link LuaUserdata}.
 * @param o Java object needing conversion
 * @return {@link LuaValue} corresponding to the supplied Java value. 
 * @see LuaValue
 * @see LuaInteger
 * @see LuaDouble
 * @see LuaString
 * @see LuaUserdata
 */
public static LuaValue coerce(Object o) {
	if ( o == null )
		return LuaValue.NIL;
	Class clazz = o.getClass();
	Coercion c = (Coercion) COERCIONS.get( clazz );
	if ( c == null ) {
		c = clazz.isArray()? arrayCoercion:
			o instanceof LuaValue ? luaCoercion:
				instanceCoercion;
		COERCIONS.put( clazz, c );
	}
	return c.coerce(o);
}
 
Example 19
Source File: CoerceJavaToLua.java    From HtmlNative with Apache License 2.0 3 votes vote down vote up
/**
 * Coerse a Java object to a corresponding lua value. 
 * <p>
 * Integral types {@code boolean}, {@code byte},  {@code char}, and {@code int} 
 * will become {@link LuaInteger};
 * {@code long}, {@code float}, and {@code double} will become {@link LuaDouble};
 * {@code String} and {@code byte[]} will become {@link LuaString}; 
 * types inheriting from {@link LuaValue} will be returned without coercion;
 * other types will become {@link LuaUserdata}.
 * @param o Java object needing conversion
 * @return {@link LuaValue} corresponding to the supplied Java value. 
 * @see LuaValue
 * @see LuaInteger
 * @see LuaDouble
 * @see LuaString
 * @see LuaUserdata
 */
public static LuaValue coerce(Object o) {
	if ( o == null )
		return LuaValue.NIL;
	Class clazz = o.getClass();
	Coercion c = (Coercion) COERCIONS.get( clazz );
	if ( c == null ) {
		c = clazz.isArray()? arrayCoercion:
			o instanceof LuaValue ? luaCoercion:
				instanceCoercion;
		COERCIONS.put( clazz, c );
	}
	return c.coerce(o);
}
 
Example 20
Source File: LuaView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 2 votes vote down vote up
/**
 * @param context     View级别的Context
 * @param luaViewCore
 * @param metaTable
 */
public LuaView(Context context, LuaViewCore luaViewCore, LuaValue metaTable) {
    super(context, luaViewCore.getGlobals(), metaTable, LuaValue.NIL);
    this.mLuaViewCore = luaViewCore;
}