Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI('/configuration')
- -- Initializes debugging for CC Config
- -- this sets the log tag to 'demo':upper()
- -- Location: /.config-tmp/VERSION/log.txt
- cc_config_init_debug('demo')
- -- Creates a Config in /.config-tmp/VERSION called 'hiddencfg.cfg'
- local hidden = configuration.new('hiddencfg', 'A Config File Hidden in a Hidden Directory')
- -- Creates a Config in / (the root directory) called 'knowncfg.cfg'
- local known = configuration.new('knowncfg', '/', 'A Config Not Hidden')
- -- This is exclusively logged to the CC Config Log File
- -- iff cc_config_init_debug was called previously
- -- LogLevels tell what the message should be tagged with.
- -- Supports INFO, WARN, and ERROR ('INFO', 'WARN', 'ERR' tags respectively)
- -- Also has aliases in lowercase (INFO==info) and expanded (WARN==warning)
- cc_config_debug(LogLevels.WARN, 'Successfully initialized configs...')
- cc_config_debug(configuration.LogLevels.INFO, 'We can also %s messages. More than %4d :)', 'format', 256)
- cc_config_debug(LogLevels.err, 'For when you don\'t want to THROW an error')
- -- Error messages will actually throw an error and will log to the log file
- -- cc_config_error('You can error too')
- -- cc_config_error('Even with %s messages', 'format')
- -- You can GET Strings, Numbers, Booleans and Lists (tables)
- -- If these values do not exist, they create them in the cfg and return the default value
- -- If they do exist, the cfg value is used but min, max and valid values are overwritten
- local exampleString = hidden:getString('exampleStr', 'category', 'defaultValue', 'Element Comments', {'validValues', 'defaultValue'})
- local exampleNumber = hidden:getNumber('exampleNum', 'category', 0.00612354, '', 0, 1)
- local exampleBoolean = hidden:getBoolean('exampleBool', 'othercategory', true, '')
- local exampleList = hidden:getList('exampleList', 'category.subcategory', {1, 2, 'wow', true}, '', {1, 2, 'wow', true})
- local exampleList2 = hidden:getList('exampleList2', 'category.subcategory', {'one', 90.214, false})
- print(table.concat(exampleList2, ', '))
- -- You can even get the ConfigValue objects themselves
- local configValueObj = known:get('category', 'testCV', 'someValue', 'Comments')
- local configValueObj2 = known:get('othercategory.sub', 'testCV', 256, '', 0, 256)
- configValueObj:set('someOtherValue')
- configValueObj:setValids({'someValue', 'someOtherValue'})
- configValueObj2:set(512)
- configValueObj2:setMax(512)
- print(configValueObj:getRaw())
- print(configValueObj:getString())
- -- configValueObj:getNumber() will error
- print(configValueObj2:getNumber())
- -- You can set category commens by file or retrieve the ConfigCategory object and set it there
- hidden:setCategoryComment('category', 'Example of Setting Category Comments')
- hidden:getCategory('category.subcategory'):setComment('Another Way to set Category Comments')
- -- You MUST save to write out any changes to the cfg file
- hidden:save()
- known:save()
- -- Not required necessarily, but recommended
- -- handles cleaning _G of CC Config functions
- os.unloadAPI('configuration')
Advertisement
Add Comment
Please, Sign In to add comment