ddxiami

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3157|回复: 1

Lua语法--17调试(Debug)

[复制链接]
发表于 2020-8-19 22:10:13 | 显示全部楼层 |阅读模式
===============================================
#!/usr/local/bin/lua

function myfunction ()
print(debug.traceback("Stack trace"))
print(debug.getinfo(1))
print("Stack trace end")
        return 10
end
myfunction ()
print(debug.getinfo(1))
===============================================
回复

使用道具 举报

 楼主| 发表于 2020-8-19 22:10:22 | 显示全部楼层
===============================================
#!/usr/local/bin/lua

function newCounter ()
  local n = 0
  local k = 0
  return function ()
    k = n
    n = n + 1
    return n
    end
end

counter = newCounter ()
print(counter())
print(counter())

local i = 1

repeat
  name, val = debug.getupvalue(counter, i)
  if name then
    print ("index", i, name, "=", val)
        if(name == "n") then
                debug.setupvalue (counter,2,10)
        end
    i = i + 1
  end -- if
until not name

print(counter())
===============================================
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|技术文档库 ( 闽ICP备15017263号-2 )|网站地图

GMT+8, 2025-5-18 17:45 , Processed in 0.035586 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表