Skip to content

Create Lua_Object-Oriented_Programming_Framework.lua #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Lua_Object-Oriented_Programming_Framework.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- Import pl.class and pl.meta libraries
local class = require "pl.class"
local meta = require "pl.class".meta

-- Define a base class
BaseClass = class()

-- Define methods for the base class
function BaseClass:_init()
print("BaseClass constructor called")
end

function BaseClass:baseMethod()
print("BaseClass method called")
end

-- Define a derived class inheriting from the base class
DerivedClass = class(BaseClass)

-- Define methods for the derived class
function DerivedClass:_init()
print("DerivedClass constructor called")
end

function DerivedClass:derivedMethod()
print("DerivedClass method called")
end

-- Create instances of the classes and call their methods
local baseObj = BaseClass()
baseObj:baseMethod()

local derivedObj = DerivedClass()
derivedObj:baseMethod()
derivedObj:derivedMethod()