View Single Post
12-31-18, 07:01 PM   #1
mtp1032
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 22
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:
  1. Slot = {}
  2. Slot.__index = Slot
  3.  
  4. setmetatable(Slot, {
  5.     __index = Container,        -- makes the inheritance work
  6.      __call = function (cls, ...)
  7.     local self = setmetatable({}, cls)
  8.     self:_init(...)
  9.     return self
  10.   end,
  11. })
  12.  
  13. -- This is the _init function.
  14. function Slot:_init( bagNumber, slotIndex )
  15.            
  16.     Container._init(self)               -- call the base class constructor
  17.     self.is_a = "Slot"                   -- in the parent class, this is set to "Virtual Container"
  18. end
  19.  
  20. -- the is_a() method
  21. function Slot:is_a()
  22.    return self.is_a
  23. end

Now, here's the test code that elicits the error:

Lua Code:
  1. local s = Slot(1,1)
  2. DEFAULT_CHAT_FRAME:AddMessage( s:is_a() )

It fails with the message shown above. Both function and property work as expected in the base class.

Any thoughts?

Last edited by mtp1032 : 12-31-18 at 08:01 PM. Reason: Forgot to copy "Slot.__index = Slot"
  Reply With Quote