Re: Classy - Middleclass Inspired, But a lot faster
Posted: Thu Mar 09, 2017 5:53 pm
Update has been made.
Code: Select all
local Person = class('Person')
Person.species = 'Human'
Person.numArms = 2
Person.numFingers = 10
Person.defaultPicture = love.graphics.newImage('photo.jpg')
Code: Select all
local Person = class('Person', {
species = 'Human',
numArms = 2,
numFingers = 10,
defaultPicture = love.graphics.newImage('photo.jpg'), -- Causes error
}
Code: Select all
Error: libraries/classy/footable.lua:111: [string "return {restQuad=Quad: 0x025dd3e0}"]:1: '<name>' expected near '0x025dd3e0'
stack traceback:
[C]: in function 'assert'
libraries/classy/footable.lua:111: in function '_makeAllocatorFunction'
libraries/classy/classy.lua:213: in function 'class'
class/unit/unit.lua:1: in main chunk
[C]: in function 'require'
main.lua:29: in main chunk
[C]: in function 'require'
[string "boot.lua"]:429: in function <[string "boot.lua"]:275>
[C]: in function 'xpcall'
Code: Select all
-- Class definition ommited.
function Person:__init__()
self.defaultPicture = love.graphics.newImage ('person.jpg')
end
-- Alternatively if you want to save memory for something like this.
Person.static.defaultPicture = love.graphics.newImage('person.jpg')
-- And then...
function Person:__init__(image)
if image then
self.image = love.graphics.newImage (image)
else
self.image = Person.defaultPicture
end
end