Giter Site home page Giter Site logo

class.lua's Introduction

Class.lua

Another class library for lua. This one has getters and setters. MIT License.

Syntax:

To add to your project, at the top of main.lua, put this:
require 'class' -- or whatever directory you put it in
This will (start to) implement a basic rectangle class:
rect = class()

rect.init = function(self, ...)
	local arg = {...}
	self.x = arg[1] or 0
	self.y = arg[2] or 0
	self.w = arg[3] or 0
	self.h = arg[4] or 0
end

rect.left = {
	get = function(self)
		return self.x - self.w / 2
	end,
	set = function(self, val)
		self.x = val + self.w / 2
		return self
	end
}

rect.right = {
	get = function(self)
		return self.x + self.w / 2
	end,
	set = function(self, val)
		self.x = val - self.w / 2
		return self
	end
}
Class methods are handled the same way as most other class libraries:
rect.move = function(dx, dy)
	self.x = self.x + dx
	self.y = self.y + dy
	return self
end
Inheritance (including multiple inheritance) is also supported:
quad = class()
... -- quad methods/properties here

aabb = class(rect, quad) -- make it inherit from rect and quad
                         -- rect comes before quad, so it gets more priority
... -- aabb methods/properties here

About the Samples:

They show off features of the library. At the top of your program, put:
require 'class'
require <insert filename here>
...

Polyclass.lua

(Will be) an incredibly feature rich class library for lua. Meant to go with polycode. Still highly experimental, as it needs to go through testing, as well as compatibility with polycode's c++ classes. MIT License.

Usage

require 'polyclass'

Syntax

class 'Foo'
local count = 0

function Foo:init(x)
	self.x = x
	count = count + 1
end

Foo.static.count = {
	get = function(self)
		return count
	end,
}

You can see how properties are handled, as will as static stuffs.

Limitations

Cannot do static properties that set via function or table This is primarily due to a logistical error with defining non-statics and setting static properties, which both use the same syntax. I may set up a sort of 'packing' of classes once you have defined them.

Compatibility

Supports class commons. Yay!

class.lua's People

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.