Thread Tools Display Modes
03-21-07, 04:26 AM   #1
ngollon
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 9
How to call non-global functions by name?

Hi!

I've got the following problem.
Suppose the string f contains the name of a function. If f is a global function, I can call ist via the environment _G. Like

f = "UnitHealth"
health = _G[f]("player"),

but if f is a function, like all these functions in Ace Addons, this does not seem to work, i.e.:

f = "sRaidFrames.Print"
_G[f]("Hello World!")

returns an error. Is there a way to make this work? =)
I hope I've made my problem clear. Please don't ask me, why I'd want to do that. I want it =)

Thanks much!
Vaeyl

Last edited by ngollon : 03-21-07 at 02:38 PM.
  Reply With Quote
03-22-07, 08:54 AM   #2
Synthos
A Deviate Faerie Dragon
Join Date: Mar 2007
Posts: 10
A function in an ace addon is really just a function in a table.

You can call a table function just like globals, but without the _G.

it'll be something like sRaidFrames["Print"]("Hello World");
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to call non-global functions by name?


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