void loadDict(std::vector<std::string>& keys, std::vector<std::string>& values, const std::string& filePath, const std::string& pattern, bool bufferFlag) { std::string line; std::vector<std::string> buf; if (bufferFlag) { std::vector<std::string> bufferVec = limonp::Split(filePath,"\n"); for (int i = 0; i < bufferVec.size(); i++) { std::string line = bufferVec[i]; limonp::Split(line, buf, pattern); assert(buf.size() >= 2); keys.push_back(buf[0]); values.push_back(buf[1]); } } else { std::ifstream ifs(filePath.c_str()); //ifs.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); XCHECK(ifs.is_open()) << "open " << filePath << " failed."; for (size_t lineno = 0; getline(ifs, line); lineno++) { limonp::Split(line, buf, pattern); assert(buf.size() >= 2); keys.push_back(buf[0]); values.push_back(buf[1]); } ifs.close(); } }
static EEL_xno init_env_table(EEL_state *es) { EEL_value a, v; EEL_xno x = eel_o_construct(es->vm, EEL_CTABLE, NULL, 0, &v); if(x) { eel_msg(es, EEL_EM_IERROR, "Could not create" " 'environment' table!\n"); return x; } es->environment = v.objref.v; SETNAME(es->environment, "'environment' Table"); /* Module paths */ XCHECK(eel_o_construct(es->vm, EEL_CARRAY, NULL, 0, &a)); XCHECK(array_sadd(a.objref.v, ".")); XCHECK(array_sadd(a.objref.v, "./modules")); XCHECK(array_sadd(a.objref.v, EEL_MODULE_DIR)); XCHECK(array_sadd(a.objref.v, "")); XCHECK(eel_setsindex(es->environment, "path_modules", &a)); eel_disown(a.objref.v); return 0; }
void Start() { XCHECK(!isStarted); XCHECK(!pthread_create(&thread_, NULL, Worker, this)); isStarted = true; }
void Join() { XCHECK(!isJoined); XCHECK(!pthread_join(thread_, NULL)); isJoined = true; }
virtual ~IThread() { if(isStarted && !isJoined) { XCHECK(!pthread_detach(thread_)); } };