First commit
This commit is contained in:
58
src/types/native.cpp
Normal file
58
src/types/native.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user