• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

sroccaserra/object-lua: [Deprecated] A class-oriented OOP module for Lua

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

sroccaserra/object-lua

开源软件地址(OpenSource Url):

https://github.com/sroccaserra/object-lua

开源编程语言(OpenSource Language):

Lua 97.1%

开源软件介绍(OpenSource Introduction):

[Deprecated]

I now prefer to use native prototype-based object oriented programming, in both Lua and JavaScript.

For inspiration, you can look at these JS refs:

And of course, the historical papers about prototypical objects:

ObjectLua

A class-oriented OOP module for Lua

This is an implementation of a class-oriented Lua module, coded entirely in Lua. The object model allows you to override new() (see tests), so you can write classes that behave the way you want. While still in design stage, the interface is getting quite stable and I will add a multiple inheritance mechanism if a user asks me to, or if I need it miself.

This is a beta release, please report bugs & feature requests to the project's UserVoice Page.

Features

  • Class oriented
  • All classes derive from Object
  • Single inheritance (will add multiple if someone needs it)
  • All method calls are virtual, the class of the instance determines the bound method
  • Access to superclass method in overriden methods with a Java-like super.method(self)
  • The use of super only grants access to methods, NOT to data members (prevents many evils)
  • Consistent use of :, always use : to call any method of any class or instance
  • Object model allows to redefine new() in any class (see tests)
  • Use has to define members (inspired by Moose)
  • Hopefully only one way to do things, very predictible results

Note: there is a Prototype.lua file in the package, which is completely independant, but if you need prototype-based oop have a look at it (it provides a super(self) function).

Warnings

  • This is a beta release. Changes can be made in the future
  • No optimization. This is still in the design stage

Code

This project's code can be dowloaded from its GitHub page.

You can also install ObjectLua from LuaRocks:

$ luarocks install objectlua

Tests and Usage

See TestObject.

The tests documenting ObjectLua usage can be found in the test directory. You can run them with:

$ rake test

They use LuaUnit.

References

The main point is to bootstrap the object model and then, build on it to populate Class with new(), inheritsFrom(), subclass(), and Object with initialize(), isKindOf(), clone()...

Thanks to Ludovic Perrine for making things clearer with enlightening discussions. Thanks to Robert Rangel for finding a blocker bug fixed in version 0.0.3.

See Also




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap