Allow the user to get and set current path

This commit is contained in:
2025-04-29 06:28:31 -05:00
parent e853153008
commit e2392bd597
3 changed files with 43 additions and 0 deletions

View File

@ -144,6 +144,18 @@ namespace Tesses::CrossLang
return nullptr;
}
static TObject FS_getCurrentPath(GCList& ls, std::vector<TObject> args)
{
return Tesses::Framework::Filesystem::VFSPath::GetAbsoluteCurrentDirectory();
}
static TObject FS_setCurrentPath(GCList& ls, std::vector<TObject> args)
{
Tesses::Framework::Filesystem::VFSPath path;
if(GetArgumentAsPath(args,0,path))
Tesses::Framework::Filesystem::VFSPath::SetAbsoluteCurrentDirectory(path);
return nullptr;
}
void TStd::RegisterIO(GC* gc,TRootEnvironment* env,bool enableLocalFilesystem)
{
@ -159,6 +171,8 @@ namespace Tesses::CrossLang
dict->SetValue("Local", vfs);
dict->DeclareFunction(gc, "MakeFull", "Make absolute path from relative path",{"path"},FS_MakeFull);
dict->DeclareFunction(gc,"getCurrentPath","Get current path",{},FS_getCurrentPath);
dict->DeclareFunction(gc,"setCurrentPath","Set the current path",{"path"},FS_setCurrentPath);
}
dict->DeclareFunction(gc, "ReadAllText","Read all text from file", {"fs","filename"},FS_ReadAllText);

View File

@ -74,6 +74,7 @@ namespace Tesses::CrossLang
gc->BarrierBegin();
dict->DeclareFunction(gc,"FromString","Create a Path from string",{"path"},Path_FromString);
dict->DeclareFunction(gc,"Create","Create a Path from parts",{"relative","parts"},Path_Create);
dict->DeclareFunction(gc,"Root","Create Absolute Root Path",{}, Path_Root);
env->DeclareVariable("Path", dict);

View File

@ -1922,6 +1922,34 @@ namespace Tesses::CrossLang {
cse.back()->Push(gc, path.GetExtension());
return false;
}
if(cse.back()->env->GetRootEnvironment()->permissions.canRegisterLocalFS && key == "MakeAbsolute")
{
Tesses::Framework::Filesystem::VFSPath p;
if(GetArgumentAsPath(args,0,p))
{
cse.back()->Push(gc,path.MakeAbsolute(p));
return false;
}
else
{
cse.back()->Push(gc,path.MakeAbsolute());
return false;
}
}
if(cse.back()->env->GetRootEnvironment()->permissions.canRegisterLocalFS && key == "MakeRelative")
{
Tesses::Framework::Filesystem::VFSPath p;
if(GetArgumentAsPath(args,0,p))
{
cse.back()->Push(gc,path.MakeRelative(p));
return false;
}
else
{
cse.back()->Push(gc,path.MakeRelative());
return false;
}
}
if(key == "ChangeExtension")
{
Tesses::Framework::Filesystem::VFSPath newPath = path;