Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
18th June 2009, 11:18 | #1 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
GScript - language extensions for Avisynth
This is something I started as a 'proof of concept' for my own amusement.
As I think some people will find it useful, I am making it generally available. GScript is a plugin that extends the Avisynth scripting language to provide additional control-flow constructs: multi-line conditionals (if-then-else blocks), 'while' loops and 'for' loops. Rather than trying to simulate these constructs with functions, GScript effectively extends the language syntax, making it easy to use the new constructs in a natural way and in arbitrary combinations. Here are the constructs in detail: 'if' statement Code:
if ( condition ) { statements } else { statements } The statements can be any Avisynth statements, including the GScript extensions themselves, and so the new constructs can be nested. The else part may be omitted (equivalent to else {}). GScript also provides the 'else if' construct (optionally repeated to create a chain of conditionals). Thus Code:
if ( condition ) { statements } else if ( condition ) { statements } else if (...) { ... } ... else { statements } Code:
while ( condition ) { statements } Example: Code:
while (Height() < h) { StackVertical(last, c) } Code:
for ( variable = init , limit , step ) { statements } First the variable is set to the value of init. The statements are repeated until the exit condition is met, ie variable exceeds limit (if step > 0), or is less then limit (if step < 0). After each iteration, variable is incremented by step. If the initial value satisfies the exit condition, the number of iterations will be zero. Example: Code:
for (i=1, nBlurs) { Blur(0.5) } Once the plugin is loaded (either via LoadPlugin or by installing GScript.dll in your plugins folder), there are two ways to use the extended language features. Firstly, a script (or part of a script) containing extensions can be passed as a text string to the GScript function (similar to the way functions like ScriptClip or MT are used). For example, Code:
GScript(""" if (i > 10) { x = 1 y = 2 z = 3 } else { x = 4 y = 5 z = 6 } """) The advantage of this is that you don't have to put quotes around the script, or worry about possible problems if the embedded script itself contains both triple and single quotes. Thus, you can write entire scripts directly in the extended language and just pass to Avisynth a single GImport command to read it. Code:
GImport("MyGScript.avs") Update: Version 1.1 (GScript_11.zip) released 6th Dec 2009 Last edited by Gavino; 15th February 2010 at 13:58. Reason: Remove v1.0 dll from attachments |
Tags |
for-loop, if-then-else, while-loop |
Thread Tools | Search this Thread |
Display Modes | |
|
|