Coder Social home page Coder Social logo

agui888 / object-lua Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sroccaserra/object-lua

0.0 2.0 0.0 385 KB

[Deprecated] A class-oriented OOP module for Lua

Home Page: http://lua-users.org/wiki/ObjectLua

License: Other

Emacs Lisp 0.07% Ruby 2.79% Lua 95.67% HTML 1.47%

object-lua's 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

object-lua's People

Contributors

sroccaserra avatar

Watchers

James Cloos avatar  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.