Thread Tools Display Modes
03-28-09, 11:36 AM   #1
jadakren
A Flamescale Wyrmkin
 
jadakren's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 103
tagstrings & editing of them

Regarding tagstrings,

I assume that it's not possible to return the contents of a function as a string?

idea i have is to edit tags and the functions that drive them, but in order to do this it seems I would need to provide them as strings and somehow execute them with loadstring.

ideas?

Code:
oUF.Tag["[name]"] = function(u)
 local func = "UnitName(u)"
 return u~=nil and loadstring(func) or func
end
I assume this would allow me to continue using the tagstring normally. But it would also allow me access to the function generating the output value, since i have such an approach for an ingame editor to obtain the internals for this tag :

Code:
function config:GetTagOptions(tag)
 local funcString = oUF.Tag[tag] or nil
 return (funcString~=nil and tostring(funcString())) or 'error'
end
function config:SetTagOptions(tag,funcData)
 oUF.Tags[tag] = function(u) 
  local func = funcData.func
  return loadstring(func)
 end
end
Here we suppose some kind of ingame editor is told to change the way the tagstring '[name]' behaves so that it makes names lowercase :
Code:
oUF.SetTagOptions('[name]',{func = 'UnitName(u):lower()'})
any ideas or thoughts to make this idea better/workable/more efficient or just maybe any kind of thoughts you have?
  Reply With Quote
03-28-09, 11:41 AM   #2
jadakren
A Flamescale Wyrmkin
 
jadakren's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 103
One idea i have for this is to store the function logic as strings within another table. (oUF.TagsLogicStrings)

upon initial addon_loaded event i would compile each function string to the oUF.Tags table and from that point ouf.tags is operating as it does normally.

when a user needs to edit the logic, the editor then pulls the logic string from oUF.TagsLogicStrings[tagName] and presents it the editor multiline field.

user then modifies the logic and saves it at which point the string is recompiled back to oUF.Tags.
  Reply With Quote
03-28-09, 01:02 PM   #3
jadakren
A Flamescale Wyrmkin
 
jadakren's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 103
Here is a proof of concept, that i got working this morning :

Code:
tags = {
 ['[faction]'] = function(u)
   return u
 end,
}
events = {
 ['[faction]'] = "UNIT_FACTION"
}

ReWriteTag = function(tag,hooks,logic)
 if tag then 
  local builder = assert(loadstring("return "..logic))
  if(builder) then tags[tag] = builder() end
 end
 if hooks then events[tag] = hooks end
end

testTag = [[function(u) return UnitFactionGroup(u) end]]
testEvent = "UNIT_FACTION"

print(tags['[faction]']('player'))

ReWriteTag('[faction]',testEvent,testTag)

print(tags['[faction]']('player'))
  Reply With Quote
03-29-09, 03:13 PM   #4
jadakren
A Flamescale Wyrmkin
 
jadakren's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 103
i've hit a brick wall with this.

using the playerframe as an example try to change the tag of a fontstring without a uireload.

for the sake of this exercise the current tag is '[curpp]'

Code:
ofp = oUF_Player
fontobj = ofp.Power.text

newtag = '[perpp]%'

ofp:Untag(fontobj)
ofp:Tag(fontobj,tag1)
fontobj:UpdateTag()
I can get the fontstring to only change once, at the point where i call fontobj:UpdateTag()

After that initial call, it seems that it no longer has an update handler and therefore never continues to fire upon relevant events.

how do i get the fontstring to update on the events specified with the new tag?

Last edited by jadakren : 03-29-09 at 03:40 PM.
  Reply With Quote
03-30-09, 12:32 AM   #5
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
The new tag your giving it is nil, so I'm guessing that's where your problem is located. When I tried to :Tag() :Untag() and :Tag() it worked fine at least.

You did however locate a little issue, which is that oUF didn't remove the :UpdateTag() function when you :Untag'd a fontstring.

I haven't had time to look at your concept yet, but I guess I will later today.
  Reply With Quote
03-30-09, 02:03 AM   #6
jadakren
A Flamescale Wyrmkin
 
jadakren's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 103
Opps, yes i made a mistake in that example. But i was able to get all tags to change providing i used the UpdateTag() function.

Although while i was investigating this concept last night, i did actually get the tag to change to a new one and continue updating at that point.

But this only occured once or twice and despite my repeated attempts to re-produce it ... i failed miserably.

Once i look again, i'll post up here my understanding of how the tag system works. Maybe i am misunderstanding the process.
  Reply With Quote
03-30-09, 03:24 AM   #7
jadakren
A Flamescale Wyrmkin
 
jadakren's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 103
ah yes i see now, untag isn't removing the old event driver from the events table.

it is also inserting our new one but isn't reassigning the new driver to our current fontstrings set of events.

is this because our fontstring (indentified by tableid) is still in the events table?
  Reply With Quote
03-30-09, 06:58 AM   #8
jadakren
A Flamescale Wyrmkin
 
jadakren's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 103
as i wrote in the bug(?) report, i replaced my current ouf/elements/tags.lua with the one found on your git repo and it now performs as per expected.

I still don't really understand the whole process.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » tagstrings & editing of them


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