L3DT development blog
Large 3D terrain generator

ZeoScript compiler

Hi Everyone,

In the latest build of L3DT Pro (v2.8 build 2, 10th of Dec '09), the ZeoScript plugin has been updated to use a just-in-time (JIT) compiler. The effect of this compiler is to increase the speed of loops in ZeoScript, and that it has achieved. Map calculations in ZeoScript should now run at least 5x faster than before.

Syntax changes

Users should also be aware that the syntax of the ZeoScript language has been revised for greater clarity and ease of use. I have updated the example scripts provided with the new installer, but if you use custom scripts, you may need to modify them to work with the new release. Below I have included a listing of all the major syntax changes:

Nested function calls

Function nesting, whereby one function's return value is fed into the argument list of another, was previously achieved using the <zs:ScriptText> operator. Now, the 'zs:' component is redundant, so nested functions are denoted simply by the < and > braces.

The examples below show the old and new way of calling nested functions. Here, the values of c and d are added together, then multiplied by b, and finally a is assigned the resultant value:

Old set a <zs:mul b <zs:add c d> >
New set a <mul b <add c d> >

By removing the 'zs:' component, the purpose of the code becomes more obvious, and this should make the language both easier to use and learn.

Accessing maps, file formats and global variables

Previously, to retrieve a map from the L3DT map project, one used the <m:MapName> operator. This special operator has been replaced by the 'GetMap' function, which otherwise behaves in much the same fashion, as shown below:

Old map.GetWidth <m:HF>
New map.GetWidth <GetMap “HF”>

Similarly, the <f:MapName MapType FileExt> operator for retrieving file format handlers was replaced by the 'GetFormat' function, and the <v:VarName> operator for retrieving global variables was replaced by the 'GetVar' function.

Casting variable types

To cast a variable value from one type or another, it was necessary to use the <cast:type var> operator. This has been replaced by a 'cast' function, but as it happens, the resulting syntax is almost identical:

Old echo <cast:float i>
New echo <cast float i>

[note that the ':' is no longer necessary]

Pointer referencing and dereferencing

In previous versions of ZeoScript, the interpreter would automatically reference variables and dereference pointers as required. In the new version, users now have responsibility to manage pointers, just as with C/C++.

As an example, the code below shows the use of the function 'EditUI' which takes two arguments, the first of which is a pointer to a variable (a hvar), and the second is a string. In the new compiler, you must manually reference the variable using the & operator to get the hvar, like so:

int i
EditUI &i "Enter integer" // edit i (using & to get handle)

In the old interpreter, you could pass any variable in as the first argument, and the interpreter would automatically reference the variable to get the hvar:

int i
EditUI i "Enter integer"

By disabling automatic referencing/dereferencing, I hope to make it more obvious whether fucntion arguments are being passed by value or by reference. However, this behaviour may be more difficult to learn for scripters not familiar with pointers. Consequently, many examples are provided.

elseif

In addition to the 'if', 'else' and 'endif' statements, I have now added an 'elseif' statement to permit neater if/else chains.

For example, the following code prints a different message depending on the value of an integer i.

if <isgt i 10>
  echo "i is greater than 10"
elseif <isgt i 5>
  echo "i is greater than 5 but less than or equal to 10"
else
  echo "i is less than or equal to 5"
endif

In the old interpreter, the 'elseif' used above could only be achieved by nesting an if statement within an else statement, like so:

if <isgt i 10>
  echo "i is greater than 10"
else
  if <isgt i 5> // nested if in else, instead of an elseif
    echo "i is greater than 5 but less than or equal to 10"
  else
    echo "i is less than or equal to 5"
  endif
endif

By permitting 'elseif', we save on some unnecessary nesting, and simply the structure of the if/else chain.

Future changes

Any further development of ZeoScript will be focussed on improving the execution speed of the runtime engine, and extending the range of functions and features available. I do not anticipate making any any further changes to the syntax of the language, as I feel ZeoScript now meets its requirements with a minimum of fuss. Hence, scripts written for this new ZeoScript plugin should continue to work indefinitely with future releases of L3DT (that's the plan, anyhow.)

Documentation

I have not yet updated the examples or reference pages for ZeoScript, as those pages represent the state of ZeoScript in the current release-version of L3DT. These pages will be updated for the next release, which will likely be v2.8a, in the near-ish future.

In lieu of updated documentation, I have updated all the scripts included with the installer, which provide examples for most of the scripting features. However, if you require additional information or help, please feel free to ask in the plugins and scripts forum.

Best regards, Aaron.

 
l3dt/2009/dec/11.txt · Last modified: 2017/08/31 05:29 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Share Alike 3.0 Unported
L3DT Development Blog RSS Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki