Thread Tools Display Modes
03-03-09, 11:51 AM   #1
Ne0nguy
A Fallenroot Satyr
 
Ne0nguy's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 22
Post Question about this variable usage

I have been looking though an addon called BlackList, which the author seems to have abandoned.

The following is all working code... I just have no idea how it is possible:
In the TOC the only saved variable is BlackListConfig:
Code:
(7)	## SavedVariables: BlackListConfig
After VARIABLES_LOADED fires, this runs:
Code:
(54)	if ( not BlackListConfig ) then
(55)		 BlackListConfig = {};
(56)	end
(57)	
(58)	if ( not BlackListConfig[REALM] ) then
(59)		BlackListConfig[REALM] = {};
(60)	end
(61)	
(62)	if ( not BlackListConfig[REALM].blackList ) then
(63)		BlackListConfig[REALM].blackList = {};
(64)	end
(65)	
(66)	_blackList = BlackListConfig[REALM].blackList;
After this point there is no significant reference to "BlackListConfig[REALM].blackList". All changes and additions to the database use "_blackList". Yet all the changes that are made to _blackList are saved and loaded between sessions.

Is there anything special about the naming convention that allows this to happen? There is no direct code copying the contents of _blackList back to BlackListConfig[REALM].blackList at any time.
  Reply With Quote
03-03-09, 12:23 PM   #2
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Is there anything special about the naming convention that allows this to happen? There is no direct code copying the contents of _blackList back to BlackListConfig[REALM].blackList at any time.
Table variables are references to whatever table they're pointed at:

Code:
local x = {1,2,3,4,5}
local y = x
y[3] = "foo"
message(x[3]) --will display foo
local z = CopyTable(y)
z[3] = "bar"
message(y[3]) --will display foo
  Reply With Quote
03-03-09, 12:37 PM   #3
Ne0nguy
A Fallenroot Satyr
 
Ne0nguy's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 22
Thank you for your reply. That has cleared up a few things for me.

I always assumed it was just passing the contents onto the new variable rather than referencing it.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Question about this variable usage


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