I admit defeat
I haven't a clue why all of the sudden it no longer makes sense to me, but after more than a year away - I can't seem to write lua anymore. :(
It refuses to register in my thick skull, leaving me feeling rather inadequate right now (Ok, I have the flu together with abdo flu, so I am feeling quite down.) I've been trying to wrap my head around how others do the scope, event handling, module setup, but it seems to elude me. Say, p3lim, he handles it well I think, but I just don't understand : https://github.com/p3lim-wow/Inomena...er/Inomena.lua (I am certain if I understand it, I am saved) Basically; here's what I've been trying to achieve : - Have my basic UI setup in one add-on, which I had working - but then I made the feverish decision to redo the entire thing. -- I was going to have it modular again, as it was. -- this is no longer working of course. -- I wanted to have my core.lua contain the event handlers and utility functions core.lua is setup and works, however, I seem to have lost the "module" effect, and I can't seem to figure it out. I looked at various other add ons written by people whom I greatly admire - but I just am not seeing the light. Not when it comes to the modular nature, not when it comes to event handling. It's set up as follows : Code:
Eavu.toc |
You need to register events before you can trigger them:
Lua Code:
I think coding when you're sick is a bad idea, i tried do "programming" once i was drunk, thex next day was a massive omg wtf rollback. :) However that table should contain the events you want to register: Lua Code:
Also if you use the in pairs loop then you need to register it's v part not the k. (But it depends how your table looks like.) |
the only good things about this coding when sick area. I keep losing my train of thought.
b. I am not afraid to delete ENTIRE files (yep, I am missing half an add-on) and especially c. I actually use github, and "gitted" almost everything. I keep wondering though : Lua Code:
Frame handler created just to deal with all the OnEvents Lua Code:
But then this mastodont .. just wild Lua Code:
There has got to be an easier way that I *can* understand :P But I am watching too many events to just do each one separately, all I wanted was to find that one "event handler" that I can drop into my eavu.lua (is loaded first btw) and then use Eavu.EVENT() in the other modules. |
Quote:
I actually declare my functions like so (Only the Eavu.Print doesn't work, simply because - well the modular aspect got lost somehow. You see how I have to redo the event handler again, even though this is a module? lua Code:
|
What p3lim does is create his own implementation of RegisterEvent, where he can pass a handler function as a second argument to it. The code then checks whether a handler is already present for the passed event. If not, it creates a table entry with the event as the key and the handler as the value (the value is of type function). If there is already a handler, and the handler is a function, it changes the table entry so that the key is the event and the value is a new table containing the old and the new handler (so it is an array with 2 values, both are of type function) and sets his metatable to it (more on that below). If the handler is not of type function (it will then be a type table) it just injects the new handler into that table.
The __call metamethod allows a table to be called like a function and defines what the return of that should be. The first argument it gets is the table itself, followed by all the arguments passed in table call. In p3lim's case it tells it to execute all the handlers registered to the given event. |
Quote:
|
Quote:
Also: Be nice to Kaelten - I've been stoned ranting about incoherent coding stuff to him for a day or two .... I think I've made him face palm quite a few times |
That can be fun, though!
|
Quote:
|
All times are GMT -6. The time now is 02:07 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI