With The Global "this:" Gone
Any number of addons have broken. One example is the very useful BugMeNot addon (which I'm trying to patch right now).
I've figured out workarounds for most of the "this:" uses in the BugMeNot.lua code, but not all of them. Any suggestions from others as to how they solved similar problems? A message in another forum addressed this issue, but was damnably sketchy on how to solve the problem. http://forums.worldofwarcraft.com/th...76430349&sid=1 They say "use self and pass it between functions." Yeah, right ... so someone tell me how to do that with BugMeNot.lua? Or Thottbot.lua? Or Dialect.lua? Because I cannot make "self" work ANYWHERE in any real world code. Understand I was a pretty good programmer in my time, but never made the mental jump to OOP, so I'm still pretty shakey about all this stuff about objects, frames, etc. For instance, I have BugMeNot running again (optimized quite a bit even) ... but am still getting errors when making changes on the popup GUI menu (where the code used "this:" numerous times). function DropDownMenuItem_OnClick() UIDropDownMenu_SetSelectedValue(this.owner, this.value); PlaySound("igMainMenuOptionCheckBoxOn"); if (this.value == 0) then --We clicked the first menu item. Enter code here to affect the rest of your mod. elseif (this.value == 1) then --We clicked the second menu item. Enter code here to affect the rest of your mod. end end With every button, every text field, every checkbox being its own separate object, how the HELL can I identify what clicked? Who owns it? What the value was, or is? Thanks in advance. |
Pass a reference to the object with DropDownMenuItem_OnClick. Example:
Code:
f = CreateFrame("MyNewFrame") Code:
function DropDownMenuItem_OnClick(self) LUA isn't OOP. |
Thanks for the (only) response. That's exactly what I did, and my code ended up looking exactly like yours.
Except I'm still getting UIDropDownMenu lua errors: "attempt to index local "frame" (a nil value). It's talking about self, of course. self simply isn't bringing in a frame. And there's no simple "CreateFrame" function in this code: a hugely complicated .xml file is creating frames, buttons, text fields, the lot. Everything seems to have its own bloody name and frame. Oh, and when you're not an OOP programmer, lua certainly DOES look object oriented. Oh sure, it's all just structures and pointers; I know that. But then so is OOP. I don't see any significant difference. But no matter. My check buttons are working fine; it's the 3-selection drop-down menus that are triggering the errors. Almost there, but not quite. |
Some of these addons aren't that easy to convert from the "this" style. You'd have to track down the root of every function call and modify it so the function gets the UI object it needs.
I can take a look into it, but I need to look at the full source code you have running to see where I can patch it up. Btw, Lua is more of a programming framework that's injected into a host environment. It takes whatever form is needed to run. Lua can be OOP through creative use of tables and metatables. WoW's Widget API tries to push it more towards OOP using shared metatables. Also note the WoW implementation is not multithreaded. Going into an infinite loop will cause WoW to freeze. |
All times are GMT -6. The time now is 01:22 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI