建立对象报错
function newAnimal(name)
local animal={
name="unknown",
says="pffft",
position={x=0,y=0}
}
animal.name=name;
if name=="cat" then
animal.says="meow"
elseif name=="dog" then
animal.says="bow bow"
elseif name=="mouse" then
animal.says="squeak"
end
function animal:speak()
print(animal.says)
end
function animal:move(speed)
animal.position.x=animal.position.x+speed
end
return animal
end
cat_01=animal.new("cat")
cat_01:speak()