Add uuid support

This commit is contained in:
2026-02-16 17:42:01 -06:00
parent 46850e8edf
commit 5be9d96b54
21 changed files with 5774 additions and 4838 deletions

View File

@@ -1,4 +1,5 @@
#include "CrossLang.hpp"
#include "TessesFramework/Serialization/BitConverter.hpp"
#if defined(_WIN32)
#include <windows.h>
@@ -131,6 +132,10 @@ namespace Tesses::CrossLang
ls.GetGC()->BarrierEnd();
return list;
}
static TObject Env_getLittleEndian(GCList& ls, std::vector<TObject> args)
{
return Tesses::Framework::Serialization::BitConverter::IsLittleEndian();
}
void TStd::RegisterEnv(GC* gc, TRootEnvironment* env)
{
@@ -155,6 +160,7 @@ namespace Tesses::CrossLang
dict->DeclareFunction(gc,"getUser","Get user folder",{},Env_getUser);
dict->DeclareFunction(gc,"getPlatform","Get platform name",{},Env_getPlatform);
dict->DeclareFunction(gc,"GetRealExecutablePath", "Get the absolute path for executable", {"path"},Env_GetRealExecutablePath);
dict->DeclareFunction(gc, "getLittleEndian", "Is the platform little endian", {},Env_getLittleEndian);
gc->BarrierBegin();
dict->SetValue("EnvPathSeperator",EnvPathSeperator);
env->SetVariable("Env", dict);

View File

@@ -1,5 +1,11 @@
#include "CrossLang.hpp"
#include "TessesFramework/Streams/ByteReader.hpp"
#include "TessesFramework/Streams/Stream.hpp"
#include "TessesFramework/Uuid.hpp"
#include <memory>
#include <variant>
#include <vector>
#if defined(CROSSLANG_ENABLE_SHARED)
#if defined(CROSSLANG_ENABLE_FFI)
#include <ffi.h>
@@ -568,6 +574,23 @@ namespace Tesses::CrossLang
std::shared_ptr<Tesses::Framework::TextStreams::TextWriter> strm;
return GetArgument(args,0,strm);
}
static TObject TypeIsByteReader(GCList& ls, std::vector<TObject> args)
{
if(args.empty()) return nullptr;
std::shared_ptr<Tesses::Framework::Streams::ByteReader> strm;
return GetArgument(args,0,strm);
}
static TObject TypeIsByteWriter(GCList& ls, std::vector<TObject> args)
{
if(args.empty()) return nullptr;
std::shared_ptr<Tesses::Framework::Streams::ByteWriter> strm;
return GetArgument(args,0,strm);
}
static TObject TypeIsUuid(GCList& ls, std::vector<TObject> args)
{
if(args.empty()) return nullptr;
return std::holds_alternative<Tesses::Framework::Uuid>(args[0]);
}
static TObject TypeIsVFS(GCList& ls, std::vector<TObject> args)
{
if(args.empty()) return nullptr;
@@ -741,6 +764,11 @@ namespace Tesses::CrossLang
if(std::holds_alternative<TVMVersion>(_obj)) return "Version";
if(std::holds_alternative<std::shared_ptr<Tesses::Framework::Date::DateTime>>(_obj)) return "DateTime";
if(std::holds_alternative<std::shared_ptr<Tesses::Framework::Date::TimeSpan>>(_obj)) return "TimeSpan";
if(std::holds_alternative<std::shared_ptr<Tesses::Framework::Streams::ByteReader>>(_obj)) return "ByteReader";
if(std::holds_alternative<std::shared_ptr<Tesses::Framework::Streams::ByteWriter>>(_obj)) return "ByteWriter";
if(std::holds_alternative<Tesses::Framework::Uuid>(_obj)) return "Uuid";
if(std::holds_alternative<std::shared_ptr<Tesses::Framework::Streams::Stream>>(_obj))
{
auto strm = std::get<std::shared_ptr<Tesses::Framework::Streams::Stream>>(_obj);
@@ -1222,6 +1250,21 @@ namespace Tesses::CrossLang
}
return nullptr;
}
static TObject New_ByteReader(GCList& ls, std::vector<TObject> args)
{
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
if(GetArgument(args, 0, strm))
return std::make_shared<Tesses::Framework::Streams::ByteReader>(strm);
return nullptr;
}
static TObject New_ByteWriter(GCList& ls, std::vector<TObject> args)
{
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
if(GetArgument(args, 0, strm))
return std::make_shared<Tesses::Framework::Streams::ByteWriter>(strm);
return nullptr;
}
void TStd::RegisterRoot(GC* gc, TRootEnvironment* env)
{
GCList ls(gc);
@@ -1230,6 +1273,8 @@ namespace Tesses::CrossLang
env->permissions.canRegisterRoot=true;
RegisterHelpers(gc,env);
RegisterUuid(gc, env);
auto date =env->EnsureDictionary(gc,"DateTime");
date->DeclareFunction(gc, "Sleep","Sleep for a specified amount of milliseconds (multiply seconds by 1000 to get milliseconds)", {"ms"},DateTime_Sleep);
@@ -1269,6 +1314,10 @@ namespace Tesses::CrossLang
task->DeclareFunction(gc, "FromResult", "async from result", {"result"}, Task_FromResult);
TDictionary* newTypes = env->EnsureDictionary(gc, "New");
newTypes->DeclareFunction(gc, "ByteReader","Read binary data from stream",{"stream"},New_ByteReader);
newTypes->DeclareFunction(gc, "ByteWriter","Write binary data to stream",{"stream"},New_ByteWriter);
//newTypes->DeclareFunction(gc,)
newTypes->DeclareFunction(gc, "Promise", "Create an async object",{"resolve","reject"},New_Promise);
newTypes->DeclareFunction(gc, "DateTime","Create a DateTime object, if only one arg is provided year is epoch, isLocal defaults to true unless epoch",{"year","$month","$day","$hour","$minute","$second","$isLocal"},New_DateTime);
@@ -1339,6 +1388,9 @@ namespace Tesses::CrossLang
env->DeclareFunction(gc, "TypeIsTimeSpan","Get whether object is a TimeSpan",{"object"},TypeIsTimeSpan);
env->DeclareFunction(gc, "TypeIsTextReader","Get whether object is a TextReader",{"object"},TypeIsTextReader);
env->DeclareFunction(gc, "TypeIsTextWriter","Get whether object is a TextWriter",{"object"},TypeIsTextWriter);
env->DeclareFunction(gc, "TypeIsByteReader","Get whether object is a ByteReader",{"object"},TypeIsByteReader);
env->DeclareFunction(gc, "TypeIsByteWriter","Get whether object is a ByteWriter",{"object"},TypeIsByteWriter);
env->DeclareFunction(gc, "TypeIsUuid","Get whether object is a Uuid",{"object"},TypeIsUuid);
newTypes->DeclareFunction(gc, "Regex", "Create regex object",{"regex"},[](GCList& ls,std::vector<TObject> args)->TObject {

View File

@@ -0,0 +1,40 @@
#include "CrossLang.hpp"
#include "TessesFramework/Serialization/BitConverter.hpp"
#include "TessesFramework/Uuid.hpp"
namespace Tesses::CrossLang {
static TObject Uuid_NewUuid(GCList& ls, std::vector<TObject> args)
{
return Tesses::Framework::Uuid::Generate();
}
static TObject Uuid_TryParse(GCList& ls, std::vector<TObject> args)
{
std::string str;
Tesses::Framework::Uuid uuid;
if(GetArgument(args, 0, str) && Tesses::Framework::Uuid::TryParse(str,uuid))
return uuid;
return nullptr;
}
static TObject Uuid_FromBytes(GCList& ls, std::vector<TObject> args)
{
TByteArray* ba;
int64_t index;
if(GetArgumentHeap(args,0,ba) && GetArgument(args, 1, index) && (size_t)index < ba->data.size() && (size_t)index + 16 <= ba->data.size())
{
return Tesses::Framework::Serialization::BitConverter::ToUuid(ba->data[(size_t)index]);
}
return nullptr;
}
void TStd::RegisterUuid(GC* gc, TRootEnvironment* env)
{
gc->BarrierBegin();
TDictionary* guid = env->EnsureDictionary(gc, "Uuid");
guid->DeclareFunction(gc,"NewUuid","Create random uuid",{},Uuid_NewUuid);
guid->DeclareFunction(gc, "TryParse","Try to parse",{"str"}, Uuid_TryParse);
guid->DeclareFunction(gc, "FromBytes", "From bytes (big endian)",{"byteArray","offset"}, Uuid_FromBytes);
gc->BarrierEnd();
}
}