新手提问
lua吧
全部回复
仅看楼主
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
level 8
不知道啊,我只知道元表需要定义__index字段,看你的程序连__index都没出现,多看书吧.
2015年02月05日 04点02分 2
1