弱引用key
摘要:local t = {} setmetatable(t, {__mode="k"}) -- t的key是弱引用,一旦其他地方没有了对key的引用,那么t里的这个字段也会被删除 local key1 = {name="key1"} t[key1] = 1 key1 = nil collectgarba
阅读全文
coroutine
摘要:local function foo(a) print("foo: ", a) return coroutine.yield(2 * a) end local co = coroutine.create(foo) print(coroutine.resume(co, 1)) -- true, 2 *
阅读全文
table.extract
摘要:展开表: local extract extract = function (t, key, ...) -- print("extract key: ", key, type(t), t) if not key then return t end if not t then return nil e
阅读全文
xpcall 用法
摘要:local function f(x, y) print("f args: ", x, y) error("f error") -- raise error end -- 1 local function error_handler(err) print(err) return debug.trac
阅读全文