View Single Post
04-13-11, 02:30 AM   #7
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Originally Posted by Vladinator View Post
On the subject (kind of), is it possible to add a new function, let's say:

string:fc = function() return self:sub(1, 1):upper() end
local str = "hello world"
print(str:fc()) -- prints "H"

Not sure if it's doable without causing taint and break other addons, considering string is quite global.
The only way to directly define a colon-notation version of the function is:

Code:
function string:fc()
        return self:sub(1, 1):upper()
end
This is perfectly legal and non-tainting, since the Lua string library in no way controls or impacts the WoW API.

To do it the way you alluded to, you'd need to do it thusly:

Code:
string.fc = function(self)
        return self:sub(1, 1):upper()
end
At that point, you'd be able to call the function using colon-notation.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.

Last edited by Torhal : 04-13-11 at 02:34 AM.
  Reply With Quote