Skip to content

Repository files navigation

lua-object

Table of contents

General information

Base class implementation for Lua

Installation

You can:

  • clone the repository:
git clone https://github.com/a1div0/lua-object.git
  • install the lua-object module using tarantoolctl:
tarantoolctl rocks install https://raw.githubusercontent.com/a1div0/lua-object/main/lua-object-1.0.3-1.rockspec

Usage

Create a child class

localObject=require('lua-object')
localNewClass=Object:extend()
localNewClassChild=NewClass:extend()

Creates an instance of the class

localobj=NewClass:new(a, b, c...)

Declare constructor

functionNewClass:initialize(a, b, c...)
---end

initialize - is key word

Declare method

functionNewClass:method1(a, b, c...)
---end

Call parent method

functionNewClassChild:method1(a, b, c...)
---NewClass.method1(self, a, b, c...)
---end

Checks if an instance of an object belongs to this class or to one of the parents of this class

ifobj.myInstance(NewClass) then---end

An example of using the module

localObject=require('lua-object')
localBaseTable=Object:extend()
functionBaseTable:myFunction1(arg1, arg2, arg3)
---- ...--endlocaltableA=BaseTable:new()
iftableA:isInstance(Object) thentableA:myFunction1(1, 2, 3)
end

About

Base class implementation for Lua

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages