Advertisement

Namespace Bug?

Started by April 11, 2015 06:43 PM
1 comment, last by WitchLord 9 years, 7 months ago

I've encountered a bug with namespaces, if you create a object type inside of a namespace besides the global, then create a global property with the same name as the object type but in the global namespace, the opIndex method fails. The following code should show whats going on more than my explanation


#include "angelscript.h"
#include <stdio.h>

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 FooObj
{
    public:
        FooObj() { };

        int operator[](int num)
        {
            return 1;
        }

        void test() { }
};

int main()
{
    asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
	engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL);

    engine->SetDefaultNamespace("NSBugTest");
    engine->RegisterObjectType("FooObj", 0, asOBJ_REF | asOBJ_NOCOUNT);
    engine->RegisterObjectMethod("FooObj", "int opIndex(int)", asMETHOD(FooObj, FooObj::operator[]), asCALL_THISCALL);
    engine->RegisterObjectMethod("FooObj", "void test()", asMETHOD(FooObj, FooObj::test), asCALL_THISCALL);
    engine->SetDefaultNamespace("");

    FooObj foo;
    engine->RegisterGlobalProperty("NSBugTest::FooObj FooObj", &foo);

    asIScriptModule *mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
	mod->AddScriptSection("test",
			"void main() \n"
			"{ \n"
            "   FooObj.test();\n"
            "   int num = FooObj[0];\n"
			"} \n");
	mod->Build();

    return 0;

}

The call to test() will work like it should, however the opIndex call generates the following error:


test (1, 1) : INFO : Compiling void main()
test (4, 21) : ERR  : Expected ']'
test (4, 21) : ERR  : Instead found '<integer constant>'

Thanks

Thanks for the report. I'll investigate and have it fixed 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

I've fixed this in revision 2154.

Thanks,

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