List of Nasal extension functions: Difference between revisions

Jump to navigation Jump to search
m
Line 97: Line 97:


=== <tt>setprop()</tt> ===
=== <tt>setprop()</tt> ===
Sets a property value for a given node path string. Always returns nil.
Sets a property value for a given node path string. Returns 1 on success or 0 if the property could not be set (i.e. was read-only).


<syntaxhighlight lang="nasal">
<syntaxhighlight lang="nasal">
Line 103: Line 103:
</syntaxhighlight>
</syntaxhighlight>


All arguments but the last are concatenated to a path string, with a slash (/) inserted between each element. The last value is written to the respective node. If the node isn't writable, then an error message is printed to the console.
All arguments but the last are concatenated to a path string, like getprop() above. The last value is written to the respective node. If the node isn't writable, then an error message is printed to the console.
 
Note: <tt>setprop()</tt> concatenates a list of input arguments by means of inserting a "/" in between. That is nice for properties, as this slash is part of the tree. However, when one wants to make use of indices, like [0], one has to concatenate by hand (using "~") ''inside'' one part of the string argument list. An example is:
 
<syntaxhighlight lang="nasal">
var i = 4;
setprop("instrumentation","cdu","page["~i~"]","title","MENU");
</syntaxhighlight>
 
This results in instrumentation/cdu/page[4]/title = 'MENU' (string)


Examples:
Examples:
Line 121: Line 112:
</syntaxhighlight>
</syntaxhighlight>


'''Erasing a property from the property tree''': a property that has been created, for example through <tt>setprop()</tt> can be erased via
'''Erasing a property from the property tree''': a property that has been created, for example through <tt>setprop()</tt> has to be erased using the props namespace helper, like this:


<syntaxhighlight lang="nasal">
<syntaxhighlight lang="nasal">
props.globals.getNode("foo/bar").remove(); # take out the complete node
props.globals.getNode("foo/bar").remove(); # take out the complete node
props.globals.getNode("/foo").removeChild("bar"); # take out a certain child node
props.globals.getNode("foo").removeChild("bar"); # take out a certain child node
</syntaxhighlight>
</syntaxhighlight>


395

edits

Navigation menu