Jump to content




Get handler within function within handler


  • You cannot reply to this topic
4 replies to this topic

#1 Selim

  • Members
  • 189 posts
  • LocationHiding 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 by Selim, 05 February 2016 - 03:15 PM.


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 05 February 2016 - 03:24 PM

local handler = {}

handler.handlerFunction = function() return handler end


#3 Selim

  • Members
  • 189 posts
  • LocationHiding in Online Storage

Posted 05 February 2016 - 03:25 PM

Wow...should have thought of that...

#4 wilcomega

  • Members
  • 466 posts
  • LocationHolland

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

View PostLyqyd, on 05 February 2016 - 03:24 PM, said:

local handler = {}

handler.handlerFunction = function() return handler end

View PostSelim, on 05 February 2016 - 03:25 PM, said:

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

#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users