Scripted plugin overview

Charlie Brej plymouth at brej.org
Tue Jun 16 03:41:13 PDT 2009


I have pushed the scripted plugin into the git as a branch "scripted-plugin". It 
has been written in my coding "style" and I will go through to correct it all 
soon. The point of this email is to just present the syntax of the scripted 
language and see if people have ideas to what is desired. Most of these are not 
concious design choices but rather that's the way the pieces fell when trying to 
make a minimal language so please say which bits are undesirable.

The general syntax is pretty C like with semicolons. There are four internal 
types: NULL, int, string and hash (float will be added soon). You don't have to 
declare a variable or its type before you use it. If you read a variable which 
has not been set its value will be NULL. Ints allow all the usual operations and 
comparisons. Strings can be concatenated using a plus. Operations between types 
that are not compatible give a NULL. To access an element of a hash you can 
either use or square brackets with the value to index by (hash["element"] or 
index="element"; hash[index]) or if the index is a string you can use the dot 
notation (hash.element). When using int as a hash index (equivalent of an array) 
it gets translated into a string (hash[10] is equivalent to hash["10"]). When 
assigning one var to another, if it is a string or an int the object is 
duplicated, otherwise a reference is made.

There are two contexts (local and global). If a variable is used (read or 
written to) it is looked for in the local context (even if equal to NULL), if 
not found then it is looked for in the global context, if not found it is 
created in the local context. The two contexts are actually hashes and which can 
be accessed to force a variable to be looked for in that context only by using 
"local" and "global" (e.g. global.var = 0). There is no scoping within {} blocks.

Functions are defined with "fun function_name (par1, par2){body}". When called 
par1 and par2 in the local context get set with the first two parameters passed 
in. If fewer are passed in then they are unset (NULL when read). If a function 
fails to return a value or reaches the end it returns a NULL.


On the implementation side the code is 3,000 lines of code so not too heavy and 
runs at the order of 1 MIPS. The system allows additional native types and 
functions to be added which can represent native C implementations. Image and 
sprite are two examples where a new object type is introduces along with some 
functions to interact with it. Some functions which do not need any raw C can be 
described directly in a script. These scripts are escaped (using perl) and 
#included in the compiled code and parsed/executed at startup. Garbage 
collection is done by reference counting which can lead to memory leaks in 
cyclicly referencing objects.


More information about the plymouth mailing list