zola

Members
  • Content count

    45
  • Joined

  • Last visited

Community Reputation

122 Neutral

About zola

  • Rank
    Member
  1. RegisterObjectBehaviour assert

    [oh] Damn, You are good! I wish i had Your mindreading skills :) Of course, I totaly forgot about updating my custom tokendefs. Thanks a lot! Tom
  2. Hi I was using AS v. 1.10.1 WIP and have now upgraded to 1.10.1c. But now some registration code that used to work throws now an assert mzybe I'm still using something the wrong way? Compilation works just fine but when I run an assertion is issued at this line: r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_CONSTRUCT,"void initVector3(f32,f32,f32)",asFUNCTION4( Vector3Binding,void,initVector3,(f32,f32,f32,Vector3*) ),asCALL_CDECL_OBJLAST); assert( r >= 0 ); My Vector class has several constructors, overloaded operators, no destructor and many methods. Maybe someone can give me a hint what has changed between 1.10.1 WIP1 and 1.10.1c? Here's my registration code r=engine->RegisterObjectType("Vector3",sizeof(Vector3),asOBJ_CLASS_CA);assert(r>=0); r=engine->RegisterObjectProperty("Vector3","float x",offsetof(Vector3,x));assert(r>=0); r=engine->RegisterObjectProperty("Vector3","float y",offsetof(Vector3,y));assert(r>=0); r=engine->RegisterObjectProperty("Vector3","float z",offsetof(Vector3,z));assert(r>=0); ... r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_CONSTRUCT,"void initVector3()",asFUNCTION4( Vector3Binding,void,initVector3,(Vector3*) ),asCALL_CDECL_OBJLAST); assert( r >= 0 ); r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_CONSTRUCT,"void initVector3(f32,f32,f32)",asFUNCTION4( Vector3Binding,void,initVector3,(f32,f32,f32,Vector3*) ),asCALL_CDECL_OBJLAST); assert( r >= 0 ); r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_CONSTRUCT,"void initVector3(const Vector3&)",asFUNCTION4( Vector3Binding,void,initVector3,(const Vector3&,Vector3*) ),asCALL_CDECL_OBJLAST); assert( r >= 0 ); r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_ASSIGNMENT,"Vector3& copyVector3(Vector3& o)",asFUNCTION4( Vector3Binding,Vector3,copyVector3,(Vector3&,Vector3&)),asCALL_CDECL_OBJLAST); assert( r >= 0 ); r=engine->RegisterGlobalBehaviour(asBEHAVE_ADD,"Vector3 addVector3(const Vector3& left, const Vector3& right)",asFUNCTION4( Vector3Binding,Vector3,addVector3,(const Vector3&,const Vector3&) ),asCALL_CDECL); assert( r >= 0 ); r=engine->RegisterGlobalBehaviour(asBEHAVE_SUBTRACT,"Vector3 subVector3(const Vector3& left, const Vector3& right)",asFUNCTION4( Vector3Binding,Vector3,subVector3,(const Vector3&,const Vector3&) ),asCALL_CDECL);assert( r >= 0 ); Thanks Tom
  3. Context.Prepare

    Ok, thanks I just want to make sure I don't introduce overhead [wink]
  4. Context.Prepare

    Hi I'm currently trying to squeeze out performance from my app. I wonder if calling Prepare() is needed every time a script function is called or if its enough to call Prepare just once if I keep the context after the script returned? Regards Tom
  5. Pointers in AngelScript: Really necessary?

    As far as I'm concerned it only looks like a different notation. I only use pointers to pass values by reference from my app to the script I don't think it will be a big change for me.
  6. boolean operator xor

    Guess I'll have to switch to 1.10 then :)
  7. method defining

    No AngelScript can't do that. But You might implement a workaround. Some Python binding libraries use delegates do mimic class extensions. This method can also be used in AngelScript. Basically You extend the class in c++ and make wrappers for scripted function calls. Extending a class is then a matter of telling an instance of the wrapperclass which script functions to call. That's not quite the way you know from c++ but it works and you can change method implementation of an instance at runtime. Cheers Tom
  8. Script var byref

    Thanks.
  9. boolean operator xor

    Wow, thanks a lot man. It didn't work though :) I have now a compile error with this statement: // 'entity' and 'ud' are pointer to registered classes ... if(entity==0 || ud==0) return; compiler message: media/scripts/EditorUtilities.asc (40, 1) : Info : Compiling void UpdateEntity(IEntity*, CEditorUserData*) media/scripts/EditorUtilities.asc (42, 15) : Error : Illegal operation on this datatype media/scripts/EditorUtilities.asc (42, 20) : Error : '==' is not available for '<unrecognized token>' media/scripts/EditorUtilities.asc (42, 5) : Error : Expression must be of boolean type CScriptServerAngelScript::load() Build failed. [module: escape_utilities, file: media/scripts/EditorUtilities.asc] This didn't give errors before I did the changes. Nevermind, I can just as well exchange all occurances of XOR with != in the statements I want to check. Thanks Tom
  10. boolean operator xor

    Yeah [smile] But readability for unexperienced programmers goes down if you use != in a long boolean expression. I would have needed it for a little program where students can learn to convert logical expressions. It would have been nice to have an easy way to evaluate the resulting string. With anglescript executeString this would have been a peace of cake [cool] However I'll have to do the find and replace way then Cheers Tom
  11. boolean operator xor

    Hi a boolean xor / ^ would be convenient. Thanks
  12. Script var byref

    hi Is it correct that you can't define variables as references in a script function? i'd like to do the following: // script void changeMaterial(IEntity* e, UserData* ud) { Material& mat=e->getGraphicObject(0)->getMaterial(0); // ... } the script compilation bails out when it comes to the assignment of the material. I changed my code to return a pointer to a material and this works without any problem. So I just want to make sure this is an unsupported feature :) Cheers Tom
  13. Thanks for the link to the article. I feel that I should have at least a rudimentary knowledge about the approaches the various compilers take. Quote:Original post by WitchLord If I'm able to do what I want to do, the C++ compiler will be responsible for all this. The application will just get a function pointer from the context and call it with all parameters necessary. It will then be as easy to call script functions as functions dynamically loaded from a dll. Aye :) cheers to that! Even though the usage is quite easy today this should really give the last sceptic a reason to take a close look at angelscript. Keep up the good work. Tom
  14. Ah, ok I begin to understand, thanks. This is then the way to go: -- if I have a script function that returns a registered object I'll have to prepare the memory that will hold the data myself. Using ctx->SetArgument i tell the engine where to store the data. The return value must be in this case the first argument by convention. ( I assume in C++ the compiler does this for me then :) what about the case when i don't use the return value of a function? does the c compiler allocate room for the return value too? I'm just curious.) -- if I have a script function that returns basetypes I get them with ctx->GetReturnValue, because the return value can be stored in some register no memory must be provided. I don't know if this is a correct explanation, just guessing here, I'm not a compiler guy ;) Anyway what You suggested works just fine, thanks again. Cheers Tom
  15. Yep Your method works :) But I did not give You my complete setup. Here's a test that doesn't work #include "utils.h" #include <math.h> #include <new> #define TESTNAME "TestVector3" #define asFUNCTION4(c,r,f,p) asFunctionPtr((asFUNCTION_t)( (r(*)p)c::f) ) class Vector3 { public: inline Vector3() {} inline Vector3( float fX, float fY, float fZ ) : x( fX ), y( fY ), z( fZ ) {} inline Vector3(const Vector3& other){ x=other.x; y=other.y; z=other.z; } float x,y,z; // asBEHAVE_CONSTRUCT static void initVector3(Vector3* me); // asBEHAVE_CONSTRUCT static void initVector3(float x, float y, float z, Vector3* me); // asBEHAVE_CONSTRUCT static void initVector3(const Vector3& other, Vector3* me); // asBEHAVE_DESTRUCT static void destroyVector3(Vector3* me); // asBEHAVE_ASSIGNMENT static Vector3& copyVector3(Vector3& left, Vector3& right); }; // asBEHAVE_CONSTRUCT void Vector3::initVector3(Vector3* me) { new(me) Vector3(0,0,0); } // asBEHAVE_CONSTRUCT void Vector3::initVector3(float x, float y, float z, Vector3* me) { new(me) Vector3(x,y,z); } // asBEHAVE_CONSTRUCT void Vector3::initVector3(const Vector3& other, Vector3* me) { new(me) Vector3(other); } // asBEHAVE_DESTRUCT void Vector3::destroyVector3(Vector3* me) { me->~Vector3(); } // asBEHAVE_ASSIGNMENT Vector3& Vector3::copyVector3(Vector3& other, Vector3& me) { me=other; return me; } static char *script = "Vector3 TestVector3() \n" "{ \n" " Vector3 v; \n" " v.x=1; \n" " v.y=2; \n" " v.z=3; \n" " return v; \n" "} \n"; bool TestVector3() { bool fail = false; int r; asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); r = engine->RegisterObjectType("Vector3",sizeof(Vector3),asOBJ_CLASS_CDA);assert(r>=0); r = engine->RegisterObjectProperty("Vector3","float x",offsetof(Vector3,x));assert(r>=0); r = engine->RegisterObjectProperty("Vector3","float y",offsetof(Vector3,y));assert(r>=0); r = engine->RegisterObjectProperty("Vector3","float z",offsetof(Vector3,z));assert(r>=0); r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_CONSTRUCT,"void initVector3()",asFUNCTION4( Vector3,void,initVector3,(Vector3*) ),asCALL_CDECL_OBJLAST); assert( r >= 0 ); r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_CONSTRUCT,"void initVector3(float,float,float)",asFUNCTION4( Vector3,void,initVector3,(float,float,float,Vector3*) ),asCALL_CDECL_OBJLAST); assert( r >= 0 ); r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_CONSTRUCT,"void initVector3(const Vector3&)",asFUNCTION4( Vector3,void,initVector3,(const Vector3&,Vector3*) ),asCALL_CDECL_OBJLAST); assert( r >= 0 ); r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_DESTRUCT,"void destroyVector3()",asFUNCTION4( Vector3,void,destroyVector3,(Vector3*) ),asCALL_CDECL_OBJLAST); assert( r >= 0 ); r=engine->RegisterObjectBehaviour("Vector3",asBEHAVE_ASSIGNMENT,"Vector3& copyVector3(Vector3& o)",asFUNCTION4( Vector3,Vector3,copyVector3,(Vector3&,Vector3&)),asCALL_CDECL_OBJLAST); assert( r >= 0 ); Vector3 v; engine->RegisterGlobalProperty("Vector3 v", &v); COutStream out; engine->AddScriptSection(0, TESTNAME, script, strlen(script)); r = engine->Build(0, &out); asIScriptContext *ctx = 0; r = engine->CreateContext(&ctx); int funcID = engine->GetFunctionIDByDecl(0,"Vector3 TestVector3()"); ctx->Prepare(funcID); ctx->Execute(); r=ctx->GetReturnValue((asDWORD*)&v,int(ceil(sizeof(v)/4.0))); engine->Release(); return fail; } It bails out when the constructor is called. So I guess I'm doing something complete wrong here. Btw the error does not occure if I use the ExecuteString method your using in the tests. Maybe You see where my missconception is. Thanks for Your time Tom