tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorial [2009/09/16 03:00]
aspectscript
tutorial [2009/10/26 14:55] (current)
aspectscript
Line 1: Line 1:
 ====== Tutorial ====== ====== Tutorial ======
  
-Here, you can find a small tutorial of AspectScript.+===== Getting Started =====
  
-===== Getting Start =====+In order to be able to dynamically weave aspects without modifying a particular JavaScript engine, AspectScript first performs a code transformation phase in which some expressions are rewritten. This instrumentation can be performed in two ways. The first is easier, but less efficient (useful for development). The second is a little bit more complicated, but more efficient (choose this one for production code).
  
-To insert aspects, AspectScript instruments the code. This transformation can make it in two ways. The first is easier, but it is lesser efficient. The second is a little bit more complicated but it is more efficient.   +=== The easy way --- on-line transformation === 
-=== The easy way === + 
-This way is ideal when you are learning AspectScript or you are editing and testing the AspectScript code on-the-fly. To use the **easy way**you only have to include JavaScript script in the following way:+This option is ideal when you are learning AspectScript or you are developing code, because the code is transformed each time your Javascript script is loaded. For on-line tranformationit is only necessary to include the JavaScript source in the following way:
  
 <code html> <code html>
 <script language="javascript" src="jst.php?url=script.js"> </script> <script language="javascript" src="jst.php?url=script.js"> </script>
 </code> </code>
-Where the **jst.php**PHP file available in AspectScript, instruments the code+ 
-=== The efficient way === +Where the **jst.php** is the PHP file available in the standard distribution of AspectScript
-The previous solution is a little bit inefficient because AspectScript modifies the JavaScript code every time that the Web page is loadedYou can transform the JavaScript code once and then you only include the transformed scriptTo attain this, you have to execute the command:+ 
 +For instance[[http://www.pleiad.cl/aspectscript/external/tetris/tetris.js|this]] is the original tetris application, and the [[http://www.pleiad.cl/aspectscript/external/aspectscript/jst.php?url=http://www.pleiad.cl/aspectscript/external/tetris/tetris.js|transformed one]] using jst.php (it can take some time to load because the transformation is a heavy process, please click once). 
 + 
 +=== The efficient way - off-line transformation === 
 + 
 +On-line transformation is a little bit inefficient because the scripts are transformed each time they are requested (on every page load)As an altenative, Javascript scripts can be transformed once and then the transformed code included in pages The following commands performs this off-line transformation: 
 <code Bash> <code Bash>
-cat script.js | js -f 'launcher.js'newscript.js+cat script.js | js -f 'launcher.js'script-t.js
 </code> </code>
-and then, in the web page you include the new script+ 
 +And then, in the web page you include the transformed script
 <code html> <code html>
-<script language="javascript" src="newscript.js"> </script>+<script language="javascript" src="script-t.js"> </script>
 </code> </code>
  
-===== Define and Deploy Aspects ===== +The **launcher.js** script and the **js** executable are included in the standard AspectScript distribution. 
-The aspects of AspectScript are pointcut-advices pairsThe pointcuts and advices are JavaScript functions. For instance, if you need to identify all executions of the **foo** function.  + 
-<code JavaScript+===== Define and Deploy Aspects (Under Construction)===== 
-AspectScript.after(AspectScript.Pointcuts.exec(foo)function(jp) { + 
-        alert("foo was executed"); +The aspects of AspectScript are just a pointcut-advice pairPointcuts and advices are plain JavaScript functions. For instance, if you need to identify all executions of the **foo** function.  
-});+ 
 +<code java
 +var pointcut = AspectScript.Pointcuts.exec(foo)
 +var advice   function() { 
 + alert("Foo was executed"); 
 +}
 +AspectScript.after(pointcut, advice);
 </code> </code>
  
 ===== For More Information ===== ===== For More Information =====
-You want to learn more about AspectScript, you can see the [[examples|examples]] or reading the [[technical report|technical report]] + 
 +This page is still under construction.  Please see the [[examples|examples]] page if you want to learn more about AspectScript.
  
  
  • tutorial.1253080813.txt.gz
  • Last modified: 2009/09/25 13:01
  • (external edit)