Forum

> > CS2D > Scripts > Get CS2D Path
Forums overviewCS2D overview Scripts overviewLog in to reply

English Get CS2D Path

4 replies
To the start Previous 1 Next To the start

old Get CS2D Path

Waldin
User Off Offline

Quote
Hello, i need the cs2d path, for function io.enumdir
is this code working? it is for me, but just want know if working others.
Also, is other way to get this?
1
2
3
4
5
6
7
for path in string.gmatch(package.path, "[^;]+") do
	local to = string.find(path, "[\\|/]lua[\\|/]%?%.lua$")
	if to then 
		cs2dpath = string.sub(path, 1, to - 1)
		break
	end
end

old Re: Get CS2D Path

xNir
User Off Offline

Quote
1
scriptpath = string.match(string.sub(debug.getinfo(1).source, 2), "(.+/)")

old Re: Get CS2D Path

Waldin
User Off Offline

Quote
ah no, it searchs (cs2d folder)/lua/?.lua in package.path
just save the start of /lua/?.lua, and save from start to it.

@user xNir: i need cs2d folder, not the current script path.

old Re: Get CS2D Path

xNir
User Off Offline

Quote
1
2
3
luapath = string.match(package.path, ";[^;]+;([^%?]+)")
luapath = string.gsub(luapath, "\\", "/") -- Remove this if not necessary
cs2dpath = string.gsub(luapath, "lua/", "")
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview