level 1
沸腾的群山
楼主
问题1:怎么在表中定义函数?
TT={ str="this is a test" }
可以这样吗?
TT={
str="this is a test",
function func()
...
end
}
我定义了
function TT.func()
print(str)
end
执行TT.func()出现nil。 改成print(TT.str)才出结果。lua记不住自己表中定义的域吗?
问题2:
TT={ str="this is a test" }
function TT.func()
print(TT.str)
end
GG={}
setmetatable(GG,TT)
TT.func()
GG.func()
但是GG.func()出错了,GG的metatable不已经是TT了吗?
各位大婶帮帮新手。
2015年02月04日 05点02分
1
TT={ str="this is a test" }
可以这样吗?
TT={
str="this is a test",
function func()
...
end
}
我定义了
function TT.func()
print(str)
end
执行TT.func()出现nil。 改成print(TT.str)才出结果。lua记不住自己表中定义的域吗?
问题2:
TT={ str="this is a test" }
function TT.func()
print(TT.str)
end
GG={}
setmetatable(GG,TT)
TT.func()
GG.func()
但是GG.func()出错了,GG的metatable不已经是TT了吗?
各位大婶帮帮新手。