yaci.lua
yaci.lua copied to clipboard
There exists a problem when super and virtual are used at the same time.
This problem can be found in the README.md.
It's the example under '''Instances methods'''.
1 -- Use Yaci 1.2 2 -- http://lua-users.org/wiki/YetAnotherClassImplementation 3 require("yaci") 4 5 A = newclass("A") 6 function A:test() print(self.a) end 7 A:virtual("test") -- declare test() as being virtual; see below 8 function A:init(a) self.a = a end 9 10 B = newclass("B", A) 11 function B:test() print(self.a .. "+" .. self.b) end 12 function B:init(b) self.super:init(5) self.b = b end 13 14 b = B:new(3) 15 b:test() -- prints "5+3" 16 b.super:test() -- prints "5" 17 print(b.a) -- prints "5" 18 print(b.super.a) -- prints "5"
This is the code I tested. The line number 16 causes error message like:
$ lua instances.lua 5+3 lua: instances.lua:11: attempt to concatenate field 'b' (a nil value) stack traceback: instances.lua:11: in function 'test' instances.lua:16: in main chunk [C]: ?
I am getting the same error, it works when I put placeholder methods instead of setting it virtual.