lua single-method

local function newObject (value)
  return function (action, v)
    if action == "get" then return value
    elseif action == "set" then value = v
    else error("invalid action")
    end
  end
end

local d = newObject(1)
print(d("get"))
d("set",2)
print(d("get"))

1
2

猜你喜欢

转载自xiangjie88.iteye.com/blog/2401201
LUA