Forum

> > CS2D > Scripts > Get CS2D Path
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Get CS2D Path

4 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Get CS2D Path

Waldin
User Off Offline

Zitieren
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

alt Re: Get CS2D Path

xNir
User Off Offline

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

alt Re: Get CS2D Path

Waldin
User Off Offline

Zitieren
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.

alt Re: Get CS2D Path

xNir
User Off Offline

Zitieren
1
2
3
luapath = string.match(package.path, ";[^;]+;([^%?]+)")
luapath = string.gsub(luapath, "\\", "/") -- Remove this if not necessary
cs2dpath = string.gsub(luapath, "lua/", "")
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht