SECS

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ub3rl1t
Prole
Posts: 15
Joined: Sun Jul 12, 2009 10:43 pm

SECS

Post by ub3rl1t »

Can some one please explain how i can use this to make my own classes.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: SECS

Post by Robin »

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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: SECS

Post by bartbes »

That was the example for the advanced version..., well anyway, I can now celebrate, the first time anyone has opened a topic about something I made :P (IIRC)
ub3rl1t
Prole
Posts: 15
Joined: Sun Jul 12, 2009 10:43 pm

Re: SECS

Post by ub3rl1t »

i swear im not stupid but i dont understand the example, any extra help would be awesome.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: SECS

Post by bartbes »

Well, you start with this:

Code: Select all

myclass = class:new()
which creates a new class/object (they are both in my implementation)
You add the stuff you want:

Code: Select all

function myclass:hello()
    print("Hello!")
end
And there you have it, a class, create objects like this:

Code: Select all

myobject = myclass:new()
myobject:hello()
User avatar
appleide
Party member
Posts: 323
Joined: Fri Jun 27, 2008 2:50 pm

Re: SECS

Post by appleide »

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
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], dusoft, Google [Bot], Majestic-12 [Bot], Semrush [Bot] and 63 guests