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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 21st May 2005, 05:04   #1  |  Link
vcmohan
Registered User
 
Join Date: Jul 2003
Location: India
Posts: 890
Facility to skip portions of script

In Avisynth script # symbol makes the parser to disregard the line. When a large number of statements are being tried for optimum results very often need to skip a large chunk of script arises. By meticulous planning and equating results to some symbols this is possible but immediately one statement is changed a chain of statements need some modifications. Functions can be specified but not always convenient. I am looking forward for a facility like /* */ of C++ may be /# or @# or &# and their inverses on a line by itself can ignore the code inbetween by the parser.

Yesterday I posted a similar request but today I did not find it in the topics.
__________________
mohan
my plugins are now hosted here
vcmohan is offline   Reply With Quote
Old 21st May 2005, 06:09   #2  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
Re: Facility to skip portions of script

Quote:
Originally posted by vcmohan
Functions can be specified but not always convenient.
Functions usually are the best way to go.

Disabling code by commenting it out in general software development usually leads to maintainability problems. Refactoring and modularizing are good things.

But, if you really must, one hack is to use quotes (or triple-quotes) and treat an entire section of a script as one big, unused string.
stickboy is offline   Reply With Quote
Old 21st May 2005, 07:21   #3  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
could you elaborate on the triple quote thing? i don't get how it'd carry across lines.

btw, avisynth scripting, though often quite advanced, isn't software development. it's good to be able to "rem out" several lines when you're only talking about trying different things out on a clip. it'd also be nice for documenting useful scripts (so other people can use them) without having to put heaps of # everywhere.

for example, i'm the only geek at work who really knows avisynth, though heaps of people would like to use it for simple things (NTSC to PAL comes up a lot). to have an instruction manual inside a script is useful in these cases, though it's not really important to have no #'s at the start of each line. more of a convenience thing i guess.

hehe... i second vcmohan's request
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 21st May 2005, 13:52   #4  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
Quote:
Originally posted by Mug Funky
could you elaborate on the triple quote thing? i don't get how it'd carry across lines.
It just does. That's the way how AviSynth's script parser works.

Code:
mpeg2source("sample.d2v") 

# unused = """ \
addborders(16,0,0,0)
subtitle("funny text")
# normal comments don't interfere 
greyscale
# \"""

return last
In the same manner, after uncommenting the first and last #'s you could even do

eval(unused)

By doing so, you can enclose different parts of a script in quotation marks, and use these strings as quasi-functions. At times this may come handy for conditional executions and such. See here.

stickboy wrote lots of useful stuff for AviSynth. Reading it is really worth it.
- But if one doesn't mind bowing down to grab the money that's lying on the street, well ...
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 22nd May 2005, 13:15   #5  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
tnx, didée
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 23rd May 2005, 16:31   #6  |  Link
esby
Registered User
 
esby's Avatar
 
Join Date: Oct 2001
Location: france
Posts: 521
Quote:
Disabling code by commenting it out in general software development usually leads to maintainability problems.
1- Sorry to be abrupt, but how is that possible? Commenting out code is a way to quick test code part. I do agree that it means that you have no cvs/svn/ source control (god knows what you are or should be using) system. Now, I doubt that the facility provided by /* or (* blocks leads to maintainability problems.
If I take vb6 as an example, you don't have this option... so you are forced to use comment your block by starting ' which is kinda depressing...
I do agree that the use of goto and labels leads to disastrous problem, but that's not the case for style commenting, as far I know.

2- Even with this argument taken (and proven as valid), I doubt that it will affect the stability of scripts, if such concept exists. Am I wrong?

Now adding the corresponding comment style is possible in the actual parser and in the future (3.0) right?

esby
__________________
http://esby.free.fr/
esby is offline   Reply With Quote
Old 23rd May 2005, 17:22   #7  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
Quote:
Originally posted by esby
1- Sorry to be abrupt, but how is that possible? Commenting out code is a way to quick test code part. I do agree that it means that you have no cvs/svn/ source control (god knows what you are or should be using) system. Now, I doubt that the facility provided by /* or (* blocks leads to maintainability problems.
Abusing the comment system as a means to disable code has the following problems:
  • Comments serve as documentation. When you disable code by putting it in comments, it isn't always clear whether that code is merely disabled or if that code is serving as documentation to the code around it. e.g.
    Code:
    # x = y
    y = z
    Does the above mean that x == y == z? Or does it mean that x = y and y = z are mutually exclusive? It's confusing. #if 0 .. #endif in C is usually slightly better.
  • It allows the commented out code to become stale. You disable some code, the rest of the code evolves, and now you have this section of disabled code that no longer works if enabled, and it's usually not clear what purpose the disabled code served, why it's disabled, and why it wasn't just completely removed in the first place. Or sometimes there are several sections of code that are commented out, but they are meant to be re-enabled only in certain combinations.
Sure, using comments to disable code for quick testing is fine, but once time starts elapsing, you start forgetting things. Maintainable code needs to defend itself against time.
Quote:
2- Even with this argument taken (and proven as valid), I doubt that it will affect the stability of scripts, if such concept exists. Am I wrong?
I'm not talking about stability; I'm talking about modifying a script at some future date and not wasting time trying to figure it out. Furthermore, as memory fades, it becomes increasingly difficult to remove disabled code. "Why didn't I remove this code originally? I must have left it here for a reason, so I'll keep it around in case I remember later." Right.

Last edited by stickboy; 23rd May 2005 at 17:31.
stickboy is offline   Reply With Quote
Old 23rd May 2005, 22:59   #8  |  Link
esby
Registered User
 
esby's Avatar
 
Join Date: Oct 2001
Location: france
Posts: 521
I agree with the explanation, except a few points...
Code:
# x = y
y = z
I am not wrong, but it is not 'start/end block style commenting'
So you are merely talking of the usage of comments to take code out, no matter the type of comments used.
I mean, the example you use can be done (and is done already) in avisynth.
So it does not justify the absence of 'comment blocks'.

Now give me just the counter example of what you say.
(pascal style)

Code:
(*** Removed code 
 y := z 
 x := z   
 End of removed code ***)
I think there is no possible ambiguity.
The ambiguity you describe is only possible by bad documentation practice to my eyes. Of course, nobody is perfect, but the point is not here.


Quote:
I'm talking about modifying a script at some future date and not wasting time trying to figure it out.
That's what the 'real & proper' comments are for, no matter the language.
Having a start & end comment type can help here,
as you can format more easily comments, althought it is very relative and narrowed point of view...
Of course, functionnal programming is a better approach.
Now I usually create an avs script by modifying a model or template.
When I use function, it is mainly to avoid rewriting existing code, not to maintain these scripts over time. These scripts have a relatively restricted utility over time. You can even consider that once there have been written and used, you'll almost never use them again, but that's my mere opinion.

esby

PS: I think that the one of the reason to the absence of comment blocks is that nobody ever requested them or estimated them to be avs scripting.
__________________
http://esby.free.fr/
esby is offline   Reply With Quote
Old 24th May 2005, 03:35   #9  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
Quote:
Originally posted by esby
I am not wrong, but it is not 'start/end block style commenting'
So you are merely talking of the usage of comments to take code out, no matter the type of comments used.
I mean, the example you use can be done (and is done already) in avisynth.
So it does not justify the absence of 'comment blocks'.
Right, and I'm not opposing adding start/end comment blocks in AviSynth. None of my posts above referred specifically to multi-line comments.

All I said was that using comments (whether single-line or multi-line) for the purpose of disabling code is in general a poor programming practice that can lead to maintainability problems.
stickboy is offline   Reply With Quote
Old 26th May 2005, 03:25   #10  |  Link
vcmohan
Registered User
 
Join Date: Jul 2003
Location: India
Posts: 890
May be maintainability problems exist with this style of commenting out portions of script. but I find that just as in C++ coding it is useful in many cases, there is utility in having such a facility in Avisynth scripting also. Every facility can be misused, but that does not preclude having such a facility. Hope it will be introduced.
__________________
mohan
my plugins are now hosted here
vcmohan is offline   Reply With Quote
Old 9th June 2007, 17:41   #11  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
It is a time to return to this discussion.
IMO, block comments would be useful both for multi-line and single-line comments like C /* comment */
It also may be useful for editors like AvsP for of sliders or switching blocks.

The implementation is quite easy (in tokenizer.cpp).

The question is: what symbols to use as a comment.
New avosynth must be compatible with old scripts.
The possible candidates are: [ and ] or [# and #]
May be some other. AvsP-compatibility is important too,
but AvsP syntax may be changed IMO.
For example, it is possible to use filter(param=[<"name",0,255>]5) instead of filter(param=[<"name",0,255,5>]).
In this case brackets may be considered by new Avisynth as comment block.

?
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick
I usually do not provide a technical support in private messages.
Fizick is offline   Reply With Quote
Old 10th June 2007, 02:27   #12  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
I would hate to waste a good set of single bracketing characters. You never know when you might need them.

So I would prefer to go with a pair of characters like the [# ... #] or what most current languages seem to be using i.e good ol' /* ... */
IanB is offline   Reply With Quote
Old 10th June 2007, 09:18   #13  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
After some playing I discover, that Didee example with triple quotes may be even more simple:

Code:
version()

"""  it is docstring comment block
addborders(16,0,0,0)
subtitle("funny text")
# normal comments don't interfere 
greyscale
"""

return last
So, we already have some almost normal block comments (python-style). http://en.wikipedia.org/wiki/Python_...and_docstrings

But it can not be used in function parateters through.


Looking to source I discover one more undocumented feature:
__END__ statement for comments after end of code!
(like Perl and Ruby)

Code:
version()

addborders(16,0,0,0)
# normal comments don't interfere 

__END__
any lines after this end statement is a comment and not processed

subtitle("funny text")
greyscale

return last
seems, it was so in all avisynth versions.
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick
I usually do not provide a technical support in private messages.
Fizick is offline   Reply With Quote
Old 10th June 2007, 23:03   #14  |  Link
gzarkadas
Registered User
 
gzarkadas's Avatar
 
Join Date: Sep 2005
Location: 100011110010001000001 10000011111111000001
Posts: 221
Triple double quoted strings may appear in the script as values to assign in variables or pass to functions (especially when you want to make something a bit more elaborate with the runtime filters, or make an if..else block). Thus one cannot block-comment such sections of the script with this trick.

I believe a special double pair with its first character to be # is the best solution, because then only the part of the tokenizer that skips characters after the comment has to be modified. Some possible candidates:

#/ ...... /#

#{ ...... }#

#< ...... >#

#[ ...... ]#
__________________
AVSLib, a free extension library for Avisynth. Current version: 1.1.0 (beta), 14/05/2007.
[ Home page | Download page ]

Last edited by gzarkadas; 10th June 2007 at 23:04. Reason: minor corrections
gzarkadas is offline   Reply With Quote
Old 10th June 2007, 23:21   #15  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Using a leading '#' will change the existing behaviour. Any script that happens to match the chosen pair would no longer work. Candidate pairs need to cause a systax error in the existing versions.
IanB is offline   Reply With Quote
Old 10th June 2007, 23:29   #16  |  Link
Leak
ffdshow/AviSynth wrangler
 
Leak's Avatar
 
Join Date: Feb 2003
Location: Austria
Posts: 2,441
Quote:
Originally Posted by IanB View Post
Using a leading '#' will change the existing behaviour. Any script that happens to match the chosen pair would no longer work. Candidate pairs need to cause a systax error in the existing versions.
I guess /* */ fits that bill quite well...

np: The Black Dog - Vir²l (Parallel)
__________________
now playing: [artist] - [track] ([album])
Leak is offline   Reply With Quote
Old 10th June 2007, 23:40   #17  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
well, /* ... */ is not so bad (this combination is not possible in current version).

will it possible to comment inside a function?

Code:
version()
borders(0,/* add two top lines */ 2, -0,-0)
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick
I usually do not provide a technical support in private messages.
Fizick is offline   Reply With Quote
Old 10th June 2007, 23:44   #18  |  Link
Leak
ffdshow/AviSynth wrangler
 
Leak's Avatar
 
Join Date: Feb 2003
Location: Austria
Posts: 2,441
Quote:
Originally Posted by Fizick View Post
will it possible to comment inside a function?

Code:
version()
borders(0,/* add two top lines */ 2, -0,-0)
As long as comments are skipped in the tokenizer that should be possible, yes.

Will there be support for nested block comments? Those would simply need a counter in the skipping routine.

And what should happen with stuff like "/*/" and "*/*"?

np: Porn Sword Tobacco - Copyright The Universe (New Exclusice Olympic Heights)
__________________
now playing: [artist] - [track] ([album])
Leak is offline   Reply With Quote
Old 11th June 2007, 02:51   #19  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Hmmm, nested block comments. Very usefull. Possible, but not straight forward. I have currently hijacked the """ code and it seems to work, but nesting cannot be done this way.
IanB is offline   Reply With Quote
Old 11th June 2007, 09:05   #20  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Okay, I've been tinkerin' somewhat.

1. Having both nestable and first drop terminable comments is damn usefull.

2. [# #] I think looks ugly, the # char is to heavy.

3. [* *] seems to look more balanced to my eye.

So currently I have /* */ as first drop terminable comments. i.e /* /* */ is valid.

And [* *] as nestable terminable comments i.e. [* [* *] *] is valid.

To keep things backwards compatible the # nuke to EOL style comment has priority. i.e # /* and # [* are valid.

I'll put the code into CVS soonish and put up an avisynth.dll to try.

Thoughts?
IanB is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:58.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.