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:
@@ -107,7 +107,7 @@ Let you mount a "decrypted" version of the disk for easy file manipulation.
|
|||||||
---
|
---
|
||||||
## Additional library
|
## Additional library
|
||||||
|
|
||||||
### [libClass](libClass/)
|
### [libClass2](libClass2/)
|
||||||
add object oriented programming to lua.
|
add object oriented programming to lua.
|
||||||
|
|
||||||
### [libGUI](libGUI/)
|
### [libGUI](libGUI/)
|
||||||
|
33
libClass2/README.md
Normal file
33
libClass2/README.md
Normal 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())
|
||||||
|
```
|
Reference in New Issue
Block a user