Update of /cvsroot/net-script/netscript2/src/scripts
In directory sc8-pr-cvs1:/tmp/cvs-serv6624
Added Files:
allfeatures.xml
Log Message:
--- NEW FILE: allfeatures.xml ---
<?xml version="1.0"?>
<!-- This Script tests all main features of the implementation of NetScript -->
<html xmlns:ns="http://netscript.insomnia-hq.de">
<head>
<title>NetScript - All features Test</title>
</head>
<body>
<h1>NetScript - All features Test</h1>
Lets test some builtin functions:
5 + 5 = $(eval[5+5]) <br/>
Interpreter is at: $(SYS.interpreterURL) <br/>
This Script is at: $(SYS.scriptURL)<br/>
url[../../test.xml] is $(url[../../test.xml]) <br/>
<ns:var name="x" val="5"/>
I created a variable named x. Its value is $(x). <br />
<ns:for name="i" from="1" to="$(x)" step="1">
This should stand here for $(x) times.<br />
</ns:for>
<hr />
Now i'm defining a class.<br />
<ns:class name="Car">
<ns:member name="color"/>
<ns:member name="wheels"/>
<ns:method name="INIT">
<ns:var var="this.color" val="blue"/>
<ns:var var="this.wheels" val="4"/>
</ns:method>
<ns:method name="oneLessWheel">
<ns:var var="this.wheels" val="$(eval[$(this.wheels)-1])"/>
</ns:method>
<ns:method name="getWheels" byRef="wheels">
<ns:var var="wheels" val="$(this.wheels)"/>
</ns:method>
<ns:method name="setColor" byVal="color">
<ns:var var="this.color" val="$(color)"/>
</ns:method>
<ns:method name="getColor" byRef="color">
<ns:var var="color" val="$(this.color)"/>
</ns:method>
<ns:method name="printXTimes" byVal="times">
<ns:for name="x" from="1" to="$(times)" step="1">
<ns:invoke var="this" method="printYourself"/> <br/>
</ns:for>
</ns:method>
<ns:method name="printXTimesRecursive" byVal="times">
<ns:invoke var="this" method="printYourself"/> <br />
<ns:if test="$(times) > 1">
<ns:invoke var="this" method="printXTimesRecursive" times="$(eval[$(times)-1])"/>
</ns:if>
</ns:method>
<ns:method name="printYourself">
I am a $(this.color) car on $(this.wheels) wheels!
</ns:method>
</ns:class>
The class is defined so i can create an object of it.<br />
<ns:new name="aCar" class="Car"/>
In the Ctor the cars color is set to blue. lets check this: <br />
<ns:invoke var="aCar" method="printYourself"/> <br />
I'm setting the color of the car to red. <br />
<ns:invoke var="aCar" method="setColor" color="red"/>
<ns:invoke var="aCar" method="printYourself"/> <br />
Now let's check call by reference. Im creating a variable y.
<ns:var name="y" val="green"/> Its value is $(y).<br />
Now i invoke getColor on our car. <br />
<ns:invoke var="aCar" method="getColor" color="y"/>
y is now $(y). <br />
Now a quiet heavy test. A for loop in a method, which is calling another method.
We print the car 5 times.<br />
<ns:invoke var="aCar" method="printXTimes" times="5"/><br/>
Now lets do the same with a recursive implementation. <br />
<ns:invoke var="aCar" method="printXTimesRecursive" times="5"/> <br />
Now we remove two wheels off the car.<br/>
<ns:var name="carswheels" val="0"/>
<ns:invoke var="aCar" method="getWheels" wheels="carswheels"/>
<ns:while test="$(carswheels) > 2">
<ns:invoke var="aCar" method="oneLessWheel"/>
<ns:invoke var="aCar" method="getWheels" wheels="carswheels"/>
<ns:invoke var="aCar" method="printYourself"/><br/>
</ns:while>
That's it. We are finished.
</body>
</html>
|