SECS
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: SECS
Have you tried the LÖVE Wiki? Here's an example: http://love2d.org/wiki/index.php?title=SECS#Example_2 (there are 2 other examples on the same page).
Help us help you: attach a .love.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: SECS
Well, you start with this:
which creates a new class/object (they are both in my implementation)
You add the stuff you want:
And there you have it, a class, create objects like this:
Code: Select all
myclass = class:new()
You add the stuff you want:
Code: Select all
function myclass:hello()
print("Hello!")
end
Code: Select all
myobject = myclass:new()
myobject:hello()
Re: SECS
I've been using SECS for a long time, and after modifying it bit by bit... I've now ended up with something thats "intermediate" to the simple and advanced version. The class of each instance is its metatable, but the superclass of a class isn't the class's metatable.
Code: Select all
----------------------------------------------------------------------------
-- Copyright (c) 2009 Bart Bes
--
-- Permission is hereby granted, free of charge, to any person
-- obtaining a copy of this software and associated documentation
-- files (the "Software"), to deal in the Software without
-- restriction, including without limitation the rights to use,
-- copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the
-- Software is furnished to do so, subject to the following
-- conditions:
--
-- The above copyright notice and this permission notice shall be
-- included in all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-- OTHER DEALINGS IN THE SOFTWARE.
----------------------------------------------------------------------------
-- Single Inheritance Classes.
local class, class_mt={}, {}
class.__index=class
setmetatable(class, class_mt)
function class_mt:__index(key)
if rawget(self, "__class") then
return self.__class[key]
end
return nil
end
function class:new(...)
-- Call this to make an instance from a class. ... are init parameters
local c = {}
c.__class = self
c.__index=c
setmetatable(c, self)
if c.init then
c=c:init(...)
end
return c
end
function class:subclass(t)
-- Call this to subclass the class. t is a table.
-- i.e class will be the super of t.
t.__class = self
setmetatable(t, getmetatable(self))
return t
end
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 14 guests