Home | Reviews | GUIpedia | Forum | Fun500


ksrScripting language preview
I made a start today implementing the scripting language for my GUI. I've based it loosely on [url=http://en.wikipedia.org/wiki/Tcl]Tcl[/url], which is a really simple yet powerful language - you should definitely check it out. Here's a sample of what my language looks like: [code]set user Kyle #add two numbers set var1 4 set var2 6 set result [+ $var1$ $var2$] #add two strings (same syntax!) set var3 Hello set var4 ", World!" put "Hello $user$, $var1$+$var2$=$result$" put [+ $var3$ $var4$][/code] which outputs:[code] Hello Kyle, 4+6=10 Hello, World![/code] As you can see, the script is dynamically typed (meaning you don't have to declare variables as being 'string' or 'integer' etc.) All statements are of the format "command argument1 argument2 ...", and wherever you can put a variable, you can also place a command by enclosing it within [square brackets] The result of the command (everything is a function - even if it just returns an error code) is then substituted in. Similarly, wherever you can place a string literal, you can place a variable by enclosing it within $dollarsigns$ (this includes WITHIN quotes - unlike QB ). One thing which might catch you out is the syntax for arithmetic - an operator (such as + above) comes before the two operands. This is because the + sign, like everything else, is actually a function. (Incidentally, this is also how LISP works). A few other unusual things about this language (which I think may be unique within QB/FB GUI scripting languages): A variable, believe it or not, is ALSO a function! This opens up the possibility for self-modifying code, e.g. [code]set instruction "put Hello" $instruction$[/code] With more than the 3 commands I've currently implemented (set, put and +), you could for instance get commands from the user and execute them without having to parse them. Also, variable names need not be just one word: [code]set "a variable whose name is very long" value put $a variable whose name is very long$[/code]
2008-07-232:09 PM

agumaRe:Scripting language preview
Nice! :) That's sort of like mine too.
2008-07-232:10 PM

BrandonRe:Scripting language preview
cool, so do you have a screenshot of this in action?
2008-07-232:23 PM

ToddRe:Scripting language preview
WOW! That's amazing Kyle! It's almost like PHP where you can put variables in string literals and PHP interprets them as variables rather than as literal strings. Did you put in the backslash override trigger in case someone wants to put a $ in the string? So if they do "$a" it will put "$a" out on the screen while if they put "$a" it will put the value of "a" on the screen.
2008-07-232:24 PM

ksrRe:Scripting language preview
[quote]cool, so do you have a screenshot of this in action? [/quote] At the moment, it's purely text-mode. I'm not too sure how GUI elements will work at the moment, but I'm looking at how [url=http://en.wikipedia.org/wiki/Tk_(computing)]Tk[/url] does it (Tk is a GUI library often packaged with Tcl). [b]tlsuess wrote:[/b] [quote]Did you put in the backslash override trigger in case someone wants to put a $ in the string? So if they do "$a" it will put "$a" out on the screen while if they put "$a" it will put the value of "a" on the screen.[/quote] I haven't implemented this yet, but yeah, eventually backslash will be used as the escape character for things like $, " etc.
2008-07-232:38 PM

BrandonRe:Scripting language preview
Well you should add it to the modern GUIs Topic you can get to it in the main menu.
2008-07-232:41 PM

ksrRe:Scripting language preview
[b]Brandon wrote:[/b] [quote]Well you should add it to the modern GUIs Topic you can get to it in the main menu.[/quote] When I think of a name, I will :P
2008-07-232:55 PM

BrandonRe:Scripting language preview
Edge 3?lol
2008-07-233:36 PM

ksrRe:Scripting language preview
Ahaha, I think I've probably used that somewhere.
2008-07-233:51 PM

ksrRe:Scripting language preview
Today I implemented the {while} control structure, which is essentially the same as a DO..LOOP/WHILE..WEND structure in BASIC. This language doesn't have a FOR..NEXT equivalent - but you can use a {while} with the same effect, providing you increment/decrement your count variable manually. Here's an example that outputs a multiplication table: [code]#ex4.app: demonstration of nested whiles set x 0 { while [< $x$ 10] #FOR equivalent set x [+ 1 $x$] #add 1 to x (part of FOR) set y 0 { while [< $y$ 10] set y [+ 1 $y$] put -nonewline [* $x$ $y$] put -nonewline " " } #force newline put "" }[/code] As you can see, whiles can be nested (up to 100 times), and some commands have additional flags you can set (such as "-nonewline" in "put" above). [br][br]edit: Here's a screenshot of the output: [url=http://www.file-pasta.com/file/1217001143.6376_tnt%20ex4.png] [img]http://www.file-pasta.com/thumb/-1217001143.6376_tnt%20ex4.png[/img] [/url]
2008-07-2511:47 AM

BrandonRe:Scripting language preview
OK now add a GUI at it will be cool. :P
2008-07-2512:26 PM

GUIs


2021 Brandon Cornell