History

auto_profiles: check for non-existent properties

Previously, it just silently didn't do anything which is not very intuitive. Since the lua api returns an error string, check to see if it matches the "property not found" case and print an error message. Additionally, don't add the fake property to the internal cached_properties list or try to observe it. This avoids redundant evaluate calls which will never actually succeed. We do still mark it under watched_properties however. This avoids having to call mp.get_property_native multiple times.

Dudemanguy committed 3 years ago

Commit 6e4a76d1 parent bdf7b5c1 file · +6 −1Browse files

Showing the changes to player/lua/auto_profiles.lua (1 of 1 file). Show all

Unified · Split

player/lua/auto_profiles.lua+6−1
@@ -87,8 +87,13 @@ function get(name, default) · 86 unmodified lines
8787 -- Normally, we use the cached value only
8888 if not watched_properties[name] then
8989 watched_properties[name] = true
90+ local res, err = mp.get_property_native(name)
91+ if err == "property not found" then
92+ msg.error("Property '" .. name .. "' was not found.")
93+ return default
94+ end
95+ cached_properties[name] = res
9096 mp.observe_property(name, "native", on_property_change)
91− cached_properties[name] = mp.get_property_native(name)
9297 end
9398 -- The first time the property is read we need add it to the
9499 -- properties_to_profiles table, which will be used to mark the profile

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t