Help with Lua OO
Here is an error I'm having trouble tracking down.
Message: Interface\AddOns\SandBox\libs\UnitTests.lua:38: attempt to call method 'is_a' (a string value) Here's my class declaration followed by the _init(...) definition Lua Code:
Now, here's the test code that elicits the error: Lua Code:
It fails with the message shown above. Both function and property work as expected in the base class. Any thoughts? |
Code:
function Slot:is_a() Code:
local s = Slot(1,1) Code:
self.is_a = "Slot" Code:
DEFAULT_CHAT_FRAME:AddMessage( s:is_a() ) |
Well, thanks as always, Fizzlemizz but I'm not sure I understood your suggestion. For example, I rewrote the method and changed its name from this (the original):
Code:
function Slot:is_a() Code:
function Slot:type() So, after all this, did I misunderstand your suggestion? Cheers, |
Your original code with a few print statements
Lua Code:
At each print (excluding the last) you will notice the the table is the same. That means that during the intitialisation of s (local s = Slot(1,1)) when the code gets too: Code:
self.is_a = "Slot" Code:
Slot.is_a = "Slot" Code:
function Slot:is_a() I think you're thinking that s should actually be a new table entry in the Slot table. |
Quote:
Thanks and cheers, |
All times are GMT -6. The time now is 09:18 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI