--table_1 为 对象
table_1={ name ="默默",age=18}
--table_1 中的元素
table_1.likeEatobj=function(str)
if type(str)==string then
print (table_1.name.."喜欢吃"..str )
end
end
--构造函数
function table_1:new(o )
local t=o or {}--类似于c#中的三元运算符
setmetatable(t,{__index=self})--设置元表 如果看不懂就去菜鸟教程看元表的知识
return t;
end
--继承
table_2=table_1.new ({xb="男"})
--调用
print(table_2.xb)
Lua中的继承
最新推荐文章于 2024-07-26 01:03:45 发布