lua的面向对象思路

function People(name)
    local self = {}

    local function init()
        self.name = name
    end

    self.sayHi = function ()
        print("hello "..self.name)
    end

    self.nimei = function ()
        print("nimei de")
    end

    init()
    return self
end

-- local p = People("zhangsan")
-- p:sayHi()
-- p:nimei()

-- 继承
function Man(name)
    local self = People(name)

    self.sayHello = function ()
        print("这种继承好low")
    end
    return self
end

local p = Man("lisi")
p:sayHello()
p:nimei()

 

posted @ 2022-07-13 23:58  JvvYou  阅读(25)  评论(0编辑  收藏  举报