From 89a903b319817dacf3abdebe1756f3ae73c91d0b Mon Sep 17 00:00:00 2001 From: torque Date: Mon, 13 Nov 2017 14:22:50 -0800 Subject: [PATCH] settings: use a single underscore prefix for "private" methods. The double underscore is used to denote metamethods and could potentially (though unlikely) cause problems with forward compatibility. --- src/requires.moon | 12 ++++++------ src/settings.moon | 2 +- tools/DefaultConfigGenerator.moon | 14 +++++++------- tools/ReadOptionsStub.moon | 7 ++++--- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/requires.moon b/src/requires.moon index b75298c..01344b3 100644 --- a/src/requires.moon +++ b/src/requires.moon @@ -9,15 +9,15 @@ mp.get_osd_size = mp.get_osd_size or mp.get_screen_size -- This is here instead of in settings.moon because it would conflict with the -- default settings generator tool if it were placed in settings, and this is -- the only file that goes before settings. -settings = { __defaults: { } } +settings = { _defaults: { } } -- These methods are jammed in a metatable so that they can't be overridden from -- the configuration file. settingsMeta = { - __reload: => + _reload: => -- Shallow copy should be good. This is necessary to reset values to the -- defaults so that removing a configuration key has an effect. - for key, value in pairs @__defaults + for key, value in pairs @_defaults settings[key] = value options.read_options @, script_name .. '/main' @@ -28,7 +28,7 @@ settingsMeta = { -- about failing to stroke zero-height object. @['bar-height-inactive'] = 1 - __migrate: => + _migrate: => oldConfig = mp.find_config_file 'lua-settings/%s.conf'\format script_name newConfigFile = 'lua-settings/%s/main.conf'\format script_name newConfig = mp.find_config_file newConfigFile @@ -59,11 +59,11 @@ settingsMeta = { log.info 'Configuration successfully migrated.' __newindex: ( key, value ) => - @__defaults[key] = value + @_defaults[key] = value rawset @, key, value } settingsMeta.__index = settingsMeta setmetatable settings, settingsMeta -settings\__migrate! +settings\_migrate! diff --git a/src/settings.moon b/src/settings.moon index dc61789..0453fd7 100644 --- a/src/settings.moon +++ b/src/settings.moon @@ -377,4 +377,4 @@ will disappear without animating all the way off-screen. Positive values will cause the display to animate the wrong direction. ]] -settings\__reload! +settings\_reload! diff --git a/tools/DefaultConfigGenerator.moon b/tools/DefaultConfigGenerator.moon index 3b966e7..7425550 100644 --- a/tools/DefaultConfigGenerator.moon +++ b/tools/DefaultConfigGenerator.moon @@ -1,24 +1,24 @@ convertToComment = ( text ) -> - result = { '' } + result = { } text\gsub '(.-)\n', ( line ) -> table.insert result, '# ' .. line - table.concat result, '\n' + return table.concat result, '\n' convertToValue = ( value ) -> switch type value when 'boolean' - value and 'yes' or 'no' + return value and 'yes' or 'no' when 'number' - tostring value + return tostring value else - value + return value combined = {} -for setting in *settings.__keys +for setting in *settings._keys value = settings[setting] comment = convertToComment helpText[setting] - settingString = setting .. '=' .. convertToValue value + settingString = setting .. '=' .. convertToValue( value ) .. '\n' table.insert combined, comment table.insert combined, settingString table.insert combined, '' diff --git a/tools/ReadOptionsStub.moon b/tools/ReadOptionsStub.moon index 01a7e36..57432d4 100644 --- a/tools/ReadOptionsStub.moon +++ b/tools/ReadOptionsStub.moon @@ -1,5 +1,6 @@ options = { read_options: -> } -settings = { __keys: { }, __reload: => } -setmetatable settings, __newindex: ( key, value ) => - table.insert @__keys, key +settings = { _keys: { }, _reload: => } +setmetatable settings, { __newindex: ( key, value ) => + table.insert @_keys, key rawset @, key, value +}