crosslang/src/types/native.cpp

58 lines
1.3 KiB
C++

#include "CrossLang.hpp"
namespace Tesses::CrossLang
{
TNative::TNative(void* ptr,std::function<void(void*)> destroy)
{
this->ptr = ptr;
this->destroyed=false;
this->destroy = destroy;
}
bool TNative::GetDestroyed()
{
return this->destroyed;
}
void* TNative::GetPointer()
{
return this->ptr;
}
void TNative::Mark()
{
if(this->marked) return;
this->marked=true;
GC::Mark(this->other);
}
void TNative::Destroy()
{
if(this->destroyed) return;
if(this->destroy != nullptr)
{
this->destroyed=true;
this->destroy(this->ptr);
}
}
TNative* TNative::Create(GCList& ls, void* ptr,std::function<void(void*)> destroy)
{
TNative* native = new TNative(ptr,destroy);
GC* gc = ls.GetGC();
ls.Add(native);
gc->Watch(native);
return native;
}
TNative* TNative::Create(GCList* ls, void* ptr,std::function<void(void*)> destroy)
{
TNative* native = new TNative(ptr,destroy);
GC* gc = ls->GetGC();
ls->Add(native);
gc->Watch(native);
return native;
}
TNative::~TNative()
{
this->Destroy();
}
}