Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixin is not working when :new method is present #40

Open
ldurniat opened this issue Nov 2, 2017 · 1 comment
Open

Mixin is not working when :new method is present #40

ldurniat opened this issue Nov 2, 2017 · 1 comment

Comments

@ldurniat
Copy link

ldurniat commented Nov 2, 2017

Modified example from https://github.com/Yonaba/30log/wiki/Mixins is not working. I just added :new method to example from wiki. It raise an error:

attempt to index local 'aWindow' (a nil value)

I use 30log in Corona SDK. After removing :new method there is no errors:)

-- A simple Geometry mixin
local Geometry = {
  getArea = function(self) return self.width * self.height end
}

-- Let us define two unrelated classes
local Window = class ("Window", {width = 480, height = 250})
local Button = class ("Button", {width = 100, height = 50, onClick = false})

function Window:new( name, value )
  self.name = name
  self.value = value
end 

-- Include the "Geometry" mixin in Window and Button classes
Window:with(Geometry)
Button:with(Geometry)

-- Let us define instances from those classes
local aWindow = Window()
local aButton = Button()

-- Instances can use functionalities brought by Geometry mixin.
print(aWindow:getArea()) -- outputs 120000
print(aButton:getArea()) -- outputs 5000
@ldurniat ldurniat changed the title Mixin is not working when :new is present Mixin is not working when :new method is present Nov 2, 2017
@jtoy
Copy link

jtoy commented Apr 20, 2022

dead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants