• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






新叶

 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理

2022年7月9日

弱引用key
摘要: local t = {} setmetatable(t, {__mode="k"}) -- t的key是弱引用,一旦其他地方没有了对key的引用,那么t里的这个字段也会被删除 local key1 = {name="key1"} t[key1] = 1 key1 = nil collectgarba 阅读全文
posted @ 2022-07-09 17:37 新叶 阅读(39) 评论(0) 推荐(0)
 
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 * 阅读全文
posted @ 2022-07-09 17:34 新叶 阅读(64) 评论(0) 推荐(0)
 
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 阅读全文
posted @ 2022-07-09 17:28 新叶 阅读(89) 评论(0) 推荐(0)
 
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 阅读全文
posted @ 2022-07-09 17:24 新叶 阅读(265) 评论(0) 推荐(0)