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

Recommended Posts

Hello, Till now I was using AngelScript in a very simple way : ExecuteString(...) This was well working. Then I have decided to work another way : AddScriptSection + Build + GetFunctionID ... Well, this doesn't work. What I'm doing is : AddScriptSection("module", "funcname", "void funcname() {" + same code that was working with ExecuteString + "}", strlen(..)) as many time as i have pieces of code. Then I call Build and I get : Building... Parsing: "XPNTree_TIMEOUT" Error : (1, 13) Expected identifier Parsing: "TheOtherCode" Error : (1, 101) Expected identifier Error : (1, 145) Unexpected token 'if' Parsing: "FlipImage" Error : (1, 84) Expected identifier ... What I am doing wrong ? Thanks for any answer. AbrKen.

Share on other sites
some more elements :

this code :

void XPNTree_TIMEOUT() {
int i; i = 50;
}

void TheOtherCode() {
...

Generate :
Building...
Parsing: "XPNTree_TIMEOUT"
Error : (1, 13) Expected identifier
...

this code :

void XPNTree_TIMEOUT() {
int i;
}

void TheOtherCode() {
...

is well compiling.

Share on other sites
more clues for anyone that can answer the first message :

If I call AddScriptSection only one time (with all the script functions concatenated of course), this works just fine.

Why ?

Share on other sites
I can't see any error in the way you're doing it. I'll have to make some tests.

Would it be possible for you to write a test case for the test framework that reproduces the errors and then pass that to me? That will make it easier for me to help you.

You'll find the test framework here:

http://www.angelcode.com/angelscript/files/testframe.zip

Calling AddScriptSection() only one time or multiple times shouldn't make any difference, except for the error reporting.

Regards,
Andreas

Share on other sites
I tried the following and had no errors:

#include "angelscript.h"#include <stdio.h>#include <string.h>static const char *script = "void XPNTree_TIMEOUT() {int i; i = 50;}";static const char *script2 = "void TheOtherCode() {}";class COutStream : public asIOutputStream{public:	void AS_CALL Write(const char *text) { printf(text); }};bool Test_Build(){	bool ret = false;	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);	engine->AddScriptSection("test", "test", script, strlen(script));	engine->AddScriptSection("test", "test2", script2, strlen(script2));	COutStream out;	int r = engine->Build("test", &out);	if( r < 0 )	{		printf("Test_Build: Failed to build script.\n");		ret = true;	}	engine->Release();		return ret;}

What are you different from my example above?

Could it be that you're not sending the correct length of the script? Verify the way you call strlen().

Share on other sites

I wasn't sending function declaration, eg :

/*void FlipImage(){*/			bstr bstrTmp;			string strTmp;			CLuaXmlPresenter *xmlPresenter;			xmlPresenter = getReferencedPresenter("XPNPresenter");			if (xmlPresenter != 0) {				CLuaXmlPresenterElementBitmap *xmlBitmap;				xmlBitmap = xmlPresenter->GetBitmap(10);				if (xmlBitmap != 0) {					CImage *imageBitmap;					imageBitmap = xmlBitmap->GetImageBitmap();					if (imageBitmap != 0) {						imageBitmap->Flip();						xmlBitmap->Display(0, true);					}				}			}/*}*/

The comment line are what was missing (not sent to AddScriptSection).

This is interristing, I have learned this way that ScriptCode MUST be contained in function, ans ONLY variable declaration is addmited as global.