diff --git a/koala-wrapper/native/src/common.cc b/koala-wrapper/native/src/common.cc index 553a1079b72f7767f317fe0025f0a384f66bb1b7..d95f378fdec3370e8131e8ff784d7bb4887b841b 100644 --- a/koala-wrapper/native/src/common.cc +++ b/koala-wrapper/native/src/common.cc @@ -50,6 +50,19 @@ const char *LIB_DIR = "lib"; static std::string ES2PANDA_LIB_PATH; +std::string joinPath(vector &paths) +{ + std::string res; + for (int i = 0; i < paths.size(); ++i) { + if (i == 0) { + res = paths[i]; + } else { + res += SEPARATOR + paths[i]; + } + } + return res; +} + void impl_SetUpSoPath(KStringPtr &soPath) { ES2PANDA_LIB_PATH = std::string(soPath.c_str()); @@ -57,8 +70,16 @@ void impl_SetUpSoPath(KStringPtr &soPath) KOALA_INTEROP_V1(SetUpSoPath, KStringPtr); void* FindLibrary() { - std::string soFullPath = ES2PANDA_LIB_PATH + SEPARATOR + LIB_DIR + SEPARATOR + LIB_ES2PANDA_PUBLIC; - return loadLibrary(soFullPath); + std::vector pathArray; + char* envValue = getenv("PANDA_SDK_PATH"); + if (envValue) { + pathArray = {envValue, PLUGIN_DIR, LIB_DIR, LIB_ES2PANDA_PUBLIC}; + } else if (!ES2PANDA_LIB_PATH.empty()) { + pathArray = {ES2PANDA_LIB_PATH, LIB_DIR, LIB_ES2PANDA_PUBLIC}; + } else { + pathArray = {LIB_ES2PANDA_PUBLIC}; + } + return loadLibrary(joinPath(pathArray)); } es2panda_Impl *GetImpl() {