1 #include <iostream>
2 #include <angelscript.h>
3 using namespace std;
4
5 void Print(float value)
6 {
7 cout<<value<<endl;
8 }
9
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 }
19
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);
25
26 i = engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL);
27 assert(i>=0);
28
29
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");
34
35 // Do some preparation before execution
36 asIScriptContext *context = engine->CreateContext();
37 int functionID = engine->GetFunctionIDByDecl("test", "void dosomething()");
38
39 // Execute the script function
40 context->Prepare(functionID);
41 context->Execute();
42
43 // Release the context when finished with it
44 context->Release();
45 return 0;
46 }
Can t get it to work
http://www.8ung.at/basiror/theironcross.html
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?
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?
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 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.
Regards,
Andreas
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.
Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
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?
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?
http://www.8ung.at/basiror/theironcross.html
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.
The parser is hand made. It's in as_parser.cpp if you're interested in looking at the code.
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 can run scripts now, but there s one further problem that I could not solve
I want to register a cfunction, see snippets underneath
The script looks as follows:
float globalval=0;
string msg ="hallo";
void dosomething()
{
Prints(msg);
Print(globalval);
}
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?
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()
{
Prints(msg);
Print(globalval);
}
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?
http://www.8ung.at/basiror/theironcross.html
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:
Since you're using amd64, then the generic calling convention is the only available, until I can add support for the native calling conventions.
Regards,
Andreas
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.
Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement