196 posts
Location
Hiding in Online Storage
Posted 05 February 2016 - 03:09 PM
If I have a custom handler for an object and I have a function within the handler, how would I get the handler variable to the function?
Example:
handler = {
handlerFunction = function() end,
}
In the above example, how would I get handler to handerFunction?
Edited on 05 February 2016 - 02:15 PM
8543 posts
Posted 05 February 2016 - 03:24 PM
local handler = {}
handler.handlerFunction = function() return handler end
196 posts
Location
Hiding in Online Storage
Posted 05 February 2016 - 03:25 PM
Wow…should have thought of that…
453 posts
Location
Holland
Posted 05 February 2016 - 03:26 PM
I am not to sure on this, i have had similar problems, one theoretical sollution i thought of was to set the function environment of all functions to the handler and then give the handler a metatable with __index = _G.
but you will have to test it, maybe someone else has a better sollution
local handler = {}
handler.handlerFunction = function() return handler end
Wow…should have thought of that…
this works if you have one object with that name, but wont work if all objects are in the same array probably, maybe my sollution will work
8543 posts
Posted 05 February 2016 - 03:29 PM
Uh, no, you might want to review scope, upvalues, and closures. It'll work anywhere as long as it's set up that way.