Skip to content

Commit c669d10

Browse files
committed
fix: Apply changes from 4.0.3-4.0.4 related to sciter dll loading.
refs sciter-sdk#112
1 parent 8b23655 commit c669d10

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

sciter-x-api.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@
66

77
EXTERN_C ISciterAPI* SCAPI SciterAPI();
88

9-
ISciterAPI* SAPI( ISciterAPI* ext ) {
10-
static ISciterAPI* _api = NULL;
9+
#if defined(__cplusplus) && !defined(PLAIN_API_ONLY)
10+
inline ISciterAPI* SAPI( ISciterAPI* ext = nullptr ) {
11+
#else
12+
inline ISciterAPI* SAPI(ISciterAPI* ext) {
13+
#endif
14+
static ISciterAPI* _api = nullptr;
1115
if( ext ) _api = ext;
1216
if( !_api )
1317
{
1418
_api = SciterAPI();
15-
tiscript::ni( _api->TIScriptAPI() );
19+
#if defined(__cplusplus) && !defined(PLAIN_API_ONLY)
20+
tiscript::ni(_api->TIScriptAPI());
21+
#endif
1622
}
23+
assert(_api);
1724
return _api;
1825
}
19-
26+
2027
#elif defined(WINDOWS)
2128

2229
ISciterAPI* SAPI( ISciterAPI* ext ) {
@@ -70,8 +77,9 @@
7077
realpath(pathbuf, folderpath);
7178
*strrchr(folderpath, '/') = '\0';
7279

73-
void* lib_sciter_handle = dlopen(SCITER_DLL_NAME, RTLD_LOCAL|RTLD_LAZY);
74-
if( !lib_sciter_handle ) {
80+
void* lib_sciter_handle = 0;
81+
{
82+
// 1. try to load from the same folder as this executable
7583
const char* lookup_paths[] =
7684
{
7785
"/" SCITER_DLL_NAME,
@@ -85,6 +93,9 @@
8593
lib_sciter_handle = dlopen(tpath, RTLD_LOCAL|RTLD_LAZY);
8694
}
8795
}
96+
if (!lib_sciter_handle) // 2. no luck, try to load from system paths
97+
lib_sciter_handle = dlopen(SCITER_DLL_NAME, RTLD_LOCAL | RTLD_LAZY);
98+
8899
if (!lib_sciter_handle) {
89100
fprintf(stderr, "[%s] Unable to load library: %s\n", __FILE__, dlerror());
90101
exit(EXIT_FAILURE);

0 commit comments

Comments
 (0)