摘要: 对表进行更新时调用。 函数用法 print(" newindex ") mytab2 = {"a","b"} metatab2 = { __newindex=function(tab,key,value) print("被调用") rawset(tab,key,value) end } setmet 阅读全文
posted @ 2022-07-25 23:45 再努力一些 阅读(32) 评论(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 再努力一些 阅读(98) 评论(0) 推荐(0)
摘要: require("模块名") require "模块名" -- 调用模块 require("module") print(module.constant) module.func3() 阅读全文
posted @ 2022-07-25 20:30 再努力一些 阅读(31) 评论(0) 推荐(0)
摘要: 报错内容 .\module.lua:10: '(' expected near '.' stack traceback: [C]: ? [C]: in function 'require' .\testModule.lua:2: in main chunk [C]: ? error:在定义私有的函数 阅读全文
posted @ 2022-07-25 20:24 再努力一些 阅读(717) 评论(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 再努力一些 阅读(48) 评论(0) 推荐(0)