How does "persistentref" work?

Discussion of Inner Space

Moderators: Lavish Software Team, Moderators

Post Reply
mistahmikey
GamingTools Subscriber
Posts: 29
Joined: Wed Jun 30, 2010 7:48 am

How does "persistentref" work?

Post by mistahmikey » Sun Oct 27, 2013 9:45 am

When I saw this in the release notes, I thought this type might provide a way to create an alias for an object:

variable SomeObject object
variable persistentref objectAlias

objectAlias:SetReference[object]

so if, say, SomeObject has a Name member, I could write:

objectAlias.Name or
objectAlias.Reference.Name

However, neither of these work. If I echo ${objectAlias} or ${objectAlias.Reference}, they both print NULL.

So, since neither the release notes or wiki describe the semantics of this type, could someone provide an more detailed explanation ?

Lax
Owner
Posts: 6634
Joined: Fri Jun 18, 2004 6:08 pm

Post by Lax » Mon Oct 28, 2013 12:10 pm

I'd say you understand the intent. There was a few bugs with the "persistentref" object type which I took care of this morning in IS dev build 5929. Additionally, LavishScript-internal object types (including script-defined object types) were not marked as persistent and could not be used with persistentref.

As of this update:

Code: Select all

  * Fixed bugs with 'persistentref' object type
  * Marked LavishScript internal types as persistent: 
    - scriptobject (all script-defined object types), variablescope, script, query, event, 
	  container, index, collection, stack, queue, set

And some code I used for testing:

Code: Select all

objectdef someObject
{
	member SomeValue()
	{
		return "someObject's SomeValue"
	}

	variable collection:int intCollection
}

function main()
{
	variable someObject SomeObject 
	variable persistentref objectAlias 

	echo SetReference result=${objectAlias:SetReference[SomeObject.intCollection](exists)}

	objectAlias:Set[one,2]
	echo ${objectAlias[one]}
}
The SomeValue member is leftover from initial tests where I used :SetReference[SomeObject] and echoed ${objectAlias.SomeValue}

Your example should now work fine, as long as you're on the development build of Inner Space. This build should be going live within a couple weeks (noting that it now requires Visual Studio 2013 to build an IS extension or LS module, and Visual Studio 2013's "launch" isn't until Nov 13 though it is already available for download from MS)

I'll also mention that once you've set a persistentref object's Reference, you can copy the reference by setting a new persistentref to the original persistentref. Example...

Code: Select all

	variable persistentref objectAlias2
objectAlias2:SetReference[objectAlias1]
This causes objectAlias2 to point to objectAlias1's reference, it does NOT point it at the objectAlias1 object itself. (This is an important distinction to make, because objectAlias1:SetReference[xyz] after setting objectAlias2, would affect both references if 2 really pointed back to 1.)

This also means that persistentref can safely be used as a parameter to a function, and you can pass in a persistentref OR the original object to fill it.

Post Reply