getVariable VS. getZScriptVariable"

From Documentation
m (Created page with '{{ZKDevelopersGuidePageHeader}} Variables defined in the namespace can be retrieved by use of the <tt>getVariable</tt> method. On the other hand, variables defined in <tt>zscri…')
 
m (correct highlight (via JWB))
 
Line 1: Line 1:
 
{{ZKDevelopersGuidePageHeader}}
 
{{ZKDevelopersGuidePageHeader}}
  
Variables defined in the namespace can be retrieved by use of the <tt>getVariable</tt> method.
+
Variables defined in the namespace can be retrieved by use of the <code>getVariable</code> method.
  
On the other hand, variables defined in <tt>zscript</tt> is part of the interpret that interprets it. They are ''not'' a part of any namespace. In other words, you can ''not'' retrieve them by use of the <tt>getVariable</tt> method.
+
On the other hand, variables defined in <code>zscript</code> is part of the interpret that interprets it. They are ''not'' a part of any namespace. In other words, you can ''not'' retrieve them by use of the <code>getVariable</code> method.
  
 
<source lang="xml" >
 
<source lang="xml" >
Line 12: Line 12:
 
</source>
 
</source>
  
Instead, you have to use <tt>getZScriptVariable</tt> to retrieve variables defined in <tt>zscript</tt>. Similarly, you can use <tt>getZScriptClass</tt> to retrieve classes and <tt>getZScriptFunction</tt> to retrieve methods defined in <tt>zscript</tt>. These methods will iterate through all loaded interpreters until the specified one is found.
+
Instead, you have to use <code>getZScriptVariable</code> to retrieve variables defined in <code>zscript</code>. Similarly, you can use <code>getZScriptClass</code> to retrieve classes and <code>getZScriptFunction</code> to retrieve methods defined in <code>zscript</code>. These methods will iterate through all loaded interpreters until the specified one is found.
  
If you want to search a particular interpreter, you can use the <tt>getInterpreter</tt> method to retrieve the interpreter first, as follows.
+
If you want to search a particular interpreter, you can use the <code>getInterpreter</code> method to retrieve the interpreter first, as follows.
  
 
<source lang="java" >
 
<source lang="java" >

Latest revision as of 10:41, 19 January 2022

getVariable VS. getZScriptVariable


Stop.png This documentation is for an older version of ZK. For the latest one, please click here.


Variables defined in the namespace can be retrieved by use of the getVariable method.

On the other hand, variables defined in zscript is part of the interpret that interprets it. They are not a part of any namespace. In other words, you can not retrieve them by use of the getVariable method.

<zscript>
     var1 = 123; //var1 belongs to the interpreter, not any namespace
     page.getVariable("var1"); //returns null
</zscript>

Instead, you have to use getZScriptVariable to retrieve variables defined in zscript. Similarly, you can use getZScriptClass to retrieve classes and getZScriptFunction to retrieve methods defined in zscript. These methods will iterate through all loaded interpreters until the specified one is found.

If you want to search a particular interpreter, you can use the getInterpreter method to retrieve the interpreter first, as follows.

page.getInterpreter("JavaScript").getVariable("some"); //interpreter for JavaScript
page.getInterpreter(null).getVariable("some"); //interpreter for default language



Last Update : 2022/01/19

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.