加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

middleclass-extras

This is a set of additions to middleclass.

Warning:

middleclass-extras was made for middleclass 1.x and it’s not under development any more.

middleclass 2.x has some features that make it incompatible with middleclass-extras.

middleclass-extras is being (slowly) re-done as a series of smaller libs. Right now, the only one completely finished is Stateful:

Other libraries might follow, but it might just take time. Sorry about that.

Module brief description

What follows is a brief description of each of the middleclass-extras modules. Each nodule is commented out with usage examples. You can find more examples on the /spec/ folder.

  • Apply allows invoking a method in all the instances of a class (and its subclasses). It also allows sorting before executing.
  • Beholder is a small signaling/event controller mixin. Your classes can ‘observe’ and ‘stop observing’ events. Note that Invoker must be required before Beholder, or the later will not work.
  • Branchy defines some useful methods for classes that behave like trees (addChild, getAncestors, etc)
  • Callbacks is a powerful mixin that allows you to add ‘hooks’ to any existing method. For example, you can specify on runtime that you want to call a method after initializing one object.
  • GetterSetter just adds a couple convenience getXXX, setXXX methods to your class.
  • Indexable allows classes to have a ‘fallback’ method, similar to lua’s __index metamethod. Since __index is reserved, the method used for lookup will be index, whithout underscores.
  • Invoker is a very small mixin that can be used to ‘send’ methods to instances. It’s main advantage is that it accepts both method names and lua functions on its parameters.
  • Stateful defines stateful objects. Classes receive a new method called addState, and instances receive a new method called gotoState. The behaviour of each of the instance methods can be redefined per-state.

Downloading

The recommended way is using git.

In order to use middleclass-extras, you also need middleclass. You can download them both by doing:

cd your/project/path
git clone git://github.com/kikito/middleclass.git
git clone git://github.com/kikito/middleclass-extras.git

Alternatively, you can manually download them:

Usage

middleclass-extras is prepared to be required right after middleclass:

  require('middleclass.init')
  require('middleclass-extras.init')

Notes:

  • You can remove the .init part from middleclass if you are using middleclass as a file (middleclass.lua) instead of as a dir (middleclass/)
  • You can remove the .init part on both requires if your package.path setting already includes ?/init.lua

Specs

You may find the specs for this library in middleclass-specs

Copyright (c) 2010, Enrique García Cota All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of middleclass-extras nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

暂无描述 展开 收起
Lua
BSD-3-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化