阅读背景:

Lua获取当前文件名与行号

来源:互联网 

test.lua文件内容

function getFileName(File)  
    local ret = string.find(string.reverse(File), "/")
	if ret == nil then
		return File
	end
	
    local Len = string.len(File) - ret + 1     
    return string.sub(File, Len + 1, string.len(File)) 
end 


FileName = string.format("%s:%d", getFileName(debug.getinfo(1).short_src), debug.getinfo(1).currentline)
print (FileName)

--原文件路径与行号信息
print ("Name: "..debug.getinfo(1).short_src)
print ("Line: "..debug.getinfo(1).currentline)
function getFileName(File)  
   



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: