Understanding POL source

Archive of posts related to former distro versions. Be aware that posts here do not refer to the current distro and may not work.

Moderators: POL Developer, Distro Developer

Locked
bodom
POL Developer
Posts: 136
Joined: Sat Feb 21, 2015 7:52 pm
Location: Italy

Understanding POL source

Post by bodom » Tue Oct 27, 2015 11:27 am

Hey,

I am still trying to understand POL source code. I have found this:

Code: Select all

   bool NPC::send_event( Bscript::BObjectImp* event )
	{
	  if (ex != NULL)
	  {
		if (ex->os_module->signal_event( event ))
		  return true;
	  }
	  Bscript::BObject bo( event );
	  return false;
	}
Basically, if the NPC has an AI (ex != NULL) the event is sent to the script and true is returned. If not, false is returned but what "Bscript::BObject bo( event )" does?

Turley
POL Developer
Posts: 645
Joined: Sun Feb 05, 2006 4:45 am

Re: Understanding POL source

Post by Turley » Fri Oct 30, 2015 11:41 pm

Not really sure, since I didn't looked into calling code.
It looks like that the event parameter is an owing pointer, thus the function needs to transfer the ownership or destroy the pointer. Otherwise it would result in a memory leak.
The creation of the bobject is just for that purpose destroying the pointer, if you look at the deconstructor you should see a delete.

bodom
POL Developer
Posts: 136
Joined: Sat Feb 21, 2015 7:52 pm
Location: Italy

Re: Understanding POL source

Post by bodom » Sat Oct 31, 2015 1:03 pm

Thank you for your answer!

It sounds complicated to me, but I think I've understood it :D

Code: Select all

BObject::~BObject()
	{}
Anyway, BObject's deconstructor seems to be empty.

That's weird, because I am trying to debug a trace that leads me exactly there.

Locked