Advertisement

Fake static function restrictions changed

Started by April 09, 2020 12:02 AM
3 comments, last by WitchLord 4 years, 7 months ago

Hi, it seems that restrictions for static functions (global functions with namespace of the class name) have changed. The older versions of AngelScript engine seemed capable of computing the uniqueness of a funcion based on its input parameters but the current version of 2.34 seems to give up on any global function matching if a name matches a class method (ignoring parameters).
Is this restriction going to be intended going forward?
Example code:


void MessageCallback(const asSMessageInfo *msg, void *param)
{
	const char *type = "ERR ";
	if (msg->type == asMSGTYPE_WARNING)
		type = "WARN";
	else if (msg->type == asMSGTYPE_INFORMATION)
		type = "INFO";
	printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type, msg->message);
}

class TestObj {
public:
	static void staticFunc() {}
	void memberFunc1(int test) {}
};

const char* file1 = "						\
	class SomeClass {						\n\
		void function1() {					\n\
			TestObj@ temp; temp.memberFunc1(0);		\n\
			TestObj::memberFunc1();				\n\
		}							\n\
	}								\n\
	void main() {							\n\
		TestObj@ temp; temp.memberFunc1(0); 			\n\
		TestObj::memberFunc1();					\n\
	}								\n\
	";

void FakeFunc(asIScriptGeneric * input) {
}

int main(int argCount, char* argVal[])
{
	asIScriptEngine* engine = asCreateScriptEngine();
	if (engine == 0)
	{
		std::cout << "Failed to create script engine." << std::endl;
		return -1;
	}

	int r = 0;
	r = engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL);
	assert(r >= 0);

	r = engine->RegisterObjectType("TestObj", sizeof(TestObj), asOBJ_REF | asOBJ_NOCOUNT);
	assert(r >= 0);
	r = engine->RegisterObjectMethod("TestObj", "void memberFunc1(int test)", asMETHOD(TestObj, memberFunc1), asCALL_THISCALL);

	engine->SetDefaultNamespace("TestObj");

	r = engine->RegisterGlobalFunction("void memberFunc1()", asFUNCTION(FakeFunc), asCALL_GENERIC);
	assert(r >= 0);

	engine->SetDefaultNamespace("");


	asIScriptModule* mod1 = engine->GetModule("test1", asGM_ALWAYS_CREATE);
	r = mod1->AddScriptSection("test1", file1, strlen(file1));
	assert(r >= 0);
	r = mod1->Build();
	assert(r >= 0);


	return 0;
}

This was changed in 2.33.0. The algorithm for performing symbol lookups was unified to better handle namespace hierarchies in a consistent way.

Now the compiler will lookup the symbol by the name to determine the type of entity, and only after that determine what to do. global functions and class methods are not the same type of entities so they will no longer be used together for argument matching.

I plan to eventually implement true static member functions which should then support doing what you mention, but for now it is not possible with the fake static member functions.

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

@witchlord Is there any plans to tweak the code to allow fake static functions to have the same name as a member function before full static support comes in? It's not urgent for me so asking to find out if I should wait or look into doing my own changes if I need this.

I don't really have any plans for that. Though if the arguments for supporting it are strong enough I might consider it.

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