mirror of
https://git.tesses.org/tesses50/crosslang.git
synced 2026-09-30 08:44:14 +00:00
Fix bug with classes, use slim exclusively, add package private data and change rehaul cmake configs
This commit is contained in:
+193
-200
@@ -1,224 +1,217 @@
|
||||
#include "CrossLang.hpp"
|
||||
|
||||
namespace Tesses::CrossLang
|
||||
{
|
||||
int64_t TObjectStream::_GetPosInternal()
|
||||
{
|
||||
return Tesses::Framework::Streams::Stream::GetLength();
|
||||
}
|
||||
TObjectStream::TObjectStream(std::shared_ptr<GC> gc, TObject obj)
|
||||
{
|
||||
this->ls = new GCList(gc);
|
||||
this->ls->Add(obj);
|
||||
this->obj = obj;
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(obj,dict))
|
||||
{
|
||||
gc->BarrierBegin();
|
||||
if(!dict->HasValue("Read"))
|
||||
{
|
||||
dict->DeclareFunction(gc,"Read","Read from stream",{"buff","off","len"}, [](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
namespace Tesses::CrossLang {
|
||||
int64_t TObjectStream::_GetPosInternal() {
|
||||
return Tesses::Framework::Streams::Stream::GetLength();
|
||||
}
|
||||
TObjectStream::TObjectStream(std::shared_ptr<GC> gc, TObject obj) {
|
||||
this->ls = new GCList(gc);
|
||||
this->ls->Add(obj);
|
||||
this->obj = obj;
|
||||
TDictionary *dict;
|
||||
if (GetObjectHeap(obj, dict)) {
|
||||
gc->BarrierBegin();
|
||||
if (!dict->HasValue("Read")) {
|
||||
dict->DeclareFunction(
|
||||
gc, "Read", "Read from stream", {"buff", "off", "len"},
|
||||
[](GCList &ls, std::vector<TObject> args) -> TObject {
|
||||
return (int64_t)0;
|
||||
});
|
||||
}
|
||||
if(!dict->HasValue("Write"))
|
||||
{
|
||||
dict->DeclareFunction(gc,"Write","Write to stream",{"buff","off","len"}, [](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
}
|
||||
if (!dict->HasValue("Write")) {
|
||||
dict->DeclareFunction(
|
||||
gc, "Write", "Write to stream", {"buff", "off", "len"},
|
||||
[](GCList &ls, std::vector<TObject> args) -> TObject {
|
||||
return (int64_t)0;
|
||||
});
|
||||
}
|
||||
if(!dict->HasValue("getCanRead"))
|
||||
{
|
||||
dict->DeclareFunction(gc,"getCanRead","Can read from stream",{}, [](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
}
|
||||
if (!dict->HasValue("getCanRead")) {
|
||||
dict->DeclareFunction(
|
||||
gc, "getCanRead", "Can read from stream", {},
|
||||
[](GCList &ls, std::vector<TObject> args) -> TObject {
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if(!dict->HasValue("getCanWrite"))
|
||||
{
|
||||
dict->DeclareFunction(gc,"getCanWrite","Can write to stream",{}, [](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
if (!dict->HasValue("getCanWrite")) {
|
||||
dict->DeclareFunction(
|
||||
gc, "getCanWrite", "Can write to stream", {},
|
||||
[](GCList &ls, std::vector<TObject> args) -> TObject {
|
||||
return false;
|
||||
});
|
||||
}
|
||||
if(!dict->HasValue("getCanSeek"))
|
||||
{
|
||||
dict->DeclareFunction(gc,"getCanSeek","Can seek in stream",{}, [](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
}
|
||||
if (!dict->HasValue("getCanSeek")) {
|
||||
dict->DeclareFunction(
|
||||
gc, "getCanSeek", "Can seek in stream", {},
|
||||
[](GCList &ls, std::vector<TObject> args) -> TObject {
|
||||
return false;
|
||||
});
|
||||
}
|
||||
if(!dict->HasValue("getPosition"))
|
||||
{
|
||||
dict->DeclareFunction(gc,"getPosition","Can get position in stream",{}, [](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
}
|
||||
if (!dict->HasValue("getPosition")) {
|
||||
dict->DeclareFunction(
|
||||
gc, "getPosition", "Can get position in stream", {},
|
||||
[](GCList &ls, std::vector<TObject> args) -> TObject {
|
||||
return (int64_t)0;
|
||||
});
|
||||
}
|
||||
if(!dict->HasValue("getLength"))
|
||||
{
|
||||
dict->DeclareFunction(gc,"getPosition","Can get position in stream",{}, [this](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
}
|
||||
if (!dict->HasValue("getLength")) {
|
||||
dict->DeclareFunction(
|
||||
gc, "getPosition", "Can get position in stream", {},
|
||||
[this](GCList &ls, std::vector<TObject> args) -> TObject {
|
||||
return _GetPosInternal();
|
||||
});
|
||||
}
|
||||
if(!dict->HasValue("getEndOfStream"))
|
||||
{
|
||||
dict->DeclareFunction(gc,"getEndOfStream","Is at end of stream",{}, [](GCList& ls, std::vector<TObject> args)->TObject {
|
||||
}
|
||||
if (!dict->HasValue("getEndOfStream")) {
|
||||
dict->DeclareFunction(
|
||||
gc, "getEndOfStream", "Is at end of stream", {},
|
||||
[](GCList &ls, std::vector<TObject> args) -> TObject {
|
||||
return false;
|
||||
});
|
||||
}
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
bool TObjectStream::EndOfStream()
|
||||
{
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
auto res = dict->CallMethod(*ls, "getEndOfStream",{});
|
||||
bool r;
|
||||
if(GetObject(res,r)) return r;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
size_t TObjectStream::Read(uint8_t* buff, size_t sz)
|
||||
{
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
GCList ls2(this->ls->GetGC());
|
||||
|
||||
TByteArray* arr=TByteArray::Create(ls2);
|
||||
arr->data.resize(sz);
|
||||
|
||||
auto res = dict->CallMethod(ls2, "Read",{arr, (int64_t)0L, (int64_t)sz});
|
||||
|
||||
memcpy(buff,arr->data.data(),std::min(sz,arr->data.size()));
|
||||
|
||||
int64_t r;
|
||||
if(GetObject(res,r)) return r;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
size_t TObjectStream::Write(const uint8_t* buff, size_t sz)
|
||||
{
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
GCList ls2(this->ls->GetGC());
|
||||
|
||||
TByteArray* arr=TByteArray::Create(ls2);
|
||||
arr->data.resize(sz);
|
||||
memcpy(arr->data.data(), buff, sz);
|
||||
|
||||
auto res = dict->CallMethod(ls2, "Write",{arr, (int64_t)0L, (int64_t)sz});
|
||||
int64_t r;
|
||||
if(GetObject(res,r)) return r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
bool TObjectStream::CanRead()
|
||||
{
|
||||
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
auto res = dict->CallMethod(*ls, "getCanRead",{});
|
||||
bool r;
|
||||
if(GetObject(res,r)) return r;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool TObjectStream::CanWrite()
|
||||
{
|
||||
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
auto res = dict->CallMethod(*ls, "getCanWrite",{});
|
||||
bool r;
|
||||
if(GetObject(res,r)) return r;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool TObjectStream::CanSeek()
|
||||
{
|
||||
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
auto res = dict->CallMethod(*ls, "getCanSeek",{});
|
||||
bool r;
|
||||
if(GetObject(res,r)) return r;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
int64_t TObjectStream::GetPosition()
|
||||
{
|
||||
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
auto res = dict->CallMethod(*ls, "getPosition",{});
|
||||
int64_t r;
|
||||
if(GetObject(res,r)) return r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
int64_t TObjectStream::GetLength()
|
||||
{
|
||||
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
auto res = dict->CallMethod(*ls, "getEndOfStream",{});
|
||||
bool r;
|
||||
if(GetObject(res,r)) return r;
|
||||
}
|
||||
|
||||
return Tesses::Framework::Streams::Stream::GetLength();
|
||||
}
|
||||
void TObjectStream::Flush()
|
||||
{
|
||||
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
dict->CallMethod(*ls, "Flush",{});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
void TObjectStream::Seek(int64_t pos, Tesses::Framework::Streams::SeekOrigin whence)
|
||||
{
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
dict->CallMethod(*ls, "Seek",{pos,(int64_t)(whence == Tesses::Framework::Streams::SeekOrigin::Begin ? 0 : whence == Tesses::Framework::Streams::SeekOrigin::Current ? 1 : 2) });
|
||||
}
|
||||
|
||||
}
|
||||
void TObjectStream::Close()
|
||||
{
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
dict->CallMethod(*ls,"Dispose",{});
|
||||
}
|
||||
}
|
||||
TObjectStream::~TObjectStream()
|
||||
{
|
||||
TDictionary* dict;
|
||||
if(GetObjectHeap(this->obj, dict))
|
||||
{
|
||||
dict->CallMethod(*ls,"Dispose",{});
|
||||
}
|
||||
delete this->ls;
|
||||
}
|
||||
bool TObjectStream::EndOfStream() {
|
||||
TDictionary *dict;
|
||||
if (GetObjectHeap(this->obj, dict)) {
|
||||
auto res = dict->CallMethod(*ls, "getEndOfStream", {});
|
||||
bool r;
|
||||
if (GetObject(res, r))
|
||||
return r;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
size_t TObjectStream::Read(uint8_t *buff, size_t sz) {
|
||||
TDictionary *dict;
|
||||
if (GetObjectHeap(this->obj, dict)) {
|
||||
GCList ls2(this->ls->GetGC());
|
||||
|
||||
|
||||
|
||||
}
|
||||
TByteArray *arr = TByteArray::Create(ls2);
|
||||
arr->data.resize(sz);
|
||||
|
||||
auto res =
|
||||
dict->CallMethod(ls2, "Read", {arr, (int64_t)0L, (int64_t)sz});
|
||||
|
||||
memcpy(buff, arr->data.data(), std::min(sz, arr->data.size()));
|
||||
|
||||
int64_t r;
|
||||
if (GetObject(res, r))
|
||||
return r;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
size_t TObjectStream::Write(const uint8_t *buff, size_t sz) {
|
||||
TDictionary *dict;
|
||||
if (GetObjectHeap(this->obj, dict)) {
|
||||
GCList ls2(this->ls->GetGC());
|
||||
|
||||
TByteArray *arr = TByteArray::Create(ls2);
|
||||
arr->data.resize(sz);
|
||||
memcpy(arr->data.data(), buff, sz);
|
||||
|
||||
auto res =
|
||||
dict->CallMethod(ls2, "Write", {arr, (int64_t)0L, (int64_t)sz});
|
||||
int64_t r;
|
||||
if (GetObject(res, r))
|
||||
return r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
bool TObjectStream::CanRead() {
|
||||
|
||||
TDictionary *dict;
|
||||
if (GetObjectHeap(this->obj, dict)) {
|
||||
auto res = dict->CallMethod(*ls, "getCanRead", {});
|
||||
bool r;
|
||||
if (GetObject(res, r))
|
||||
return r;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool TObjectStream::CanWrite() {
|
||||
|
||||
TDictionary *dict;
|
||||
if (GetObjectHeap(this->obj, dict)) {
|
||||
auto res = dict->CallMethod(*ls, "getCanWrite", {});
|
||||
bool r;
|
||||
if (GetObject(res, r))
|
||||
return r;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool TObjectStream::CanSeek() {
|
||||
|
||||
TDictionary *dict;
|
||||
if (GetObjectHeap(this->obj, dict)) {
|
||||
auto res = dict->CallMethod(*ls, "getCanSeek", {});
|
||||
bool r;
|
||||
if (GetObject(res, r))
|
||||
return r;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
int64_t TObjectStream::GetPosition() {
|
||||
|
||||
TDictionary *dict;
|
||||
if (GetObjectHeap(this->obj, dict)) {
|
||||
auto res = dict->CallMethod(*ls, "getPosition", {});
|
||||
int64_t r;
|
||||
if (GetObject(res, r))
|
||||
return r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
int64_t TObjectStream::GetLength() {
|
||||
|
||||
TDictionary *dict;
|
||||
if (GetObjectHeap(this->obj, dict)) {
|
||||
auto res = dict->CallMethod(*ls, "getEndOfStream", {});
|
||||
bool r;
|
||||
if (GetObject(res, r))
|
||||
return r;
|
||||
}
|
||||
|
||||
return Tesses::Framework::Streams::Stream::GetLength();
|
||||
}
|
||||
void TObjectStream::Flush() {
|
||||
|
||||
TDictionary *dict;
|
||||
if (GetObjectHeap(this->obj, dict)) {
|
||||
dict->CallMethod(*ls, "Flush", {});
|
||||
}
|
||||
}
|
||||
void TObjectStream::Seek(int64_t pos,
|
||||
Tesses::Framework::Streams::SeekOrigin whence) {
|
||||
TDictionary *dict;
|
||||
if (GetObjectHeap(this->obj, dict)) {
|
||||
dict->CallMethod(
|
||||
*ls, "Seek",
|
||||
{pos,
|
||||
(int64_t)(whence == Tesses::Framework::Streams::SeekOrigin::Begin
|
||||
? 0
|
||||
: whence ==
|
||||
Tesses::Framework::Streams::SeekOrigin::Current
|
||||
? 1
|
||||
: 2)});
|
||||
}
|
||||
}
|
||||
void TObjectStream::Close() {
|
||||
TDictionary *dict;
|
||||
if (GetObjectHeap(this->obj, dict)) {
|
||||
dict->CallMethod(*ls, "Dispose", {});
|
||||
}
|
||||
}
|
||||
TObjectStream::~TObjectStream() {
|
||||
TDictionary *dict;
|
||||
if (GetObjectHeap(this->obj, dict)) {
|
||||
dict->CallMethod(*ls, "Dispose", {});
|
||||
}
|
||||
delete this->ls;
|
||||
}
|
||||
|
||||
} // namespace Tesses::CrossLang
|
||||
Reference in New Issue
Block a user