changing func to different func in middle of execution safe?

Discuss any general programming issues here

changing func to different func in middle of execution safe?

Postby Bugala » Thu Jun 15, 2017 4:35 pm

I am asking about Hollywoods innerworks about how this works to know if i can do this way.

I tried these two and they seem to work fine, but question is, is this safe thing to do or should i make temporal copy of the function that gets replaced or something to make sure it works right?


Code: Select all
Function customfunc_1()
  functable.func = customfunc_2
  DebugPrint("func_1")
EndFunction

Function customfunc_2()
  DebugPrint("func_2")
EndFunction


functable = {}
functable.func = customfunc_1

functable.func()


results in "Func_1" being printed as it should (notice that functable.func that is being executed is being replaced with func_2 before debugprint in customfunction_1 is executed)


Another test:
Code: Select all
Function customfunc_1()
  subfunc()
  DebugPrint("func_1")
EndFunction

Function customfunc_2()
  DebugPrint("func_2")
EndFunction

Function subfunc()
   functable.func = customfunc_2
EndFunction

functable = {}
functable.func = customfunc_1

functable.func()


Almost same as last one, but this time I am using subfunc to do the changing of the function. What worries me is that customfunc_1 jumps to subfunc, which replaces functable.func (that is right at that moment being executed) into customfunc_2 and after this is done, it returns from subfunc back to functable.func, but does it always return to the customfunc_1 execution (that have already been replaced) or might it in some case return to the new function.func, which would now be customfunc_2, and would it even know where there to return to?
Bugala
 
Posts: 642
Joined: Sun Feb 14, 2010 8:11 pm

Re: changing func to different func in middle of execution s

Postby airsoftsoftwair » Fri Jun 16, 2017 11:06 am

Sure, this is safe. You don't have to worry about that, once you jump into a function the VM will take care of everything else.
User avatar
airsoftsoftwair
 
Posts: 2202
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Re: changing func to different func in middle of execution s

Postby Bugala » Fri Jun 16, 2017 2:02 pm

Good. Didnt dare to start using those before getting confirmation from you, or it might have meant that when new Hollywood version would hit the street, it could suddenly stop working.
Bugala
 
Posts: 642
Joined: Sun Feb 14, 2010 8:11 pm


Return to General programming

Who is online

Users browsing this forum: No registered users and 1 guest