View Single Post
04/30/14, 12:13 PM   #11
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by skyraker View Post
I'm trying to convert the use of a string as a function call from the global namespace to calling local functions.

Lua Code:
  1. buttonname:SetHandler( "OnClicked" , function() _G[toggleFunction](buttonname) end)

How do I make this same call of toggleFunction without those functions being global? For example, toggleFunction ends up being ToggleLocation, but I have local function ToggleLocation?
I really wonder why do you not use Seerah's suggestion:
Originally Posted by Seerah View Post
Why aren't you just doing
Lua Code:
  1. buttonname:SetHandler("OnClicked", toggleFunction)
I'm not a programmer, but as far as I know handler will receive "self" (that is what you call "buttonname") as a default argument.

I you really want to use function(), I believe it should have defined argument:
Lua Code:
  1. buttonname:SetHandler( "OnClicked" , function(buttonname) toggleFunction(buttonname) end)
or because default argument is "self":
Lua Code:
  1. buttonname:SetHandler( "OnClicked" , function() toggleFunction(self) end)
Correct me if I am wrong.
  Reply With Quote