LUA OOP

作者: 庄什么庄 | 来源:发表于2017-04-24 02:20 被阅读0次

    -- Class of ParentClass

    Animals = {x = 0, y = 0};

    Animals.__index = Animals;

    -- Constructor

    function Animals:New(x, y)

    local self = {};

    setmetatable(self, Animals);

    self.x = x;

    self.y = y;

    return self;

    end

    function  Animals:Fly()

    -- body

    print("animal fly");

    end

    -- print(Animals:New(1, 5).x);

    Duck = {z = 0};

    setmetatable(Duck, Animals);

    Duck.__index = Duck;

    function Duck:New(x, y, z)

    -- body

    local self = {};

    self = Animals:New(x, y);

    setmetatable(self, Duck);

    self.z = z;

    return self;

    end

    -- function Duck:Fly()

    -- -- body

    -- print("duck fly");

    -- end

    function Cry( )

    -- body

    print("duck cry");

    end

    animal = Animals:New(1, 5);

    duck = Duck:New(3, 88);

    print(animal:Fly());

    print(duck.Fly());

    相关文章

      网友评论

        本文标题:LUA OOP

        本文链接:https://www.haomeiwen.com/subject/wtsuzttx.html