Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential Windows bug for user settings? #342

Open
Nick-Mazuk opened this issue Aug 19, 2022 · 1 comment
Open

Potential Windows bug for user settings? #342

Nick-Mazuk opened this issue Aug 19, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Nick-Mazuk
Copy link
Member

Nick-Mazuk commented Aug 19, 2022

When looking through the user settings source code, I noticed that the get_parameters_from_file uses calc_preferences_filepath directly:

function configuration.get_user_settings(script_name, parameter_list, create_automatically)
if create_automatically == nil then create_automatically = true end
local exists = get_parameters_from_file(calc_preferences_filepath(script_name), parameter_list)

Yet calc_preferences_filepath returns a tuple:

local calc_preferences_filepath = function(script_name)
local str = finale.FCString()
str:SetUserOptionsPath()
local folder_name = str.LuaString
if not finenv.IsRGPLua and finenv.UI():IsOnMac() then
-- works around bug in SetUserOptionsPath() in JW Lua
folder_name = os.getenv("HOME") .. folder_name:sub(2) -- strip '~' and replace with actual folder
end
if finenv.UI():IsOnWindows() then
folder_name = folder_name .. path_delimiter .. "FinaleLua"
end
local file_path = folder_name .. path_delimiter
if finenv.UI():IsOnMac() then
file_path = file_path .. "com.finalelua."
end
file_path = file_path .. script_name .. ".settings.txt"
return file_path, folder_name
end

This seems to be working fine on macOS, but it seems like a strong code smell. Is this working on Windows?

Either way, I'd suggest rewriting it to destructure the tuple first, then only use the first value. While this seems to be acceptable Lua code, this would not be acceptable code in many other languages and could confuse many other people (including me at first).

@Nick-Mazuk Nick-Mazuk added the bug Something isn't working label Aug 19, 2022
@rpatters1
Copy link
Collaborator

Lua functions can return multiple values without the callers having to consume them. It isn't a "tuple" in the C++ sense. It is two discrete values.

Is there a reason to think it would fail on Windows? It seems like bog-standard Lua to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants