Advertisement

Limit on number of any type arguments?

Started by November 05, 2010 11:05 AM
5 comments, last by droz 14 years ago
Does angelscript have a limit of any parameters that can be used? I have the following to register a set of Compose functions for my string class (Str.Compose("Test %1", 33)). When I try to register a function to take more than 10 any types I get the following error when running the script:

ERR : Unexpected token '?'

I register it using the following:
    obj.addMethod("String@ Compose(const String &in, ?&in)", asFUNCTION(Compose1), asCALL_CDECL_OBJLAST);    obj.addMethod("String@ Compose(const String &in, ?&in, ?&in)", asFUNCTION(Compose2), asCALL_CDECL_OBJLAST);    obj.addMethod("String@ Compose(const String &in, ?&in, ?&in, ?&in)", asFUNCTION(Compose3), asCALL_CDECL_OBJLAST);    obj.addMethod("String@ Compose(const String &in, ?&in, ?&in, ?&in, ?&in)", asFUNCTION(Compose4), asCALL_CDECL_OBJLAST);    obj.addMethod("String@ Compose(const String &in, ?&in, ?&in, ?&in, ?&in, ?&in)", asFUNCTION(Compose5), asCALL_CDECL_OBJLAST);    obj.addMethod("String@ Compose(const String &in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in)", asFUNCTION(Compose6), asCALL_CDECL_OBJLAST);    obj.addMethod("String@ Compose(const String &in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in)", asFUNCTION(Compose7), asCALL_CDECL_OBJLAST);    obj.addMethod("String@ Compose(const String &in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in)", asFUNCTION(Compose8), asCALL_CDECL_OBJLAST);    obj.addMethod("String@ Compose(const String &in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in)", asFUNCTION(Compose9), asCALL_CDECL_OBJLAST);    obj.addMethod("String@ Compose(const String &in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in)",                     asFUNCTION(Compose10), asCALL_CDECL_OBJLAST);   obj.addMethod("String@ Compose(const String &in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in)",                     asFUNCTION(Compose11), asCALL_CDECL_OBJLAST);


The addMethod function just wraps RegisterObjectMethod and checks the return code. So my question is this a limit for a reason? If so maybe you should check the number used and make RegisterObjectMethod fail.
There shouldn't be a limit, though for some platform specific implementations of native calling convention there is currently a limit due to preallocated buffers.

It is the parser that is giving you the error that you see. This would indicate that the declaration is not following the proper syntax. Perhaps it was cutoff during a string copy?

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
That isn't the issue, I checked that before posting. Also the following works fine:

obj.addMethod("void Test(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n)", asFUNCTION(Test), asCALL_CDECL_OBJLAST);
It's not failing when registering the function, it's failing in asCParser::ParseScript. I added some debug info to make sure the registration works, and as I stated earlier the function returns a positive return value.

I was also wrong it's not when registering 11 var type parameters, it happens when registering 12:

obj.addMethod("String@ Compose(const String &in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in)", asFUNCTION(Compose12), asCALL_CDECL_OBJLAST);


The script thats being parsed does not contain a ? and works if I remove the declaration of all functions taking more than 11 arguments.

This is the test script:
class App {    int Run() {        return 0;    }        }
Ah, sorry. I thought the problem was when you were registering the function.

I'll have to try to reproduce this problem to see what might be going wrong.

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

I'm not able to reproduce the problem. This is the test I wrote for this:

		engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);		engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);		RegisterScriptString(engine);		r = engine->RegisterObjectType("obj", sizeof(int), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_PRIMITIVE); assert( r >= 0 );		r = engine->RegisterObjectMethod("obj", "string @fmt(const string &in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in, ?&in)", asFUNCTION(testFuncSI_generic), asCALL_GENERIC); assert( r >= 0 );		asIScriptModule *mod = engine->GetModule("1", asGM_ALWAYS_CREATE);		mod->AddScriptSection("script", 			"class App {\n"			"	int Run() {\n"			"		return 0;\n"			"	}\n"			"}\n");		r = mod->Build();		if( r < 0 )			TEST_FAILED;		engine->Release();


The script compiles just fine, even with 20 vartype arguments (?).

Can you set a breakpoint in the message callback, and then have a look into the script buffer that is being parsed to make sure it is really is what you're expecting? Is the script null terminated? Or do you manually inform the size of the script?

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
Yeah, something is definitely happening to the script buffer as it ends up being:

"class App {\n    int Run() {\n        return 0;\n    }        \n}\n\n ?&in, ?&in, ?&in, ?&in, ?&in, ?&h"


Still trying to track it down, I'm sure it's a problem with my program, sorry for wasting your time.

This topic is closed to new replies.

Advertisement