Esempio n. 1
0
	void CGameObject::CreateLuaObject()
	{
		if (LuaVirtualMachine->IsObjectExists(GetName()))
			Log("ERROR", "Lua object named '%s' alredy exists", GetName().c_str());

		LuaVirtualMachine->CreateLuaObject(ClassName, GetName(), this);

		if (IsPrototype() && LuaVirtualMachine->IsMethodFunctionExists(GetName(), "OnPrototypeInstantiate"))
			LuaVirtualMachine->CallMethodFunction(GetName(), "OnPrototypeInstantiate");
	}
Esempio n. 2
0
	CGameObject* CGameObject::CloneTree(const string &ACloneName /*= ""*/, AlreadyClonedContainer *AlreadyCloned /*= NULL*/) const
	{
		CGameObject *result = Clone(ACloneName);

		map<CGameObject *, CGameObject *> *FirstAlreadyCloned = NULL;
		if (!AlreadyCloned)
			AlreadyCloned = FirstAlreadyCloned = new AlreadyClonedContainer;

		CGameObject *obj = NULL;

		for (LNOMType::const_iterator it = LocalNameObjectMapping.begin(); it != LocalNameObjectMapping.end(); ++it)
		{
			obj = it->second->CloneTree("", AlreadyCloned);
			result->LocalNameObjectMapping[it->first] = obj;
			(*AlreadyCloned)[it->second] = obj;
		}


		for (ChildrenConstIterator it = Children.begin(); it != Children.end(); ++it)
		{
			if (AlreadyCloned->count(*it))
				obj = (*AlreadyCloned)[*it];
			else
				obj = (*it)->CloneTree("", AlreadyCloned);

			result->Attach(obj);
		}

		if (IsPrototype())
			result->FinalizeCreation();

		if (FirstAlreadyCloned)
			delete FirstAlreadyCloned;

		return result;
	}
bool TagEntry::IsMethod() const { return IsPrototype() || IsFunction(); }
void
CBSymbolList::ReadSymbolList
	(
	istream&			input,
	const CBLanguage	lang,
	const JCharacter*	fullName,
	const JFAID_t		fileID
	)
{
	JString path, fileName;
	JSplitPathAndName(fullName, &path, &fileName);

	input >> ws;
	while (input.peek() == '!')
		{
		JIgnoreLine(input);
		input >> ws;
		}

	JStringPtrMap<JString> flags(JPtrArrayT::kDeleteAll);
	while (1)
		{
		JString* name = new JString;
		assert( name != NULL );

		input >> ws;
		*name = JReadUntil(input, '\t');		// symbol name
		if (input.eof() || input.fail())
			{
			delete name;
			break;
			}

		JIgnoreUntil(input, '\t');				// file name

		JIndex lineIndex;
		input >> lineIndex;						// line index

		ReadExtensionFlags(input, &flags);

		JCharacter typeChar = ' ';
		JString* value;
		if (flags.GetElement("kind", &value) && !value->IsEmpty())
			{
			typeChar = value->GetFirstCharacter();
			}

		JString* signature = NULL;
		if (flags.GetElement("signature", &value) && !value->IsEmpty())
			{
			signature = new JString(*value);
			assert( signature != NULL );
			signature->PrependCharacter(' ');
			}

		if (IgnoreSymbol(*name))
			{
			delete name;
			}
		else
			{
			const Type type = DecodeSymbolType(lang, typeChar);
			if (signature == NULL &&
				(IsFunction(type) || IsPrototype(type)))
				{
				signature = new JString(" ( )");
				assert( signature != NULL );
				}

			const SymbolInfo info(name, signature, lang, type,
								  kJFalse, fileID, lineIndex);
			itsSymbolList->InsertSorted(info);

			// add file:name

			if (IsFileScope(type))
				{
				JString* name1 = new JString(fileName);
				assert( name1 != NULL );
				*name1 += ":";
				*name1 += *name;

				JString* sig1 = NULL;
				if (signature != NULL)
					{
					sig1 = new JString(*signature);
					assert( sig1 != NULL );
					}

				const SymbolInfo info1(name1, sig1, lang, type,
									   kJTrue, fileID, lineIndex);
				itsSymbolList->InsertSorted(info1);
				}
			}
		}
}
JBoolean
CBSymbolList::FindSymbol
	(
	const JCharacter*	name,
	const JFAID_t		contextFileID,
	const JString&		contextNamespace,
	const CBLanguage	contextLang,
	JPtrArray<JString>*	cContextNamespaceList,
	JPtrArray<JString>*	javaContextNamespaceList,
	const JBoolean		findDeclaration,
	const JBoolean		findDefinition,
	JArray<JIndex>*		matchList
	)
	const
{
	// find all symbols that match

	matchList->RemoveAll();
	matchList->SetBlockSize(50);

	JArray<JIndex> allMatchList(50);

	JString s = name;
	SymbolInfo target;
	target.name = &s;
	JIndex startIndex;
	if (itsSymbolList->SearchSorted(target, JOrderedSetT::kFirstMatch, &startIndex))
		{
		const JSize count = itsSymbolList->GetElementCount();
		for (JIndex i=startIndex; i<=count; i++)
			{
			const SymbolInfo info = itsSymbolList->GetElement(i);
			if (!CompareSymbols(target, info) == JOrderedSetT::kFirstEqualSecond)
				{
				break;
				}

			if (!CBIsCaseSensitive(info.lang) || *(info.name) == s)
				{
				if (contextFileID == info.fileID &&		// automatically fails if context is kInvalidID
					IsFileScope(info.type))
					{
					matchList->RemoveAll();
					matchList->AppendElement(i);
					break;
					}

				if ((findDeclaration || !IsPrototype(info.type)) &&
					(findDefinition  || !IsFunction(info.type)))
					{
					matchList->AppendElement(i);
					}
				allMatchList.AppendElement(i);
				}
			}
		}

	JBoolean usedAllList = kJFalse;
	if (matchList->IsEmpty())
		{
		*matchList  = allMatchList;
		usedAllList = kJTrue;
		}

	// replace symbols with fully qualified versions

	if (!matchList->IsEmpty())
		{
		JString ns1, ns2;
		PrepareContextNamespace(contextNamespace, contextLang, &ns1, &ns2);
		PrepareCContextNamespaceList(cContextNamespaceList);
		PrepareJavaContextNamespaceList(javaContextNamespaceList);

		JArray<JIndex> noContextList = *matchList;
		if (!ConvertToFullNames(&noContextList, matchList,
								ns1, ns2, contextLang,
								*cContextNamespaceList, *javaContextNamespaceList))
			{
			if (!usedAllList && !findDeclaration && findDefinition)
				{
				// if no definition, try declarations
				// (all: class decl, C++: pure virtual fn)

				JArray<JIndex> allNoContextList = allMatchList;
				if (ConvertToFullNames(&allNoContextList, &allMatchList,
									   ns1, ns2, contextLang,
									   *cContextNamespaceList, *javaContextNamespaceList))
					{
					*matchList = allMatchList;
					}
				else
					{
					*matchList = noContextList;		// honor original request for only defn
					}
				}
			else
				{
				*matchList = noContextList;
				}
			}

		// re-sort

		matchList->SetCompareObject(FindSymbolCompare(*itsSymbolList));
		matchList->SetSortOrder(itsSymbolList->GetSortOrder());
		matchList->Sort();

		return kJTrue;
		}
	else
		{
		return kJFalse;
		}
}