Jump to content
  • Advertisement

FreeSlave

Member
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

108 Neutral

About FreeSlave

  • Rank
    Newbie
  1. FreeSlave

    QtScript vs AngelScript

    Since AngelScript was intended to use in some Qt project, I wrote this performance test to compare QtScript and AngelScript: https://bitbucket.org/FreeSlave/qtscript-vs-angelscript/overview On my machine (Intel(R) Core(TM)2 Duo CPU     E4600  @ 2.40GHz) Qt script runs 10 times faster (this is minimum, often the number is higher) than AngelScript using this test. The test itself is just multiplication of many random matrices 4x4. Matrices are represented by arrays (scriptarray add-on in case of AngelScript) in column-major form. Code looks equivalent for both scripts, except maybe for part where 'preresult' is assigned to 'result' variable, but I also tried to force to make copy of array in QtScript using slice(), which still did not reduce the distance much. I also compiled angelscript library with -O2, but it did not help. Maybe I missed something or scriptarray is not good enough. I expected better performance due to static typing.
  2. FreeSlave

    Get asIObjectType of built-in type

    Thanks, I think, I got it. I always should pass pointer to type, even if type itself is kind of pointer (like handle). This is logical. But I still need clarification about these cases: MyClass a; MyClass@ b; @b = a; and MyClass a; MyClass@ b; @b = @a; Is there some semantics difference?
  3. FreeSlave

    Get asIObjectType of built-in type

    Oh, comment in the example confused me. I mean this: // Registered with AngelScript as 'array<string> @CreateArrayOfString()' It made me think that pointer is already 'handle' because of '@' and that I don't need to pass reference to pointer, but just pointer.
  4. FreeSlave

    Get asIObjectType of built-in type

    Thanks, I missed manual somehow. But now I got segmentation fault if I register created array as  array<string>@ myArr but this works: array<string> myArr The full code snippet: #include <angelscript.h> #include "scriptstdstring/scriptstdstring.h" #include "scriptbuilder/scriptbuilder.h" #include "scriptarray/scriptarray.h" #include <cstdio> #include <string> #include <cassert> CScriptArray *CreateArrayOfStrings(asIScriptEngine* engine) { asIObjectType* t = engine->GetObjectTypeByDecl("array<string>"); assert(t); CScriptArray* arr = CScriptArray::Create(t, 3); assert(arr); for( asUINT i = 0; i < arr->GetSize(); i++ ) { std::string val("test"); arr->SetValue(i, &val); } return arr; } void writeln(const std::string &msg) { fprintf(stderr, "%s\n", msg.c_str()); } void MessageCallback(const asSMessageInfo *msg, void *param) { const char *type = "ERR "; if( msg->type == asMSGTYPE_WARNING ) type = "WARN"; else if( msg->type == asMSGTYPE_INFORMATION ) type = "INFO"; printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type, msg->message); } int main() { asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); int r = engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL); assert( r >= 0 ); RegisterStdString(engine); RegisterScriptArray(engine, true); r = engine->RegisterGlobalFunction("void writeln(const string &in)", asFUNCTION(writeln), asCALL_CDECL); assert( r >= 0 ); CScriptArray* myArr = CreateArrayOfStrings(engine); r = engine->RegisterGlobalProperty("array<string>@ myArr", myArr); assert(r >= 0); CScriptBuilder builder; r = builder.StartNewModule(engine, "MyModule"); if( r < 0 ) { printf("Unrecoverable error while starting a new module.\n"); return 1; } r = builder.AddSectionFromFile("test.as"); if( r < 0 ) { printf("Please correct the errors in the script and try again.\n"); return 1; } r = builder.BuildModule(); if( r < 0 ) { printf("Please correct the errors in the script and try again.\n"); return 1; } asIScriptModule *mod = engine->GetModule("MyModule"); asIScriptFunction *func = mod->GetFunctionByDecl("void main()"); if( func == 0 ) { printf("The script must have the function 'void main()'. Please add it and try again.\n"); return 1; } asIScriptContext *ctx = engine->CreateContext(); ctx->Prepare(func); r = ctx->Execute(); if( r != asEXECUTION_FINISHED ) { // The execution didn't complete as expected. Determine what happened. if( r == asEXECUTION_EXCEPTION ) { // An exception occurred, let the script writer know what happened so it can be corrected. printf("An exception '%s' occurred. Please correct the code and try again.\n", ctx->GetExceptionString()); } } ctx->Release(); myArr->Release(); engine->Release(); return 0; }  Script code: void main() { for( uint n = 0; n < myArr.length(); n++ ) writeln(myArr[n]); }   I got seg fault in asUINT CScriptArray::GetSize() const { return buffer->numElements; }  Is it intended behavior? . 
  5. FreeSlave

    Get asIObjectType of built-in type

    Hello, I'm new to angelscript library. I try to make such task as passing array from application to script using scriptarray add-on. So I suppose I need this  static CScriptArray *Create(asIObjectType *ot); to create array on application side. But I can't get asIObjectType for built-in types.   That's what I do (minimized example): #include <angelscript.h> #include <cstdio> int main() { asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); int intTypeId = engine->GetTypeIdByDecl("int"); if (intTypeId < 0) { printf("Type id is invalid\n"); } else { asIObjectType* intType = engine->GetObjectTypeById(intTypeId); if (!intType) { printf("Can't retrieve type\n"); } } engine->Release(); return 0; } While it can retrieve type id with GetTypeIdByDecl, but GetObjectTypeById returns null.  I use 2.29.0 version of angelscript.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!