Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yagocrispim/lua_class
Classes in Lua
https://github.com/yagocrispim/lua_class
class lua object-oriented-programming oop
Last synced: about 2 months ago
JSON representation
Classes in Lua
- Host: GitHub
- URL: https://github.com/yagocrispim/lua_class
- Owner: YagoCrispim
- License: mit
- Created: 2023-09-21T11:42:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-09T16:46:38.000Z (2 months ago)
- Last Synced: 2024-11-09T17:35:29.427Z (2 months ago)
- Topics: class, lua, object-oriented-programming, oop
- Language: Lua
- Homepage:
- Size: 31.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lua-class
## Example
```lua
local class = require "src.class"local LogAllTrait = {
log_all = function(self)
print("Name: " .. self.name)
print("Age: " .. self.age)
print("SecretName: " .. self.secret_name)
print("AgentId: " .. self.agent_id)
end
}local SecretAgent = class {
__use = { LogAllTrait },constructor = function(self, params)
self.secret_name = 'Confidential'
self.agent_id = params.agent_id
end,super_method = function()
print("[SecretAgent]: Super method")
end
}local Person = class {
__extends = SecretAgent,
constructor = function(self, params)
self:super(params)
self.name = params.name
self.age = params.age
end,class_method = function()
print("[Person]: Class method")
end
}local john = Person:new({ name = "John Doe", age = 21, agent_id = 123 })
local jane = Person:new({ name = "Jane Doe", age = 20, agent_id = 456 })--
john:log_all()
john:class_method()
john:super_method()print('---')
jane:log_all()
jane:class_method()
jane:super_method()```