Added FS.MemoryFilesystem

This commit is contained in:
2025-01-03 05:54:27 -06:00
parent 82bf80ba06
commit f0a7c77134
16 changed files with 1105 additions and 991 deletions

View File

@@ -35,6 +35,10 @@ namespace Tesses::CrossLang
}
return nullptr;
}
static TObject FS_CreateMemoryFilesystem(GCList& ls, std::vector<TObject> args)
{
return TVFSHeapObject::Create(ls, new Tesses::Framework::Filesystem::MemoryFilesystem());
}
static TObject FS_CreateFilesystem(GCList& ls, std::vector<TObject> args)
{
@@ -71,6 +75,41 @@ namespace Tesses::CrossLang
}
return nullptr;
}
static TObject FS_CreateArchive(GCList& ls, std::vector<TObject> args)
{
TVFSHeapObject* vfs;
TStreamHeapObject* strm;
std::string name;
std::string version;
std::string info;
TVMVersion version2;
if(GetArgumentHeap(args,0,vfs) && GetArgumentHeap(args,1,strm) && GetArgument(args,2,name) && GetArgument(args,3,version) && GetArgument(args,4,info) && TVMVersion::TryParse(version,version2))
{
CrossArchiveCreate(vfs->vfs,strm->stream,name,version2,info);
}
return nullptr;
}
static TObject FS_ExtractArchive(GCList& ls, std::vector<TObject> args)
{
TVFSHeapObject* vfs;
TStreamHeapObject* strm;
if(GetArgumentHeap(args,0,strm) && GetArgumentHeap(args,1,vfs))
{
auto res = CrossArchiveExtract(strm->stream,vfs->vfs);
TDictionary* dict = TDictionary::Create(ls);
ls.GetGC()->BarrierBegin();
dict->SetValue("Name",res.first.first);
dict->SetValue("Version",res.first.second.ToString());
dict->SetValue("Info",res.second);
ls.GetGC()->BarrierEnd();
return dict;
}
return nullptr;
}
void TStd::RegisterIO(GC* gc,TRootEnvironment* env,bool enableLocalFilesystem)
{
@@ -93,6 +132,10 @@ namespace Tesses::CrossLang
dict->DeclareFunction(gc, "MemoryStream","Create a memory stream",{"writable"}, FS_MemoryStream);
dict->DeclareFunction(gc, "CreateStream","Create stream", {"strm"},FS_CreateStream);
dict->DeclareFunction(gc, "CreateFilesystem","Create filesystem", {"fs"},FS_CreateFilesystem);
dict->DeclareFunction(gc, "CreateMemoryFilesystem","Create in memory filesystem", {},FS_CreateMemoryFilesystem);
dict->DeclareFunction(gc, "CreateArchive", "Create a crvm archive",{"fs","strm","name","version","info"},FS_CreateArchive);
dict->DeclareFunction(gc,"ExtractArchive", "Extract a crvm archive",{"strm","vfs"},FS_ExtractArchive);
env->DeclareVariable("FS", dict);
gc->BarrierEnd();
}