1. Index of TkScript » Introduction
  2. Index of TkScript » Introduction » About TkScript
About TkScript

a short overview of the TkScript language

Table of Contents:

1. Abstract
TKS (TkScript) is a portable "glue" script language for C++ frameworks.
  • The script engine itself is distributed under terms of the GNU General Public License (GPL)
  • The YAC plugin SDK uses the GNU Lesser General Public License (LGPL) and 3rd party plugins may use any license they want to.
    • All of the currently available plugins use either the LGPL (e.g. tksdl, tkopengl, tkui, ..) or the MIT license (e.g. →tkcg, →tkchipmunk, ..).
  • Binaries are available for Win32 (see Windows 2000/XP/Vista/Win7 32bit). Sources should build out-of-the-box for Linux X86 32/64bit (see Source code packages).
2. Features
2.1. Syntax
  • Uses a C-like syntax
2.2. Main features
  • Supports object oriented programming (OOP)
    • Script and (native) C++ classes
    • Multiple inheritance
    • Virtual methods / late binding
    • Delegates
  • Exceptions
    • Critical and uncritical error base types
  • Namespaces
    • For variables, exceptions and classes
  • PAK files
    • Platform agnostic, single-file "click-to-run" application packages
  • Speed
    • Just in time compiler (JIT) for speed critical codepaths
    • Supports native int/float datatypes as well as number objects
    • TkScript is one of the fastest scriptengines around (even without the JIT ;)
  • Multithreading
    • Synchronization features built into the language
    • Real, native threads (pthreads or win32)
2.3. Comfort features
  • Lazy casts between int/float/Object/String
  • Auto (un-)boxing
    • Scalar datatypes are automatically converted to objects and vice versa, e.g. in argument lists
  • Object operators
    • Script engine automatically takes care of new object allocation when necessary
    • Number objects can be used like any native/scalar data type
  • Easy (de-)serialization of datastructures. See The stream operator.
  • IntArray, FloatArray, StringArray, PointerArray, ValueArray, HashTable and List initializer expressions
    • returns one shared Object per source line (possibly read-only), contents are just updated when expression is evaluated
    • ..or a new Object everytime the expression is evaluated when the initializer is preceeded by the "new" keyword
  • Function objects
  • Multiline string constants
    • Useful for embedded shader programs or other "scripts" like SQL queries
  • Native code setter/getter methods can be treated like "properties"
    • e.g. instead of "trace v.getString();" you can simply write "trace v.string;"
  • Variable/Argument type can be omitted when subsequent declarations have the same type
    • Currently allowed in variable declarations, static and dynamic class method parameter lists, not in global function paramlists)
    • See Arguments.
  • Temporary, unloadable Script objects, e.g. used by tkui for scriptable ".xfm" files
2.4. Distributables
  • TkScript supports a PAK file mechanism to preprocess the sources and store them in a gzip'd, tokenized form, along with other application data like images, soundfiles etc.
    • ".tkx" application PAK files can easily be distributed and are platform agnostic
  • All script applications (and contained libraries) are compiled "from scratch" during startup
  • The filenames of such single-file, redistributable binaries end with ".tkx" (applications) respectively ".tsl" (libraries).
  • Existing .tkx applications can be dynamically extended by .tks and .tsl files using the -ef cmdline option (see Adding extra files to a pre-packaged application).
2.5. Memory managment
  • TkScript does *NOT* use garbage collection
    • For all values that reference a given Object, at most one Value may flag it as "deletable"
    • TkScript uses the keyword "deref" to unlink a (possibly) deletable Object pointer from its "owner" Value (e.g. a Variable) so a program can assign a new "owner" to an object (e.g. by pointer-assigning it to another variable)
    • Objects are deleted at exit resp. when a null pointer is assigned to the Value that currently owns the Object (think of this recursively)
  • Runtime object type verification
    • Can detect incompatible classes when an object is accessed (i.e. method calls, member queries)
      • Can detect references to dead objects, especially when the runtime is told to never free any memory during debug-runs :) (see Debugging)
2.6. Interfaces
  • The YAC plugin interface defines a number of standard "interfaces" that are used by the TkScript plugin host when working with "anonymous" objects.
    • Reflection, e.g. check whether an object is compatible with a given class, query methods/members, ..
    • Conversion between int/float/Object/String
    • Array (e.g. StringArray) and HashTable handling
    • Iterators (see The foreach statement)
    • "metaclasses" in the sense that a YAC_Object (the base class for all script objects) can have additional attributes that can be set/get. A scriptclass for example uses this mechanism to store its members.
    • I/O streams
      • (De-)Serialization with automatic byte order conversion
        • to-be-serialized members have to be tagged with the keyword "tag", see Tags.
        • yacIsComposite() is used to decide whether a non-deletable object is serialized, too (to avoid infinite recursion)
  • These interfaces are also reflected in the TkScript language constructs, keywords and operators
  • See The YAC_Object interface for details about the core C++/YAC object interface
2.7. Security/Stability concerns
  • Security/Stability concerns
    • The fact that the memory managment of TkScript is "semi-automatic" makes TkScript a language not for the faint of heart :)
    • Seriously, reference-counted memory managment can end up in exhaustive memory usage if not used properly (and may be hard to debug, too) .The design decision in TkScript to leave the memory managment partly to the scripts suggests that you should be careful at what you are doing :) Seriously again, if you really treat memory like resources (the good old C++ RAII design pattern) the semi-automatic memory managment will do (almost) all of the rest.
      • Failure to properly memory-manage object pointers in a script may result in engine crashes, unexpected type mismatch warnings or may simply be kept unnoticed until The Presentation. (sounds good, eh ?)
      • If you know what you are doing, you can write memory efficient applications ..actually you are quite well (mildly) forced to do so :)
    • The runtime is quite stable by now and the API rather fixed.
      • Major upcoming updates will include a new JIT compiler (the current one only works on 32bit X86 and then there is an outdated JIT for M68k.. never mind). The new JIT supports X86 32+64bit, ARMv5 and will hopefully support other architectures in the future, as well (the backend is considerably easy to port).
2.8. Multi-threading
  • TkScript supports multi threading via the native OS threading APIs (pthreads, win32 threads.. See Thread)
  • Script methods can be synchronized to a certain object instance, a global per-method mutex or a global named mutex using special keywords.
  • Arbitrary synchronization points using the Mutex class
  • More multithreading features like e.g. mailboxes will be added in future releases
  • Uses Thread Local Storage (TLS) to keep track of thread context handles
    • The thread context handle is required to run e.g. script class methods or to raise exceptions
2.9. Extensibility
2.10. Documentation
  • Documentation utilities
    • "explain" keyword to document script sources and "dog++" utility script to extract documentation from a C++ source
    • DOG (The DOG manual)
      • Utility script to convert the extracted documentation to HTML files and link it with some additional page files

auto-generated by "DOG", the TkScript document generator. Mon, 31/Dec/2012 13:35:30