1
0
mirror of https://github.com/AR2000AR/openComputers_codes.git synced 2025-09-04 12:45:58 +02:00

[libClass2] Readme

This commit is contained in:
2023-12-02 14:26:46 +01:00
committed by GitHub
parent 3a312f9971
commit aa8dc46afa
2 changed files with 34 additions and 1 deletions

View File

@@ -107,7 +107,7 @@ Let you mount a "decrypted" version of the disk for easy file manipulation.
---
## Additional library
### [libClass](libClass/)
### [libClass2](libClass2/)
add object oriented programming to lua.
### [libGUI](libGUI/)

33
libClass2/README.md Normal file
View File

@@ -0,0 +1,33 @@
# libClass2
```lua
local class = require("libClass2")
---@class A:Object
local A = class()
--constructor
function A:new()
--call the parent's constructor
local o = self.parent()
-- this line make `o` a objet of class `A`
o = setmetatable(o, {__index = self})
---@cast o A
o.member = 1
return o
end
function A:method()
self.member = self.member +1
return self.member
end
---@class B:A
local B = class(A)
local a = A()
print(a:method())
local b = B
print(b:method())
```