随笔分类 -  Lua

摘要:面向对象 对象:属性、方法。 table,function。 student = {name = "张三",age = 18, gotoSchool = function(name) print(name.."上学") end} --[[ student.gotoSchool = function( 阅读全文
posted @ 2022-07-26 20:39 再努力一些 阅读(33) 评论(0) 推荐(0)
摘要:对表进行更新时调用。 函数用法 print(" newindex ") mytab2 = {"a","b"} metatab2 = { __newindex=function(tab,key,value) print("被调用") rawset(tab,key,value) end } setmet 阅读全文
posted @ 2022-07-25 23:45 再努力一些 阅读(37) 评论(0) 推荐(0)
摘要:__index(两个下划线) 定义普通表 给普通表p,设置元表y,而元表y中有index,__index有一个表i,i中有我们访问的不存在的key. __index=表 print(" 测试__index ") -- 普通表 tab1 = {"a","b","c"} print(tab1[5]) - 阅读全文
posted @ 2022-07-25 22:49 再努力一些 阅读(55) 评论(0) 推荐(0)
摘要:允许我们改变table的行为 setmetatable(普通表,元表) 返回普通表 getmetatable() 获取元表 -- a = {"a","b","c"} -- b = {} -- c = setmetatable(a,b) print(" ") f = {} print("f:",f) 阅读全文
posted @ 2022-07-25 22:30 再努力一些 阅读(106) 评论(0) 推荐(0)
摘要:require("模块名") require "模块名" -- 调用模块 require("module") print(module.constant) module.func3() 阅读全文
posted @ 2022-07-25 20:30 再努力一些 阅读(37) 评论(0) 推荐(0)
摘要:-- 模块:module.lua module = {} module.constant="模块中的变量" function module.func1() print("这是函数1") end local function func2() print("这是私有函数2") end function 阅读全文
posted @ 2022-07-25 20:09 再努力一些 阅读(52) 评论(0) 推荐(0)