The pre-compiled 2014.10.13 version of the DWScript WebServer is now available!
This version includes the Pascal to JavaScript CodeGen!
Here is the download link for the installer:
DWSWebServer 2014.10.13 [1] (1541 kB)
This version also includes all fixes and improvements in DWScript, but the main attraction is the Pascal to JavaScript compiler, which bundles a limited version of SmartMobile Studio [2] compiler. It can be invoked in two ways:
- inline in a “.dws” file, through the use of a <script type=”pascal”> section, which will be compiled to a <script type=”javascript”> section
- as a library, through a “.p2js” file, which will be compiled and served as a “.js” file would be
There is only one sample currently, “op4js.dws”, which is a minimalistic illustration of both script execution contexts:
<html><body> <h3 style="color:blue">Hello OP4JS!</h3> <div id="count">???</div> <?pas // executed server-side when generating page var i : Integer; for i := 1 to 5 do PrintLn(Format('Test %d<br/>', [i])); ?> <script type="pascal"> // compiled into javascript var doc external "document", win external "window" : Variant; var counter : Integer; procedure IncrementCounter; begin var countDiv := doc.getElementById('count'); countDiv.innerHTML := IntToStr(counter); Inc(counter); win.setTimeout(@IncrementCounter, 1000); end; IncrementCounter; </script> </body></html>
it gets compiled into
<html><body>
<h3 style="color:blue">Hello OP4JS!</h3>
<div id="count">???</div>
Test 1<br/>
Test 2<br/>
Test 3<br/>
Test 4<br/>
Test 5<br/>
<script>
function IncrementCounter() {
var countDiv;
countDiv = document.getElementById("count");
countDiv.innerHTML = counter.toString();
++counter;
window.setTimeout(IncrementCounter,1000);
};
var counter = 0;
IncrementCounter()
</script>
</body></html>
Future posts will introduce more advanced usage scenarios!