init
This commit is contained in:
commit
c0c37059d6
12
main.lua
Normal file
12
main.lua
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
utils = require("oop/utils")
|
||||||
|
|
||||||
|
class = {
|
||||||
|
name = "MyClass",
|
||||||
|
sayHello = function(self)
|
||||||
|
print("Hello from " .. self.name)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
obj = utils.deepcopy(class)
|
||||||
|
obj.name = "Carl"
|
||||||
|
obj.sayHello(obj) -- Output: Hello from Carl
|
||||||
9
oop/oop.lua
Normal file
9
oop/oop.lua
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
--[[
|
||||||
|
the plan is to create a simple oop system in lua
|
||||||
|
|
||||||
|
it might not work liky python
|
||||||
|
|
||||||
|
think of it more like a facory system
|
||||||
|
with at least the concept of self
|
||||||
|
]]
|
||||||
|
|
||||||
15
oop/utils.lua
Normal file
15
oop/utils.lua
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
local function deepcopy(t)
|
||||||
|
local new = {}
|
||||||
|
for k, v in pairs(t) do
|
||||||
|
if type(v) == "table" then
|
||||||
|
new[k] = deepcopy(v)
|
||||||
|
else
|
||||||
|
new[k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return new
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
deepcopy = deepcopy
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user