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






新叶

 
 

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

随笔分类 -  Lua

 
弱引用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 新叶 阅读(40) 评论(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 新叶 阅读(66) 评论(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 新叶 阅读(92) 评论(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 新叶 阅读(271) 评论(0) 推荐(0)
Lua基础备忘
摘要:##数据类型lightuserdata 指针地址,由c管理生命周期。userdata 地址,交由lua的gc来控制。 ##闭包#表现1)函数内部可以访问函数外部的变量2)lua文件是一个匿名函数#实现c函数以及绑定在c函数上的upvalues#用lua_pushcclosure来创建c闭包#通过lu 阅读全文
posted @ 2021-11-28 21:58 新叶 阅读(84) 评论(0) 推荐(0)