Thread Tools Display Modes
04-08-13, 03:01 PM   #1
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
GlueStrings.lua from ingame

Is there a way to access the contents of GlueStrings.lua from ingame? I'm particularly interested in CHARACTER_SELECT_INFO_GHOST to get translations for 'Ghost' but
Code:
/dump CHARACTER_SELECT_INFO_GHOST
returns nothing.
  Reply With Quote
04-08-13, 03:12 PM   #2
Gethe
RealUI Developer
 
Gethe's Avatar
Premium Member
Featured
Join Date: Sep 2008
Posts: 942
Try this:

Code:
/run print(CHARACTER_SELECT_INFO_GHOST)
__________________
Knowledge = Power; Be OP

  Reply With Quote
04-08-13, 04:12 PM   #3
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
It would still return nothing, i.e. "nil" if that global doesn't exist.
__________________
Profile: Curse | Wowhead
  Reply With Quote
04-08-13, 05:01 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Rainrider View Post
I'm particularly interested in CHARACTER_SELECT_INFO_GHOST to get translations for 'Ghost' ....
You can use GetSpellInfo to get translations for anything that gives you a debuff, including Ghost:

Code:
/dump (GetSpellInfo(8326))
The extra parentheses are so you'll only get the first return (the localized name) rather than the whole list of returns. If you're using it in another context you don't need them:

Code:
local GHOST = GetSpellInfo(8326)
Code:
print("You are a " .. GetSpellInfo(8326))
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
04-08-13, 06:23 PM   #5
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
The problem is that the german translation for the spell is "Geisterscheinung" which actually means "ghost appearance" and that's kind of lengthy. Funny enough they translated it "Geist" for CHARACTER_SELECT_INFO_GHOST. I'd rather not truncate based on client locale if I could avoid that.

So no way to access GlueStrings.lua from an addon?
  Reply With Quote
04-08-13, 07:35 PM   #6
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Rainrider, no no, if it's in globalstrings.lua then it's a global variable accessible from all lua related code.

Phanx was just trying to provide an alternative way to obtain the translation of the word "Ghost" if "CHARACTER_SELECT_INFO_GHOST" is not defined, i.e. is nil. Like I said if using "/dump CHARACTER_SELECT_INFO_GHOST" returns nil then chances are it's not a defined variable, maybe the globalstrings.lua you are looking at is outdated?

Actually, by the look of the string itself it appears you might have looked at the "glue" folder, those files are only used at login and not when in-game, so those are simply not loaded when you are in-game, only at the login screen. That explains why CHARACTER_SELECT_INFO_GHOST doesn't exist when dumping, hehe.

There is no alternative for the word "Ghost" but like Phanx said, you can use a spell for instance, to obtain the word as spells are localized too! Just look at Phanx' post.
__________________
Profile: Curse | Wowhead
  Reply With Quote
04-08-13, 08:47 PM   #7
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
@Vlad

Yes, I do look at GlueXML/GlueStrings.lua, never said something about GlobalStrings.lua. I also found out it is not in _G, that's the reason I came here to ask. If something is in not in _G it doesn't mean it is not somewhere else or accessible in some other way.

Based on Phanx proposal my code currently looks like this:
lua Code:
  1. if (UnitIsDead(unit)) then
  2.     return _G["DEAD"]
  3. elseif (UnitIsGhost(unit)) then
  4.     local ghost = GetSpellInfo(8326)
  5.     if (GetLocale() == "deDE") then
  6.         ghost = ghost:sub(1, 5)
  7.     end
  8.     return ghost
  9. elseif (not UnitIsConnected(unit)) then
  10.     return _G["PLAYER_OFFLINE"]
  11. end

I'm still interested in accessing what's in GlueStrings.lua though if this is possible.
  Reply With Quote
04-08-13, 08:56 PM   #8
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,335
To further clarify what Vlad said, WoW runs two completely isolated Lua systems. GlueXML is what is used to display and run everything up to and including the Character Select and Character Creation screens. The GlueXML system has its own API to handle these related screens. The other system is FrameXML and this is what handles the game itself after you login and have chosen your character. Since addons are loaded into FrameXML, there is no way to modify or even access the GlueXML system.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
04-08-13, 09:14 PM   #9
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Originally Posted by SDPhantom View Post
Since addons are loaded into FrameXML, there is no way to modify or even access the GlueXML system.
Thank you Thanks to Phanx for the proposal and to Vlad for the patience too
  Reply With Quote
04-08-13, 09:19 PM   #10
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,335
Originally Posted by Rainrider View Post
Based on Phanx proposal my code currently looks like this:
lua Code:
  1. if (UnitIsDead(unit)) then
  2.     return _G["DEAD"]
  3. elseif (UnitIsGhost(unit)) then
  4.     local ghost = GetSpellInfo(8326)
  5.     if (GetLocale() == "deDE") then
  6.         ghost = ghost:sub(1, 5)
  7.     end
  8.     return ghost
  9. elseif (not UnitIsConnected(unit)) then
  10.     return _G["PLAYER_OFFLINE"]
  11. end
Instead of truncating the string, you can have your code override the translation on load. The following example uses the localized spell name, then checks for specific locales to see if it needs to be changed. Replacing the entire string with a new one is less taxing on the system and if they ever decide to change the translation, it won't be screwed up.
Lua Code:
  1. local GHOST,Locale=GetSpellInfo(8326),GetLocale();
  2. if Locale=="deDE" then
  3.     GHOST="Geist";
  4. end
  5.  
  6. local function UnitDeadText(unit)
  7.     if UnitIsDead(unit) then
  8.         return DEAD;
  9.     elseif UnitIsGhost(unit) then
  10.         return GHOST;
  11.     elseif not UnitIsConnected(unit) then
  12.         return PLAYER_OFFLINE;
  13.     end
  14. end



Another performance issue I fixed; unless the table field is an invalid variable name or you need to access a series of names based on a looping mechanism or any dynamic method, you should avoid using _G[].

To better understand this problem, Lua operates by looking through locals first, upvalues (locals in a higher scope), and finally global. When accessing a global by _G[], you're telling Lua to access the global list for a copy of itself, then access your variable.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-08-13 at 09:40 PM.
  Reply With Quote
04-09-13, 06:23 AM   #11
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Nice to know, thanks for the advice. I use _G[] to skip local checks, as I thought it would be wasted search time, and to emphasize those are global constants to make code more readable. I also saw some addons defining local _G = _G and a search on wowinterface idicated this is to speed up global access. If I understand you correctly using _G[] is kind of the same as using local _G = _G in a local scope (not as upvalue), isn't it?
  Reply With Quote
04-09-13, 06:32 AM   #12
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
I don't think using _G would skip any steps because lua would still look up _G in the local scope before moving to the global one.
  Reply With Quote
04-09-13, 03:15 PM   #13
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Rainrider View Post
I also saw some addons defining local _G = _G and a search on wowinterface idicated this is to speed up global access. If I understand you correctly using _G[] is kind of the same as using local _G = _G in a local scope (not as upvalue), isn't it?
local _G = _G is totally useless unless you are looking up dynamically constructed keys like:

Code:
for i = 1, 5 do 
    local chatFrame = _G["ChatFrame"..i]
    -- do something with chatFrame
end
Doing things like _G.UnitName("player") is useless and just makes your code more cluttered. If you know that you want to use UnitName just use it directly.

Upvaluing functions is not really that useful as a general rule, and just adds code clutter. The only time the speed difference is even possibly meaningful is if you are calling the function inside an OnUpdate script, COMBAT_LOG_EVENT_UNFILTERED handler, or other context where it is called potentially dozens or hundreds of times per second. If you're calling a function once each time PLAYER_ENTERING_WORLD fires, for example, upvaluing that function doesn't realistically add anything.

Remember, the first rule of program optimization -- don't do it -- and the second rule -- don't do it yet. Get your code working first, and then you can go over it to optimize, but even then don't go overboard.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
04-09-13, 07:42 PM   #14
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Thank you very much for all the advises, I really appreciate it. I only upvalue API functions I use in code reacting to UNIT_{HEALTH|POWER}_FREQUENT in my oUF layout, as I use those events on a lot of frames (which is probably a waste and is on my todo list to check and change). I don't have any experience in CPU profiling in WoW or in general and would be glad to get some pointers in that direction, though I believe I have some way left to go until my code reaches a satisfying level of functionality and readability.

Thanks again for all your help!
  Reply With Quote
04-09-13, 07:45 PM   #15
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,335
Since locals and upvalues are registry entries in Lua, the lookups for them are negligible. Relatively, all of the time spent is the table indexing operation used to find a value in the global environment. Accessing _G[] effectively doubles the time spent accessing a global since it requests an indexing for _G in the global environment, which is a copy of itself, then requests an index of that copy. If you had stored _G in a local pointer and used that instead, past the setup, it would offer no difference to performance since it would still be using an index operation to look up a value.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » GlueStrings.lua from ingame


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