Skip to content

Commit

Permalink
Adapt headers for CGO.
Browse files Browse the repository at this point in the history
  • Loading branch information
pravic committed Apr 26, 2021
1 parent 6627882 commit ffbfc63
Show file tree
Hide file tree
Showing 8 changed files with 411 additions and 784 deletions.
14 changes: 7 additions & 7 deletions include/sciter-om-def.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ typedef SBOOL(*som_any_prop_setter_t)(som_asset_t* thing, UINT64 propSymbol, con
typedef SBOOL(*som_method_t)(som_asset_t* thing, UINT argc, const SOM_VALUE* argv, SOM_VALUE* p_result);
typedef void(*som_dispose_t)(som_asset_t* thing);

struct som_property_def_t {
typedef struct som_property_def_t {
void* reserved;
som_atom_t name;
som_prop_getter_t getter;
som_prop_setter_t setter;
#ifdef __cplusplus
som_property_def_t(const char* n, som_prop_getter_t pg, som_prop_setter_t ps = nullptr) : name(SciterAtomValue(n)), getter(pg), setter(ps) {}
#endif
};
} som_property_def_t;

struct som_method_def_t {
typedef struct som_method_def_t {
void* reserved;
som_atom_t name;
size_t params;
som_method_t func;
#ifdef __cplusplus
som_method_def_t(const char* n, size_t p, som_method_t f) : name(SciterAtomValue(n)), params(p), func(f) {}
#endif
};
} som_method_def_t;

enum som_passport_flags {
SOM_SEALED_OBJECT = 0x00, // not extendable
Expand All @@ -56,7 +56,7 @@ enum som_passport_flags {

// definiton of object (the thing) access interface
// this structure should be statically allocated - at least survive last instance of the engine
struct som_passport_t {
typedef struct som_passport_t {
UINT64 flags;
som_atom_t name; // class name
const som_property_def_t* properties; size_t n_properties; // virtual property thunks
Expand All @@ -67,7 +67,7 @@ struct som_passport_t {
// any property "inteceptors"
som_any_prop_getter_t prop_getter; // var prop_val = thing.k;
som_any_prop_setter_t prop_setter; // thing.k = prop_val;
};
} som_passport_t;

#ifdef CPP11

Expand Down Expand Up @@ -533,7 +533,7 @@ namespace sciter {
};

template <class Type> struct prop_get_accessor;


// bool get_any_prop(const std::string& name, TV& val);
template <class Type, class TV>
Expand Down
34 changes: 17 additions & 17 deletions include/sciter-om.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@


struct som_passport_t;
struct som_asset_class_t;

typedef UINT64 som_atom_t;

struct som_asset_t;
typedef struct som_asset_t {
struct som_asset_class_t* isa;
} som_asset_t;

struct som_asset_class_t {
typedef struct som_asset_class_t {
long(*asset_add_ref)(som_asset_t* thing);
long(*asset_release)(som_asset_t* thing);
long(*asset_get_interface)(som_asset_t* thing, const char* name, void** out);
som_passport_t* (*asset_get_passport)(som_asset_t* thing);
};
struct som_passport_t* (*asset_get_passport)(som_asset_t* thing);
} som_asset_class_t;

struct som_asset_t {
som_asset_class_t* isa;
};

inline som_asset_class_t* som_asset_get_class(const som_asset_t* pass)
{
return pass ? pass->isa : nullptr;
return pass ? pass->isa : 0;
}

som_atom_t SCAPI SciterAtomValue(const char* name);
Expand All @@ -49,7 +49,7 @@ namespace sciter {
template <class R> class hasset;

// implementation of som_asset_t ISA
// note: does not define asset_add_ref()/asset_release() as they shall be defined in specializations
// note: does not define asset_add_ref()/asset_release() as they shall be defined in specializations
template <class A>
class iasset : public som_asset_t
{
Expand All @@ -65,8 +65,8 @@ namespace sciter {
if (out) { this->asset_add_ref(); *out = this; }
return true;
}
virtual som_passport_t* asset_get_passport() const {
return nullptr;
virtual som_passport_t* asset_get_passport() const {
return nullptr;
}

static som_asset_class_t* get_asset_class() {
Expand All @@ -87,7 +87,7 @@ namespace sciter {
static const char* interface_name() { return "asset.sciter.com"; }
//template<class C> hasset<C> interface_of() { hasset<C> p; get_interface(C::interface_name(), p.target()); return p; }
};

inline long asset_add_ref(som_asset_t *ptr) {
assert(ptr);
assert(ptr->isa);
Expand All @@ -106,7 +106,7 @@ namespace sciter {
assert(ptr->isa->asset_get_interface);
return ptr->isa->asset_get_interface(ptr, name, out);
}

inline som_passport_t* asset_get_passport(som_asset_t *ptr) {
assert(ptr);
assert(ptr->isa);
Expand All @@ -118,7 +118,7 @@ namespace sciter {
assert(ptr);
return ptr->isa;
}

//hasset - yet another shared_ptr
// R here is an entity derived from som_asset_t
template <class R> class hasset
Expand Down Expand Up @@ -164,9 +164,9 @@ namespace sciter {
void** target() { release(); return (void**)&p; }

};

// reference counted asset, uses intrusive add_ref/release counter
template<class C>
template<class C>
class asset : public iasset<asset<C>>
{
std::atomic<long> _ref_cntr;
Expand Down Expand Up @@ -215,4 +215,4 @@ namespace sciter {

#include "sciter-om-def.h"

#endif
#endif
Loading

0 comments on commit ffbfc63

Please sign in to comment.