2024-08-25 11:44:06 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2026-07-08 19:58:41 +02:00
|
|
|
#include <memory>
|
2024-08-25 11:44:06 +02:00
|
|
|
#include <set>
|
|
|
|
|
|
2026-07-25 23:01:18 +02:00
|
|
|
#include "clib/refptr.h"
|
|
|
|
|
#include "bscript/bobject.h"
|
|
|
|
|
#include "bscript/bstruct.h"
|
|
|
|
|
#include "bscript/eprog.h"
|
2024-08-25 11:44:06 +02:00
|
|
|
|
|
|
|
|
namespace Pol::Bscript
|
|
|
|
|
{
|
|
|
|
|
class BFunctionRef;
|
|
|
|
|
|
|
|
|
|
class BClassInstance final : public BStruct
|
|
|
|
|
{
|
2026-01-16 18:45:47 +01:00
|
|
|
using base = BStruct;
|
2024-08-25 11:44:06 +02:00
|
|
|
|
|
|
|
|
public:
|
2026-05-31 11:45:35 +02:00
|
|
|
BClassInstance( ref_ptr<EScriptProgram> program, int index, std::weak_ptr<ValueStackCont> globals,
|
|
|
|
|
unsigned int pid );
|
2024-08-25 11:44:06 +02:00
|
|
|
BClassInstance( const BClassInstance& B );
|
2026-01-14 21:35:59 +01:00
|
|
|
~BClassInstance() override = default;
|
2024-08-25 11:44:06 +02:00
|
|
|
|
|
|
|
|
public:
|
2026-01-14 21:35:59 +01:00
|
|
|
size_t sizeEstimate() const override;
|
2024-08-25 11:44:06 +02:00
|
|
|
ref_ptr<EScriptProgram> prog() const;
|
|
|
|
|
unsigned index() const;
|
|
|
|
|
// returns nullptr if no function found
|
|
|
|
|
BFunctionRef* makeMethod( const char* method_name );
|
|
|
|
|
|
2024-09-01 10:00:37 +02:00
|
|
|
// Inherited from BStruct
|
2026-01-14 21:35:59 +01:00
|
|
|
const char* typetag() const override;
|
2024-08-25 11:44:06 +02:00
|
|
|
|
|
|
|
|
std::set<unsigned> constructors_called;
|
|
|
|
|
|
|
|
|
|
public: // Class Machinery
|
2026-01-14 21:35:59 +01:00
|
|
|
const char* typeOf() const override;
|
|
|
|
|
u8 typeOfInt() const override;
|
|
|
|
|
BObjectImp* copy() const override;
|
|
|
|
|
bool isTrue() const override;
|
|
|
|
|
BObjectImp* call_method( const char* methodname, Executor& ex ) override;
|
|
|
|
|
BObjectImp* call_method_id( const int id, Executor& ex, bool forcebuiltin = false ) override;
|
|
|
|
|
BObjectRef get_member_id( const int id ) override;
|
2026-04-06 16:21:50 +02:00
|
|
|
// void packonto( std::string& os ) const override; // no serialization
|
2026-01-14 21:35:59 +01:00
|
|
|
|
|
|
|
|
std::string getStringRep() const override;
|
2024-08-25 11:44:06 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ref_ptr<EScriptProgram> prog_;
|
|
|
|
|
unsigned int index_;
|
2026-05-31 11:45:35 +02:00
|
|
|
unsigned int pid_;
|
2024-08-25 11:44:06 +02:00
|
|
|
|
|
|
|
|
public:
|
2026-05-27 08:02:19 +02:00
|
|
|
std::weak_ptr<ValueStackCont> globals;
|
2024-08-25 11:44:06 +02:00
|
|
|
};
|
|
|
|
|
|
2024-09-01 10:00:37 +02:00
|
|
|
class BClassInstanceRef final : public BObjectImp
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
BClassInstanceRef( BClassInstance* );
|
|
|
|
|
|
|
|
|
|
private:
|
2026-01-14 21:35:59 +01:00
|
|
|
~BClassInstanceRef() override = default;
|
2024-09-01 10:00:37 +02:00
|
|
|
|
|
|
|
|
public: // Class Machinery
|
2026-01-14 21:35:59 +01:00
|
|
|
size_t sizeEstimate() const override;
|
|
|
|
|
const char* typeOf() const override;
|
|
|
|
|
u8 typeOfInt() const override;
|
|
|
|
|
BObjectImp* copy() const override;
|
|
|
|
|
bool isTrue() const override;
|
|
|
|
|
BObjectImp* call_method( const char* methodname, Executor& ex ) override;
|
|
|
|
|
BObjectImp* call_method_id( const int id, Executor& ex, bool forcebuiltin = false ) override;
|
|
|
|
|
BObjectRef get_member_id( const int id ) override;
|
|
|
|
|
|
|
|
|
|
std::string getStringRep() const override;
|
|
|
|
|
|
|
|
|
|
ContIterator* createIterator( BObject* pIterVal ) override;
|
|
|
|
|
|
|
|
|
|
BObjectRef OperSubscript( const BObject& obj ) override;
|
|
|
|
|
BObjectRef set_member( const char* membername, BObjectImp* value, bool copy ) override;
|
|
|
|
|
BObjectRef get_member( const char* membername ) override;
|
|
|
|
|
BObjectRef operDotPlus( const char* name ) override;
|
|
|
|
|
BObjectRef operDotMinus( const char* name ) override;
|
|
|
|
|
BObjectRef operDotQMark( const char* name ) override;
|
|
|
|
|
BObjectImp* array_assign( BObjectImp* idx, BObjectImp* target, bool copy ) override;
|
2024-09-01 10:00:37 +02:00
|
|
|
|
|
|
|
|
inline BClassInstance* instance() const { return class_instance_.get(); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ref_ptr<BClassInstance> class_instance_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2026-05-27 08:02:19 +02:00
|
|
|
} // namespace Pol::Bscript
|