Skip to content

Commit

Permalink
Update to Sciter 4.4.7.0+ (#1)
Browse files Browse the repository at this point in the history
Co-authored-by: Dmitriy Seregin <[email protected]>
  • Loading branch information
105th and 105th authored Jul 6, 2021
1 parent a04e052 commit 46d0494
Show file tree
Hide file tree
Showing 23 changed files with 1,145 additions and 925 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Go bindings for Sciter

[![Build status](https://ci.appveyor.com/api/projects/status/rphv883klffw9em9/branch/master?svg=true)](https://ci.appveyor.com/project/pravic/go-sciter)
[![Build Status](https://img.shields.io/travis/sciter-sdk/go-sciter/master.svg)](https://travis-ci.org/sciter-sdk/go-sciter)
[![AppVeyor status](https://ci.appveyor.com/api/projects/status/rphv883klffw9em9/branch/master?svg=true)](https://ci.appveyor.com/project/pravic/go-sciter)
[![Travis Status](https://travis-ci.com/sciter-sdk/go-sciter.svg?branch=master)](https://travis-ci.com/sciter-sdk/go-sciter)
[![License](https://img.shields.io/github/license/sciter-sdk/go-sciter.svg)](https://github.com/sciter-sdk/go-sciter)
[![Join the forums at https://sciter.com/forums](https://img.shields.io/badge/forum-sciter.com-orange.svg)](https://sciter.com/forums)

Expand Down
12 changes: 6 additions & 6 deletions callbacks.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "sciter-x.h"
#include "_cgo_export.h"

// typedef BOOL SC_CALLBACK SciterElementCallback(HELEMENT he, LPVOID param);
// typedef SBOOL SC_CALLBACK SciterElementCallback(HELEMENT he, LPVOID param);

BOOL SC_CALLBACK SciterElementCallback_cgo(HELEMENT he, LPVOID param)
SBOOL SC_CALLBACK SciterElementCallback_cgo(HELEMENT he, LPVOID param)
{
return goSciterElementCallback(he, param);
}
Expand All @@ -26,8 +26,8 @@ VOID SC_CALLBACK LPCSTR_RECEIVER_cgo(LPCSTR str, UINT str_length, LPVOID param)
goLPCSTR_RECEIVER(str, str_length, param);
}

// typedef BOOL SC_CALLBACK ElementEventProc(LPVOID tag, HELEMENT he, UINT evtg, LPVOID prms);
BOOL SC_CALLBACK ElementEventProc_cgo(LPVOID tag, HELEMENT he, UINT evtg, LPVOID prms)
// typedef SBOOL SC_CALLBACK ElementEventProc(LPVOID tag, HELEMENT he, UINT evtg, LPVOID prms);
SBOOL SC_CALLBACK ElementEventProc_cgo(LPVOID tag, HELEMENT he, UINT evtg, LPVOID prms)
{
return goElementEventProc(tag, he, evtg, prms);
}
Expand Down Expand Up @@ -57,9 +57,9 @@ INT SC_CALLBACK ELEMENT_COMPARATOR_cgo(HELEMENT he1, HELEMENT he2, LPVOID param)
return goELEMENT_COMPARATOR(he1, he2, param);
}

// typedef BOOL SC_CALLBACK KeyValueCallback(LPVOID param, const VALUE* pkey, const VALUE* pval);
// typedef SBOOL SC_CALLBACK KeyValueCallback(LPVOID param, const VALUE* pkey, const VALUE* pval);

BOOL SC_CALLBACK KeyValueCallback_cgo(LPVOID param, const VALUE* pkey, const VALUE* pval)
SBOOL SC_CALLBACK KeyValueCallback_cgo(LPVOID param, const VALUE* pkey, const VALUE* pval)
{
return goKeyValueCallback(param, (VALUE*)pkey, (VALUE*)pval);
}
2 changes: 1 addition & 1 deletion examples/callback/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"log"
"path/filepath"

"github.com/sciter-sdk/go-sciter"
"github.com/sciter-sdk/go-sciter/window"
)
Expand Down
2 changes: 1 addition & 1 deletion examples/demoes/01/demo1.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"log"
"path/filepath"

"github.com/sciter-sdk/go-sciter"
"github.com/sciter-sdk/go-sciter/window"
)
Expand Down
2 changes: 1 addition & 1 deletion examples/demoes/05/demo5.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"log"
"path/filepath"

"github.com/sciter-sdk/go-sciter"
"github.com/sciter-sdk/go-sciter/window"
)
Expand Down
2 changes: 1 addition & 1 deletion examples/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"flag"
"log"
"path/filepath"

"github.com/sciter-sdk/go-sciter"
"github.com/sciter-sdk/go-sciter/rice"
"github.com/sciter-sdk/go-sciter/window"
Expand Down
2 changes: 1 addition & 1 deletion examples/textHtml/textHtml.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
</form>
</div>
<div id="output">
</div>
</body>
</html>
Expand Down
257 changes: 197 additions & 60 deletions include/sciter-om-def.h

Large diffs are not rendered by default.

69 changes: 49 additions & 20 deletions include/sciter-om.h
Original file line number Diff line number Diff line change
@@ -1,37 +1,55 @@
#pragma once

#include <string.h>
#include <assert.h>
#ifndef __SCITER_OM_H__
#define __SCITER_OM_H__


struct som_passport_t;
struct som_asset_class_t;

typedef UINT64 som_atom_t;


struct som_asset_class_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);
struct som_passport_t* (*asset_get_passport)(som_asset_t* thing);
};
} som_asset_class_t;


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

som_atom_t SCAPI SciterAtomValue(const char* name);

#ifdef CPP11

#include <cstring>
#include <cassert>
#include <atomic>

namespace sciter {

class atom {
som_atom_t _atom;
public:
atom(const char* name) { _atom = SciterAtomValue(name); }
atom(const atom& other) { _atom = other._atom; }
operator som_atom_t() const { return _atom; }
};

namespace om {

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
template <class A>
class iasset : public som_asset_t
{
Expand Down Expand Up @@ -70,7 +88,6 @@ namespace sciter {
//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 @@ -97,8 +114,13 @@ namespace sciter {
return ptr->isa->asset_get_passport(ptr);
}

inline som_asset_class_t* asset_get_class(som_asset_t *ptr) {
assert(ptr);
return ptr->isa;
}

//hasset - yet another shared_ptr
// R here is something derived from the iasset (om::iasset) above
// R here is an entity derived from som_asset_t
template <class R> class hasset
{
protected:
Expand All @@ -108,10 +130,10 @@ namespace sciter {
typedef R asset_t;

hasset() :p(nullptr) {}
hasset(R* lp) :p(nullptr) { if (lp) (p = lp)->asset_add_ref(); }
hasset(const hasset<R>& cp) :p(nullptr) { if (cp.p) (p = cp.p)->asset_add_ref(); }
hasset(R* lp) :p(nullptr) { if (lp) asset_add_ref(p = lp); }
hasset(const hasset<R>& cp) :p(nullptr) { if (cp.p) asset_add_ref(p = cp.p); }

~hasset() { if (p) p->asset_release(); }
~hasset() { if (p) asset_release(p); }
operator R*() const { return p; }
R* operator->() const { assert(p != 0); return p; }

Expand All @@ -121,7 +143,7 @@ namespace sciter {
bool operator==(R* pR) const { return p == pR; }

// release the interface and set it to NULL
void release() { if (p) { R* pt = p; p = 0; pt->asset_release(); } }
void release() { if (p) { R* pt = p; p = 0; asset_release(pt); } }

// attach to an existing interface (does not AddRef)
void attach(R* p2) { asset_release(p); p = p2; }
Expand All @@ -130,8 +152,8 @@ namespace sciter {

static R* assign(R* &pp, R* lp)
{
if (lp != 0) lp->asset_add_ref();
if (pp) pp->asset_release();
if (lp != 0) asset_add_ref(lp);
if (pp) asset_release(pp);
pp = lp;
return lp;
}
Expand All @@ -143,10 +165,8 @@ namespace sciter {

};


// intrusive add_ref/release counter

template<class C>
// reference counted asset, uses intrusive add_ref/release counter
template<class C>
class asset : public iasset<asset<C>>
{
std::atomic<long> _ref_cntr;
Expand Down Expand Up @@ -179,11 +199,20 @@ namespace sciter {
delete static_cast<C*>(this);
}
};
}


template <class AT>
inline AT* value::get_asset() const {
som_asset_t* pass = get_asset();
if (pass && (som_asset_get_class(pass) == AT::get_asset_class()))
return static_cast<AT*>(pass);
return nullptr;
}

}

#endif

#include "sciter-om-def.h"

#endif
Loading

0 comments on commit 46d0494

Please sign in to comment.