Quantcast
Database get/set general functions - WoWInterface
Thread Tools Display Modes
06-04-08, 04:55 AM   #1
Silmano
A Murloc Raider
 
Silmano's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 9
Question Database get/set general functions

Having this piece of code in ACE3:
Code:
local options = {
	name = "testOptions",
	type = "group",
	args = {
		test1 = {
			name = "Test1",
			desc = "Test1",
			type = "toggle",
			get = getOption,
			set = setOption,
		},
		test2 = {
			name = "Test2",
			desc = "Test2",
			type = "toggle",
			get = getOption,
			set = setOption,
		},
	},
}

local defaults = {
	profile = {
		test1 = true,
		test2 = true,
	},
}

self.db = LibStub("AceDB-3.0"):New("TestDB", defaults, "Default")
How can I make a general get/set function and delete all custom funtions for each of the options?

Something like:
Code:
function getOption(value)
	return db.value (or whatever) -- where db.value should be self.db.profile.test1 (or test2)
end
What I want to avoid is having to make each get/set function per option:
Code:
function getTest1()
	return self.db.profile.test1
end

function setTest1(value)
	self.db.profile.test1 = value
end

function getTest2()
	return self.db.profile.test2
end

function setTest2(value)
	self.db.profile.test2 = value
end

...
  Reply With Quote
06-04-08, 05:39 AM   #2
VagrantEsha
Token Werewolf Fan
 
VagrantEsha's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 27
Code:
local options      = {}
options.name       = "testOptions"
options.type       = "group"
options.get        = myGetFunc
options.set        = mySetFunc

options.test1      = {}
options.test1.name = "Test1"
options.test1.desc = "Test1 description."
options.test1.type = "toggle"
options.test1.arg  = "myTestVariable1"

options.test2      = {}
options.test2.name = "Test2"
options.test2.desc = "Test2 description."
options.test2.type = "toggle"
options.test2.arg  = "myTestVariable2"
Sorry about my weird formatting, I do it for readability (I find that it makes my mods easier to maintain, for me at least).
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Database get/set general functions

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off