Permalink
Browse files

added initial README and license

  • Loading branch information...
0 parents commit c4fdf6513dd723153ef089c32ef4c9dae83cc2e6 @kikito committed Sep 22, 2011
Showing with 92 additions and 0 deletions.
  1. +20 −0 MIT-LICENSE.txt
  2. +72 −0 README.textile
20 MIT-LICENSE.txt
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Enrique García Cota
+
+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.
72 README.textile
@@ -0,0 +1,72 @@
+h1. Stateful
+
+Lua Stateful OOP mixin to be used with "middleclass":https://github.com/kikito/middleclass
+
+* Classes gain the capacity of creating "states"
+* States can override instance methods and create new ones
+* States are inherited by subclasses
+* States are stackable - the state on the top of the stack is the most prioritary
+* There are callback functions invoked automatically when a state is entered, exited, pushed, popped ...
+
+h1. Example
+
+What follows is a basic example:
+
+<pre>
+require 'middleclass'
+Stateful = require 'stateful'
+
+local Enemy = class('Enemy')
+Enemy:include(Stateful)
+
+function Enemy:initialize(health)
+ self.health = health
+end
+
+function Enemy:speak()
+ return 'My health is' .. tostring(self.health)
+end
+
+local Immortal = Enemy:addState('Immortal')
+
+-- overriden function
+function Immortal:speak()
+ return 'I am UNBREAKABLE!!'
+end
+
+-- added function
+function Immortal:die()
+ return 'I can not die now!'
+end
+
+local peter = Enemy:new(10)
+
+peter:speak() -- My health is 10
+peter:gotoState('Immortal')
+peter:speak() -- I am UNBREAKABLE!!
+peter:die() -- I can not die now!
+peter:gotoState(nil)
+peter:speak() -- My health is 10
+</pre>
+
+
+h1. Installation
+
+First, make sure that you have downloaded and installed "middleclass":https://github.com/kikito/middleclass
+
+Just copy the stateful.lua file wherever you want it (for example on a lib/ folder). Then write this in any Lua file where you want to use it:
+
+<pre>require 'middleclass'
+local Stateful = require 'stateful'</pre>
+
+The @package.path@ variable must be configured so that the folder in which stateful.lua is copied is available, of course.
+
+Please make sure that you read the license, too (for your convenience it's now included at the beginning of the middleclass.lua file).
+
+h1. Specs
+
+This project uses "telescope":https://github.com/norman/telescope for its specs. If you want to run the specs, you will have to install telescope first. Then just execute the following from the root inspect folder:
+
+<pre>
+tsc -f spec/*
+</pre>

0 comments on commit c4fdf65

Please sign in to comment.