|
6 | 6 |
|
7 | 7 | EXTERN_C ISciterAPI* SCAPI SciterAPI();
|
8 | 8 |
|
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; |
11 | 15 | if( ext ) _api = ext;
|
12 | 16 | if( !_api )
|
13 | 17 | {
|
14 | 18 | _api = SciterAPI();
|
15 |
| - tiscript::ni( _api->TIScriptAPI() ); |
| 19 | +#if defined(__cplusplus) && !defined(PLAIN_API_ONLY) |
| 20 | + tiscript::ni(_api->TIScriptAPI()); |
| 21 | +#endif |
16 | 22 | }
|
| 23 | + assert(_api); |
17 | 24 | return _api;
|
18 | 25 | }
|
19 |
| - |
| 26 | + |
20 | 27 | #elif defined(WINDOWS)
|
21 | 28 |
|
22 | 29 | ISciterAPI* SAPI( ISciterAPI* ext ) {
|
|
70 | 77 | realpath(pathbuf, folderpath);
|
71 | 78 | *strrchr(folderpath, '/') = '\0';
|
72 | 79 |
|
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 |
75 | 83 | const char* lookup_paths[] =
|
76 | 84 | {
|
77 | 85 | "/" SCITER_DLL_NAME,
|
|
85 | 93 | lib_sciter_handle = dlopen(tpath, RTLD_LOCAL|RTLD_LAZY);
|
86 | 94 | }
|
87 | 95 | }
|
| 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 | + |
88 | 99 | if (!lib_sciter_handle) {
|
89 | 100 | fprintf(stderr, "[%s] Unable to load library: %s\n", __FILE__, dlerror());
|
90 | 101 | exit(EXIT_FAILURE);
|
|
0 commit comments