Jump to content
  • Advertisement
Sign in to follow this  

Can t get it to work

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

      1 #include <iostream>
      2 #include <angelscript.h>
      3 using namespace std;
      5 void Print(float value)
      6 {
      7           cout<<value<<endl;
      8 }
     10 void MessageCallback(const asSMessageInfo *msg, void *param)
     11 {
     12           const char *type = "ERR ";
     13             if( msg->type == asMSGTYPE_WARNING )
     14                         type = "WARN";
     15                           else if( msg->type == asMSGTYPE_INFORMATION )
     16                                       type = "INFO";
     17                                         cout<<  msg->section<<msg->row<< msg->col<< type<< msg->message<<endl;
     18 }
     20 const char *szScript ="float globalval=0;void dosomething(){Print(globalvar);}";
     21 int main(int argc,char*argv[])
     22 {
     23         int i;
     24         asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
     26         i = engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL);
     27         assert(i>=0);
     30         i = engine->RegisterGlobalFunction("void Print(float)", asFUNCTION(Print), asCALL_CDECL);
     31         assert(i>=0);
     32         engine->AddScriptSection("test","start",szScript,56);
     33         engine->Build("test");
     35         // Do some preparation before execution
     36         asIScriptContext *context = engine->CreateContext();
     37         int functionID = engine->GetFunctionIDByDecl("test", "void dosomething()");
     39         // Execute the script function
     40         context->Prepare(functionID);
     41         context->Execute();
     43         // Release the context when finished with it
     44         context->Release();
     45         return 0;
     46 }

It doesn t let me set a callback in the first place and the rest doesn t work either basiror@linux:~> g++ -o template template.cpp -langelscript basiror@linux:~> ./template template: template.cpp:27: int main(int, char**): Assertion `i>=0' failed. Aborted basiror@linux:~> Any idea what I am doing wrong here? I am under Suse 10.0 x86_64 with an amd64 Compiling the lib with AS_MAX_PORTABILITY didn t work either [Edited by - Basiror on July 21, 2006 3:49:56 AM]

Share this post

Link to post
Share on other sites
Hmm, it should work. What version of AngelScript are you using? Have you retrieved the latest version from SVN?

All the tests, except saving and loading bytecode, in the test_feature project works for 64bit Linux with amd64. I've tested this on SourceForge.net's compile farm.

Perhaps you could debug your test sample to check the value of i? Or even go into the SetMessageCallback to see where it decides to return a negative value?

Share this post

Link to post
Share on other sites
I just fixed a bug in as_bytecode.cpp and checked in the new code in revision 49. You should be able to compile and use AngelScript on amd64 and Linux now.

There is a bug in the 64bit version of AngelScript though, I've not been able to locate the bug though as it is not consistent. Depending on the order of the individual tests in test_features some of the tests fail, but when I move the test that failed to the top (for easier debugging) it doesn't fail anymore. Even the saving and loading of bytecode works when executed as the first test.

I think it is memory related, in that in some situations the generated bytecode doesn't quite clean up the script stack as it should. I'll try to locate the bug by adding asserts that validates the stack frame pointer.

If you can find a situation that faithfully reproduce the problem I would be very grateful.


Share this post

Link to post
Share on other sites
Hi, thanx for taking the time to fix these bugs, unfortunately I found another once

gcc -g -Wall -o obj/as_callfunc.o -c ../../source/as_callfunc.cpp
../../source/as_callfunc.cpp: In function ‘int DetectCallingConvention(bool, const asUPtr&, int, asSSystemFunctionInterface*)’:
../../source/as_callfunc.cpp:69: error: cast from ‘void (*)()’ to ‘asDWORD’ loses precision
make: *** [obj/as_callfunc.o] Error 1

pointers have a size of 8 bytes
and int have a size of 4 bytes

just tested this on my machine

P.S.: Did you use a parser generator to write the language parser to did you use hand parsing?

Share this post

Link to post
Share on other sites
Ah, I fixed this yesterday in revision 50. Let me know if there are any other problems.

The parser is hand made. It's in as_parser.cpp if you're interested in looking at the code.

Share this post

Link to post
Share on other sites
I can run scripts now, but there s one further problem that I could not solve

I want to register a cfunction, see snippets underneath

9 void Prints(std::string &in)
10 {
11 cout << in<<endl;
12 }

41 i = engine->RegisterGlobalFunction("void Prints(string &in)",asFUNCTION(Prints),asCALL_GENERIC);

The script looks as follows:
float globalval=0;
string msg ="hallo";
void dosomething()

The message callback prints this
System function 1 13 ERR Identifier 'string' is not a data type
0 0 ERR Invalid configuration

Any idea what I am doing wrong here?

Btw is 2.7.0 == rev 50?

Share this post

Link to post
Share on other sites
AngelScript doesn't have a built-in string type. You must first register one. You can do this by calling the RegisterScriptString() function of the add-on script string (/add_on/scriptstring/scriptstring.cpp), or you can register your own string type.

Also, you need to use the correct calling convention when registering your functions. Your Prints() functions should use the calling convention asCALL_CDECL, or you need to rewrite the function to use the generic interface, i.e:

void Prints(asIScriptGeneric *gen)
std::string *in = (std::string*)gen->GetArgAddress(0);
cout << *in <<endl;

Since you're using amd64, then the generic calling convention is the only available, until I can add support for the native calling conventions.


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!