在LUA中获取各种路径.

Posted bywayboy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在LUA中获取各种路径.相关的知识,希望对你有一定的参考价值。

1、获取当前路径。

可以使用C语言大法。也可以使用 os库调用 cd命令。

static int fmt_fs_cwd(lua_State * L)

	char path[1024];
	if(NULL == getcwd(path, 1023))
		lua_pushinteger(L, errno);
	else
		lua_pushstring(L, path);
	return 1;


获取当前执行脚本的文件名以及所在路径,这个需要借助 debug库了。

function dirname(str)
	if str:match(".-/.-") then
		local name = string.gsub(str, "(.*/)(.+)", "%1")
		return name
	elseif str:match(".-\\\\.-") then
		local name = string.gsub(str, "(.*\\\\)(.+)", "%1")
		return name
	else
		return ''
	end
end

--- 当前文件名
local __FILE__ = debug.getinfo(1,'S').source:sub(2)



以上是关于在LUA中获取各种路径.的主要内容,如果未能解决你的问题,请参考以下文章