Jump to content
  • Advertisement
Sign in to follow this  

Namespace Bug?

This topic is 1262 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

        int operator[](int num)
            return 1;

        void test() { }

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

    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);

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

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

    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>'


Edited by dkrusu

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!