Jump to content
  • Advertisement
Sign in to follow this  
luizribeiro

Module building error

This topic is 4838 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

Hello... This is my first try with AngelScript, I'm using the following code:
// AngelScript
void Update() {
        float x = 1.333;
        return x;
}

// C++
asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);;
FILE *f = NULL;
char *script = NULL;
int length = 0;
int functionID;

// Load the script
f = fopen("myscriptfile.as", "r");
fseek(f, 0, SEEK_END);
length = int(ftell(f));
fseek(f, 0, SEEK_SET);
script = new char[length];
fread(script, length, 1, f);
fclose(f); f = NULL;

// Compile the script
if(engine->AddScriptSection("module", "section", script, length) < 0) {
	printf("Error on AddScriptSession.\n");
	return 1;
}
int err = engine->Build("module");
if(err < 0) {
	printf("Error building the module: %d\n", err);
	return 1;
}
	
// ...
It's returning "Error building the module: -1"... I really don't know what to do... I think it's a stupid thing, but I'm starting... hehe Thanks anyway... Luiz Ribeiro

Share this post


Link to post
Share on other sites
Advertisement
Olá, Luiz! Seja bem vindo. [smile]

Rain Dog is correct.

You can use the output stream in order to receive the compiler messages, including warnings and errors. Example:


class COutStream : public asIOutputStream
{
public:
void Write(const char *text) { printf(text); }
};

COutStream out;
int err = engine->Build("module", &out);


Regards,
Andreas

Share this post


Link to post
Share on other sites
Duh for me. hah. Sorry for the stupid topic hahahaha ;)
Thanks for the fast replies too :D

WitchLord, thanks for the tip, I'll give it a try right now...

Thanks again,
Luiz Ribeiro

Share this post


Link to post
Share on other sites
Hello... I have some more questions, can I post them here so I don't flood the topic list? heh
1st: Can I export a C++ enum or #define to AngelScript? Something like:

#define PI 3.14
enum { A, B, C, D ... }


And use these constants on AngelScript?

The second question is: how can I pass objects pointers as arguments to a AngelScript function? So I can pass a Particle object to an AngelScript void Update(Particle p) function (that will Update the particle properties via the pointer)... Using this instead returning a Particle object from the Update function (and getting a Particle as argument) can speed up the application? (it will execute many times by second, it's a particle engine)

I think that's it for now... Thanks ;)
Luiz Ribeiro

Share this post


Link to post
Share on other sites
A define, no. Change it to a const double or something similar, and you can register that value with AS..

As for the enum, I don't believe so, but it would be a nice feature.

Share this post


Link to post
Share on other sites
What about compiling my script? So I won't need to distribute my application with the scripts source codes, I will distribute the bytecode compiled script... Like the `luac` does...

Share this post


Link to post
Share on other sites
Angelscript can save compiled bytecode and load it again later. Just keep in mind that if your configuration changes, the saved bytecode becomes invalidated. Therefore, it is a good idea to work only with script source files during development, and switch to compiled bytecode after the engine is stabilized.

For defines, you can always use my Preprocessor addon. It's on the angelcode addon page. It will work, but defines are NOT the prefered solution for constants anymore. You could, however, have a script header that defines these constants, and use the preprocessor to #include it. Enumerations can be done with constants as well. Since enum members share the same scope as their enum-type-name in C++ (That is; the value of 'a' in enum foo { a = 0; }; is accessed with the identifier 'a', not 'foo::a'.) the results are exactly the same.

And for your final question; no. Pointers were removed from AngelScript as of 2.0, and replaced with Handles that behave like smart pointers. Autohandles remove almost all of the grunt work associated with using the handle mechanism. If speed is more of an issue than safety (which I suspect it would be in a particle engine) you can use pointers in the 1.10.1d distrobution. I'm not certain how much of a speed difference there is between pointers and handles. Handles insert a few extra calls to reference count management functions. I'm still using 1.10.1d myself; since players of my game can't access the scripts at all (It's all server side) safety is less of a concern for me.

Share this post


Link to post
Share on other sites
I tried the following to create a constant for the PI number:

float pi = float(M_PI);
engine->RegisterGlobalProperty("const float PI", &pi);


It works. But then it's not a constant on the engine and someone can edit it when working on the engine hehe... If I use const float pi = float(M_PI)... Walla! It doesn't work.

Isn't there anyway to simply:

engine->RegisterGlobalProperty("const float PI", float(M_PI));
// (converting to float since M_PI is a double)


Thanks again and sorry for the lots of questions,
Luiz Ribeiro

Share this post


Link to post
Share on other sites
Your second example: No. You are registering a temporary. That's bad, to say the least.

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!