Advertisement

Invalid namespace parsing in CScriptBuilder

Started by September 04, 2024 03:33 PM
2 comments, last by WitchLord 2 months, 3 weeks ago

Hello! When compiling a script using CScriptBuilder, the program crashes because the script engine does not find the required function when parsing metadata. Here is an example script code:

namespace Base::Nested
{
	[metadata]
	void do_something()
	{
	}
}

The problem is that CScriptBuilder can't parse the namespace correctly, and only Base is used instead of Base::Nested. Here is a piece of code from scriptbuilder.cpp that I don't think is working correctly:

// Get the identifier after "namespace"
do
{
	pos += len;
	t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len);
} while (t == asTC_COMMENT || t == asTC_WHITESPACE);

if (currentNamespace != "")
	currentNamespace += "::";
currentNamespace += modifiedScript.substr(pos, len);

Maybe it should be replaced with something like this? Thank you!

// Get the identifier after "namespace"
do
{
	do
	{
		pos += len;
		t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len);
	} while (t == asTC_COMMENT || t == asTC_WHITESPACE);
	
	if (t == asTC_IDENTIFIER)
	{
		if (currentNamespace != "")
			currentNamespace += "::";
		currentNamespace += modifiedScript.substr(pos, len);
	}
} while (t == asTC_IDENTIFIER || (t == asTC_KEYWORD && modifiedScript.substr(pos, len) == "::"));

Yes. At a quick glance I think you're correct with your analysis and proposed solution.

I'll verify this and apply the fix as soon as possible.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

Your solution was correct. Thanks for the contribution.

I've checked this into the repository in revision 2952.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement