/** * Returns the {@link LuaObjectMeta} registered with the provided typename. * * @param metaName the typename to match * @return the LuaObjectMeta matching the given typename, or null if doesn't exist */ public static LuaObjectMeta getMeta(String metaName) { for (LuaObjectMeta meta : Lua.PMETA.values()) { if (meta.getTypeName().equals(metaName)) { return meta; } } for (LuaObjectMeta meta : Lua.META.values()) { if (meta.getTypeName().equals(metaName)) { return meta; } } return null; }
/** * Returns the given {@link LuaValue} as the appropriate type of {@link LuaObjectValue}, directed * by the provided {@link LuaObjectMeta} type. * * <p>If the provided value is not of the appropriate type, a {@link LuaError} is raised. * * @param value the LuaValue to check * @param clazz the target LuaObjectMeta type to check with * @return the appropriately typed LuaValue as a LuaObjectValue */ public static <T> LuaObjectValue<T> checkType( LuaValue value, Class<? extends LuaObjectMeta> clazz) { LuaObjectMeta meta = Lua.getMeta(clazz); if (meta == null) { throw new IllegalArgumentException( "Meta class " + clazz.getSimpleName() + " isn't registered"); } if (value instanceof LuaObjectValue) { LuaObjectValue<?> objectValue = ((LuaObjectValue<?>) value); if (meta.getTargetObjectClass().isInstance(objectValue.getObject())) { return (LuaObjectValue<T>) objectValue; } } throw new LuaError(String.format(INVALID_TYPE_MSG, meta.getTypeName(), value.typename())); }