Lua表实现类

Lua 复制代码
--类
Student = { 
	name = "Holens",
	age = 1,
	sex = true,

	Say1 = function()
		print(Student.name.."说话了")
	end,

	Say2 = function(t)
		print(t.name.."说话了2")
	end
}
Student.Say1()
print("*************************************")

--声明后添加
Student.child = "blueman"
print(Student.child)

--lua中.和:区别
--:会默认把调用者 作为第一个参数传入方法
Student:Say2()
print("*************************************")
相关推荐
AAA@峥3 分钟前
Python 基础开篇:认识 Python、版本选择、环境部署与首个 HelloWorld
开发语言·python
caimouse1 小时前
ReactOS 图形系统分析(47):GDI 批处理 — gdibatch.c
c语言·开发语言
qq21084629531 小时前
在python中什么是 self 和 cls?
开发语言·前端·python
杨充1 小时前
05.多用组合和少继承
开发语言·bash
傻啦嘿哟2 小时前
王者荣耀爬虫:爬取全英雄皮肤数据,用Python做可视化分析
开发语言·爬虫·python
AI直播技术杂谈2 小时前
直播画面突然模糊了,排查了三个小时
开发语言·php
菜冻鱼2 小时前
Python-pytorch-数据加载
开发语言·人工智能·pytorch·python·深度学习·机器学习
heimeiyingwang2 小时前
【架构实战】可观测性三支柱实战:Metrics、Logging、Tracing 如何统一落地
开发语言·架构·php
caimouse2 小时前
ReactOS 图形系统分析(53):系统库存对象 — stockobj.c
c语言·开发语言·spring