示例#1
0
	void ConvertTextBufferAsStringArray(const char* buffer, behaviac::vector<behaviac::string>& stringArray)
	{
		BEHAVIAC_ASSERT(buffer);
		const char* lineBuffer = buffer;

		while (*lineBuffer != '\0')
		{
			const char* currentPos = lineBuffer;

			while (*currentPos != '\n' && *currentPos != '\r' && *currentPos != '\0')
			{
				currentPos++;
			}

			behaviac::string line;
			line.assign(lineBuffer, currentPos - lineBuffer);
			stringArray.push_back(line);

			while (*currentPos == '\n' || *currentPos == '\r')
			{
				currentPos++;
			}

			lineBuffer = currentPos;
		}
	}
示例#2
0
void CScriptSystem::EndCall(behaviac::vector<behaviac::string>& array)
{
    if (m_nTempArg == -1)
    {
        return;
    }

    if (ExecuteFunction(m_pLS, m_nTempArg, 1))
    {
        if (lua_istable(m_pLS, -1))
        {
            int top = lua_gettop(m_pLS);
            lua_pushnil(m_pLS);  // first key

            while (lua_next(m_pLS, top) != 0)
            {
                // `key' is at index -2 and `value' at index -1
                const char* value = lua_tostring(m_pLS, -1);
                array.push_back(value);
                lua_pop(m_pLS, 1); // pop value, leave index.
            }
        }

        lua_pop(m_pLS, 1);
    }

    // Check for LUA stack corruption
    CheckStackOnEndCall();
}
示例#3
0
    //suppose params are seprated by ','
    static void ParseForParams(const behaviac::string& tsrc, behaviac::vector<behaviac::string>& params)
    {
        int tsrcLen = (int)tsrc.size();
        int startIndex = 0;
        int index = 0;
        int quoteDepth = 0;

        for (; index < tsrcLen; ++index)
        {
            if (tsrc[index] == '"')
            {
                quoteDepth++;

                //if (quoteDepth == 1)
                //{
                //	startIndex = index;
                //}

                if ((quoteDepth & 0x1) == 0)
                {
                    //closing quote
                    quoteDepth -= 2;
                    BEHAVIAC_ASSERT(quoteDepth >= 0);
                }
            }
            else if (quoteDepth == 0 && tsrc[index] == ',')
            {
                //skip ',' inside quotes, like "count, count"
                int lengthTemp = index - startIndex;
                behaviac::string strTemp = tsrc.substr(startIndex, lengthTemp);
                params.push_back(strTemp);
                startIndex = index + 1;
            }
        }//end for

        // the last param
        int lengthTemp = index - startIndex;

        if (lengthTemp > 0)
        {
            behaviac::string strTemp = tsrc.substr(startIndex, lengthTemp);
            params.push_back(strTemp);

            //params.push_back(strTemp);
        }
    }
示例#4
0
	void ListFiles_android(behaviac::vector<behaviac::string>& files, const char* szDirName, bool bRecurrsive)
	{
        AAssetManager* mgr = behaviac::CFileManager::GetInstance()->GetAssetManager();
		if (mgr != NULL)
		{
			const char* validDir = szDirName;
            //skip "assets:/"
			if (behaviac::StringUtils::StartsWith(validDir, "assets:/"))
			{
				validDir = validDir + 8;
			}

			AAssetDir* dir = AAssetManager_openDir(mgr, validDir);
			if (dir != NULL)
			{
				bool bEndsWithSlash = behaviac::StringUtils::EndsWith(szDirName, "/");
				if (!bEndsWithSlash)
				{
					bEndsWithSlash = behaviac::StringUtils::EndsWith(szDirName, "\\");
				}

				while (true)
				{
					const char* fileName = AAssetDir_getNextFileName(dir);
					if (fileName == NULL)
					{
						break;
					}

                    if (bEndsWithSlash)
					{
						fileName = behaviac::FormatString("%s%s", szDirName, fileName);
					}
					else
					{
						fileName = behaviac::FormatString("%s/%s", szDirName, fileName);
					}

					files.push_back(fileName);
				}

				AAssetDir_close(dir);
			}
		}
	}
示例#5
0
	static void* ThreadFunc(void* arg)
	{
		bool isLock = false;
		const char* path = (char*)arg;
		InotifyDir inotify;
		InotifyDir::Event ev;

		inotify.init();
		inotify.Watch(path);

		while (!s_bThreadFinish)
		{
			if (!inotify.EventPoll(ev))
			{
				if (isLock)
				{
					isLock = false;
					s_mutex.Unlock();
				}

				usleep(100);
				continue;
			}

			if (!isLock)
			{
				isLock = true;
				s_mutex.Lock();
			}

			if (ev.type == InotifyDir::MODIFY || ev.type == InotifyDir::ADD)
			{
				ev.name.erase(0, strlen(path));
				s_ModifiedFiles.push_back(ev.name.c_str());
			}
		}

		if (isLock)
		{
			isLock = false;
			s_mutex.Unlock();
		}

		return NULL;
	}