Jump to content
  • Advertisement

Budskii

Member
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

149 Neutral

About Budskii

  • Rank
    Newbie
  1. Budskii

    Difference between object handles/references

    Ah okay thanks. I was using SetArgObject(), that would explain the increment of ref counter. I've switched it to SetArgAddress and it works fine now
  2. Budskii

    Difference between object handles/references

    Actually, script not calling ReleaseRef() might be an error from my part, doing some more testing, will update post   EDIT: it appears the script calls AddRef() and also ReleaseRef() when it is called from C++ that would explain why from my earlier test memory was never freed and so I thought ReleaseRef() wasn't called.   Create object in C++ (ref=1) -> call script function (ref += 1 -> ref = 2) -> finish script function (ref -=1 -> ref = 1)   I'd have to initliase the object with ref=0 from C++ and then that way it would delete in script, but it is supposed to be initliased to ref=1
  3. Budskii

    Difference between object handles/references

    Earlier I said "I'm assuming refCount is supposed to be reduced by the function caller and not the function called?" I decided to test this out in a script, I added logging AddRef() ReleaseRef() and Constructor functions in the CTimer class   I tested it with this script: void main() { CTimer Timer; Timer.start(); Sleep(50); Timer.stop(); Print("Stopped timer\n"); CTimer@ timer_handle = @Timer; PrintElapsedTime(timer_handle); Print("Returned to main()\n"); } void PrintElapsedTime(CTimer@ timer) { Print("PrintElapsedTime() called\n"); Print("Time elapsed: " + timer.milliseconds() + "\n"); }   As you can see ReleaseRef() was called in PrintElapsedTime() for then handle passed in parameter   But this doesn't happen when you call a script function which takes in a handle as parameter from C++ application
  4. Budskii

    Difference between object handles/references

      Thank you for the reply.   I registered a callback like this: r = scriptEngine->RegisterFuncdef("void CTimerCallback(CTimer@)"); In a script I made this function: void DoRandomStuff(CTimer@ timer) { Print("Well this is great\n"); } I made a new CTimer in C++ and initliazed its refCount to 1 and then called DoRandomStuff() from C++ but this did not reduce the refCount. I'm assuming refCount is supposed to be reduced by the function caller and not the function called?   This will be a bit more work I guess, you would have to call C++ script functions and after it is done executing releaseRef() yourself manually   Also, a question regarding this script; CTimer timer; CTimer@ timer_handle = @timer; void DoRandomStuff(CTimer@ timer) { Print("Well this is great\n"); }   that all makes sense, but if you need to pass that handle (timer_handle) which was declared to be  a handle onto another function do you need to use @?   so should it be: DoRandomStuff(timer_handle); or DoRandomStuff(@timer_handle); They both work and script runs fine but I'm wondering if there is any different between the two?
  5. Ok, so I've just start using Angelscript recently and absolutely love it. Have a question on something i'm confused about   I've registered an object like this:   r = scriptEngine->RegisterObjectType("CTimer", 0, asOBJ_REF); assert( r >= 0 ); r = scriptEngine->RegisterObjectBehaviour("CTimer", asBEHAVE_ADDREF, "void f()", asMETHOD(CTimer, AddRef), asCALL_THISCALL); assert( r >= 0 ); r = scriptEngine->RegisterObjectBehaviour("CTimer", asBEHAVE_RELEASE, "void f()", asMETHOD(CTimer, ReleaseRef), asCALL_THISCALL); assert( r >= 0 ); r = scriptEngine->RegisterObjectBehaviour("CTimer", asBEHAVE_FACTORY, "CTimer@ f()", asFUNCTION(Scr_CTimer_Factory), asCALL_CDECL); assert( r >= 0 );   I can't seem to find anything in documentation or forums about the differences between references and object handles. From what I understand from a C++/memory perspective is that they are both pointers. I also understand that a reference cannot be null and a object handle can be. Apart from that what is the difference between them say when i'm using CTimer object.   I've switched all the &'s to @ and everything works just fine. 
  6. Budskii

    AngelScript 2.31.0 is finally out

    Edit: Nvm silly error from my part
  7. Budskii

    AngelScript 2.31.0 is finally out

    Edit: Nvm silly error from my part   Thanks for the release works just fine!
  • 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!