(I tried my best in making this follow-able and readable, but I tend to be bad at explaining, so please ask if something is unclear)
Globals
When are global variables reset? Do they last till the server is restarted? Are they affected by some kind of Garbage Collection?
Types
Every uninitialized variable appears to be a TGraalVar according to
.objecttype(), why is that?
References
What is passed by reference and what is passed by value? What can store a reference? How does
.link() affect that?
To elaborate:
PHP Code:
function onCreated()
{
test( "x" );
temp.x = this.list.x;
temp.p = 5;
send( "temp.p / objecttype: " @ temp.p.objecttype() @ " / type: " @ temp.p.type() @ " / tostring: " @ temp.p @ " / is null: " @ ( temp.p == null ) );
send( "temp.x / objecttype: " @ temp.x.objecttype() @ " / type: " @ temp.x.type() @ " / tostring: " @ temp.x @ " / is null: " @ ( temp.x == null ) );
send( "temp.x.text / objecttype: " @ temp.x.text.objecttype() @ " / type: " @ temp.x.text.type() @ " / tostring: " @ temp.x.text @ " / is null: " @ ( temp.x.text == null ) );
send( "this.list.x / objecttype: " @ this.list.x.objecttype() @ " / type: " @ this.list.x.type() @ " / tostring: " @ this.list.x @ " / is null: " @ ( this.list.x == null ) );
send( "this.list.x.text / objecttype: " @ this.list.x.text.objecttype() @ " / type: " @ this.list.x.text.type() @ " / tostring: " @ this.list.x.text @ " / is null: " @ ( this.list.x.text == null ) );
}
function test(a)
{
this.list.(@ a).text = "b";
return this.list.(@ a);
}
send being just a simple function that PMs the given string. gets a result of:
PHP Code:
name objecttype type tostring isnull
temp.p TGraalVar 0 "5" 0
temp.x TGraalVar 0 "0" 1
temp.x.text TGraalVar -1 "" 1
this.list TGraalVar -1 "" 1
this.list.x TGraalVar -1 "" 1
this.list.x.text TGraalVar 1 "b" 0
Why is
temp.x a numeric type and becomes "0", while at the same time being null, even though it supposedly is a reference to
this.list.x?
Why can't temp.x.text access
this.list.x.text? is that because this.list.x is null, thus doing
temp.x = this.list.x; you set temp.x to null and not to a reference of an object that would look like
{ text: "b" } in JSON?
Is there any way to return such a reference? I might be able to return a string and
makevar that or such... not sure if that would be of any help and I think i would have to makevar for each subvariable of
this.list.x /
temp.x I would try to access?
One way I seemingly found to do something is to do:
PHP Code:
temp.x = this.list.x.link();
Which then makes that one result:
PHP Code:
name objecttype type tostring isnull
temp.x.text TGraalVar 1 "b" 0
However, doing that also appears to mean that if i do
temp.x.text = "a"; it won't change this.list.x.text, and I'm unaware how .link() acts here since the only documentation that describes its funcationality seems to say it is used in order to make sure arrays are passed without having their values copied.
Another way I found was to make
this.list.x a TStaticVar, which would then allow
temp.x to be non-null and
temp.x.text to access
this.list.x.text.
Which also leads to another question:
Is there a computational difference (storage, processing cost) between TStaticVar and TGraalVar aside the ability to destroy StaticVars?
I've heard StaticVar's without reference are cleaned up by GC at some point, but it still being advised to destroy them manually if you can.
When are TGraalVars collected? Immediately when they lack any reference? Or on a GC cycle too?
If the latter, wouldn't it be better to use TStaticVar wherever possible?