-- 创建一个协程
local co = coroutine.create(function()
for i = 1, 3 do
print("Coroutine", i)
coroutine.yield()
end
-- 恢复协程的执行
coroutine.resume(co)
-- 输出: Coroutine 1
-- 创建一个对象
local person = {
name = "John",
age = 25,
greet = function(self)
print("Hello, my name is " .. self.name .. " and I'm " .. self.age .. " years old.")
end
}
-- 调用对象的方法
person:greet() -- 输出: Hello, my name is John and I'm 25 years old.