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. |
23rd January 2012, 03:08 | #1 | Link |
Registered User
Join Date: Jan 2012
Location: On the net
Posts: 76
|
Arrays and such
Hello all,
I am new to AviSynth (less than a month) and I quickly noticed that there was no usable array system available (the one that was pointed to was uber slow due to O(n) implementation). So I have started to write a new one (well, actually almost finished, but couldn't post till now) which is O(1) but I was wondering if anyone else would be interested in this library. If so, where would be a good place to put it? There are also other libraries I created in passing such as a for loop, profiler, parameter list to array converter, memory allocation system and others. Thanks, Mx |
23rd January 2012, 03:50 | #2 | Link |
Registered User
Join Date: Feb 2002
Location: San Jose, California
Posts: 4,406
|
I am sure we would be interested, you can post a link here so we can play with it.
Also please do not double post, we all look in both Avisynth forums. This looks like it fits in Development much better than Usage. |
26th January 2012, 08:14 | #4 | Link |
Registered User
Join Date: Jan 2012
Location: On the net
Posts: 76
|
Ok, I've uploaded it to sourceforge. Please bare with me as I've not used this service before 2 days ago.
You can download the compressed archive here. Please feel free to post feedback, questions or comments as they are all welcome. Thanks, Mx |
27th January 2012, 19:25 | #5 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
I haven't had time to look at this in detail, but here are a few quick comments.
It looks like you've put a lot of work into this - certainly, there's a lot of code there. For that reason, it's hard to know where to start to understand how to use it and (doubly so) how it works. Some examples would certainly be useful. At a casual glance, your 'for' function looks quite complicated to use. Moreover, since the block to be executed is Eval'd in the function scope, it cannot use local variables from the calling environment. That's what I was getting at in my post yesterday. Are you aware of GScript? It provides a simple for-loop construct (as a language extension, not a function). It also has a block if-then-else which could be used in place of the ugly (IMHO, of course ) Eval blocks in your code. If you like, you could even write the entire code in the extended GScript language and just use GImport instead of Import to load the files. |
28th January 2012, 01:23 | #6 | Link |
Registered User
Join Date: Jan 2012
Location: On the net
Posts: 76
|
I wish I knew about gscript before. Yes, my for is a bit messy, but it was all that I had. It'll be interesting to see how they profile against each other.
As for sharing stuff to the local environment, yes, it can be done, abet convolutedly. There is a forState that is passed around between each iteration. Learned such things from other functional languages including Boost::mpl. You pass your string into the forState and return that from the block. An example would be to write the numbers from 1 to 10 separated by commas: Code:
for(2, 11, """for_returnContinue(forState + "," + forIndex.string)""", "1").for_result A quick look at gscript, seem that you can't bail out of a loop prematurely. In the for I created, this is possible. A slight modification to the previous code to stop at 5 would look like this: Code:
for(2, 11, """for__returnContinueIf(forState + "," + forIndex.string, forIndex < 5, forState)""", "1").for_result References can also be used, but it looks strange: Code:
ref = mem_new(3) for(0, 5, """ forState.mem_set(forState.mem_get + 1) forState.for_returnContinue """, ref) assert(ref.mem_get == 8) Yeah, I should make more examples to show how to use the library. I'm just trying to figure out some reasonable ones. |\/|x Last edited by maxxon; 28th January 2012 at 01:43. |
28th January 2012, 13:37 | #7 | Link | ||
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Quote:
See posts #27-29 here (which also touches on the topic of arrays). |
||
28th January 2012, 17:06 | #8 | Link | ||
Registered User
Join Date: Jan 2012
Location: On the net
Posts: 76
|
Quote:
Another more direct way to do it though references without passing through the forState variable is to build the for body string. Code:
ref = mem_new("1") for(2, 11, """ ref = """"+ref+"""" # Note the 4 quotes, that puts in a quote inside of the string ref.mem_set(ref.mem_get + "," + forIndex) forState.for_returnContinue """, "") assert(ref.mem_get == "1,2,3,4,5,6,7,8,9,10") ref.mem_delete # forgot this line before. If you don't delete your ref, you can end up with a memory leak But to use a named variable, no, there is no way unless the scripting language gives access to the push and pop contexts functions, or give a way to call a function that will not push and pop a context. Say like this: Code:
function fn(param) { assert(myVar == "hello") myVar = param } myVar = "hello" "fn".apply_nocontext(3) assert(myVar == 3) EDIT: Actually, given what you said about creating filters, such a function is extremely doable. EDIT: Opps, no, this would have to be on level of the parser. EDIT: I am also working on static and anonymous structures which would allow for named access to the elements within. So, that would be a psudo named access feature. See next post. Quote:
Due to how the reference array (RA) works (they are a concatenated string of memory references), they are fairly easy to build and manipulate. But again, you must delete the array or you will cause a memory leak. Given this, you can actually pass in a RA into a for the same way that I described for passing the alias to the ref, though the array would be static (you wouldn't be able to change its size unless you used a reference to the array), the elements would be accessible and manipulatable. |\/|x Last edited by maxxon; 28th January 2012 at 17:50. |
||
28th January 2012, 18:13 | #9 | Link |
Registered User
Join Date: Jan 2012
Location: On the net
Posts: 76
|
I'm also considering making structure support in this library. Consider for an anonymous structure:
Code:
a = struct_newAnnon(RA_new(\ struct_el("var1", 8), \ struct_el("var2", "text") \ )) assert(a.struct_get("var1") == 8) assert(a.struct_get("var2") == "text") a.struct_set("var1") == 3 assert(a.struct_get("var1") == 3) Code:
struct_newDefine("myStruct", \ RA_new( \ struct_el("var1", 9), \ struct_el("var2", "hello") \ )) a = struct_new("myStruct") assert(a.struct_get("var1") == 9) assert(a.struct_get("var2") == "hello") a.struct_set("var2", 5) assert(a.struct_get("var2") == 5) Code:
function fn(string myData) { assert(myData.struct_get("var2") == 5) myData.struct_set("var2", "new string") } fn(a) assert(a.struct_get("var2") == "new string") for(0, 5, """ a=""""+a+"""" assert(a.struct_get("var1") == 9 + forIndex) assert(a.struct_set("var1"), a.struct_get("var1") + 1) """, "") assert(a.struct_get("var1") == 14) |\/|x Last edited by maxxon; 28th January 2012 at 18:27. |
28th January 2012, 18:31 | #10 | Link | ||
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Personally (and I don't think I'm alone), I would much prefer to write: Code:
result = "1" for (i=2, 10) { result = result + "," + i.string } Quote:
How would you write Stephen R. Savage's example with your stuff? EDIT: Just seen your latest post. I'll get back to you later on that. |
||
28th January 2012, 20:34 | #11 | Link | ||
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Code:
a.struct_set("var1", a.struct_get("var1") + 1) Quote:
It's the sort of thing that may be of interest only to language geeks like you and me. I'd be interested to hear what others think. Actually, I played around with something similar back in 2008, but it was purely for amusement and I never released it. I grandly called it 'Object AVS'. FWIW, here's the code (including an example/test). Code:
global AVSO_n = 0 function ObjNew(string "class") { global AVSO_n = AVSO_n + 1 obj = "AVSO_" + string(AVSO_n) Defined(class) ? obj.ObjSet("class", class) : NOP return obj } function ObjGet(val obj, string member) { try { v =Eval(obj+"_"+member) } catch (e) { v = NOP } return v } function ObjSet(val obj, string member, val value) { Assert(IsObj(obj), "ObjSet: invalid object") vString = (IsString(value) ? chr(34)+chr(34)+chr(34)+value+chr(34)+chr(34)+chr(34) : string(value)) Eval("global "+obj+"_"+member+"="+vString) return obj } function ObjSet(val obj, string member1, val value1, string member2, val value2) { ObjSet(obj, member1, value1) ObjSet(obj, member2, value2) } function ObjSet(val obj, string member1, val value1, string member2, val value2, string member3, val value3) { ObjSet(obj, member1, value1) ObjSet(obj, member2, value2) ObjSet(obj, member3, value3) } function ObjSet(val obj, string member1, val value1, string member2, val value2, string member3, val value3, string member4, val value4) { ObjSet(obj, member1, value1) ObjSet(obj, member2, value2) ObjSet(obj, member3, value3) ObjSet(obj, member4, value4) } function IsObj(val v) { return IsString(v) && LeftStr(v, 5) == "AVSO_" } function ObjFunc(string class, string func) { i = FindStr(func, "(") j = FindStr(func, ")") f = "function AVSO_c_"+class+"_"+LeftStr(func, i)+"val this"+(j>i+1 ? "," : "")+MidStr(func, i+1) Eval(f) } function ObjCall(val obj, string call) { class = obj.ObjGet("class") call = FindStr(call, "(") == 0 ? call +"()" : call i = FindStr(call, "(") j = FindStr(call, ")") f = "AVSO_c_"+class+"_"+LeftStr(call, i)+"obj"+(j>i+1 ? "," : "")+MidStr(call, i+1) Eval(f) } BlankClip() x = ObjNew() x.ObjSet("prop", "xxx") ObjFunc("myclass", "DoIt(){ return 42 }") ObjFunc("myclass", "DoIt2(int i){ return i+1 }") ObjFunc("myclass", """count() { return this.ObjGet("count") } """) y = ObjNew("myclass") y.ObjSet("count", 1234) global ii = 998 Subtitle(string(x.ObjGet("prop"))) Subtitle(string(y.ObjCall("DoIt()")), y=20) Subtitle(string(y.ObjCall("DoIt2(999)")), y=40) Subtitle(string(y.ObjCall("DoIt2(ii)")), y=60) Subtitle(string(y.ObjCall("count")), y=80) |
||
29th January 2012, 07:16 | #12 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
@Gavino, the new pretender (Maxxon) may well be impressive, but we all still love you best.
(unless he usurps you as omnipotent deity that we all think you are) (The king is dead ... God save the King)
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 29th January 2012 at 07:58. |
29th January 2012, 08:07 | #13 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
@Maxxon, you could do worse that to have a look at AutoIt,
as an example see here (Myself just found it about Nov/Dec 2011) http://forum.doom9.org/showthread.php?t=163343
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
29th January 2012, 08:08 | #14 | Link | |||
Registered User
Join Date: Jan 2012
Location: On the net
Posts: 76
|
Quote:
Quote:
Quote:
|\/|x Last edited by maxxon; 29th January 2012 at 08:28. |
|||
29th January 2012, 08:18 | #15 | Link | |||
Registered User
Join Date: Jan 2012
Location: On the net
Posts: 76
|
Quote:
Quote:
Quote:
|\/|x |
|||
29th January 2012, 08:27 | #16 | Link | |
Registered User
Join Date: Jan 2012
Location: On the net
Posts: 76
|
Quote:
|\/|x |
|
29th January 2012, 08:33 | #17 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
My sort of GUI batch utility (as I said, I only discovered it less than three months ago) and within
about 5 or 6 weeks of writing that GUI util), but it is a fully fledged language and very flexible. Way more flexible than the Avisynth lang. EDIT: Sorry, I read somewhere that you liked proggy languages, and answered, but presumably I read it in a different thread, because there was no pause between my previous and then current post.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 29th January 2012 at 08:44. |
31st January 2012, 07:01 | #18 | Link | ||
Registered User
Join Date: Jan 2012
Location: On the net
Posts: 76
|
Quote:
Quote:
Code:
super = MSuper() test = RA_newDefault(6, 0) for(1, 3, test = """"test"""" super = """"super"""" test.RA_set(forIndex, MAnalyse(super, idx=forIndex, isb=true)) test.RA_set(forIndex*2, MAnalyse(super, idx=forIndex)) } MDeGrain3(super, test.RA_get(1), test.RA_get(4), test.RA_get(2), test.RA_get(5), test.RA_get(3), test.RA_get(6)) Code:
super = MSuper() test = RA_newDefault(6, 0) forEx(vars_push(RA_new("super", "test")).eval, \ "i", 1, 3, """ test.RA_set(i, MAnalyse(super, idx=i, isb=true) test.RA_set(i*2, MAnalyse(super, idx=i) """).eval MDeGrain3(super, test.RA_get(1), test.RA_get(4), test.RA_get(2), test.RA_get(5), test.RA_get(3), test.RA_get(6)) |\/|x Last edited by maxxon; 31st January 2012 at 13:34. |
||
31st January 2012, 07:33 | #19 | Link | |
Registered User
Join Date: Jan 2012
Location: On the net
Posts: 76
|
Quote:
Code:
struct_define("myclass", RA_new(struct_el("var1", 0))) function myclass_new() { } function myclass_get(string obj) { obj.struct_get("var1") } function myclass_set(string obj, int val) { obj.struct_set("var1", val) } function myclass_delete() { } instance = obj_new("myclass") assert(instance.obj_call("get")==0) instance.obj_call("set", 9) assert(instance.obj_call("get")==9) instance.obj_delete Then later on tack on an inhieritance system which would do function searches up the inhierentance tree if ones don't exist. Of course that probably wouldn't work properly until the try catch bug is fixed. |\/|x p.s. please forgive any spelling mistakes, I've just got a new laptop and I've not installed the dictionary yet. Last edited by maxxon; 31st January 2012 at 07:35. |
|
31st January 2012, 07:39 | #20 | Link | |
Registered User
Join Date: Jan 2012
Location: On the net
Posts: 76
|
Quote:
|\/|x |
|
Tags |
array, avisynth, fast, o(1) |
Thread Tools | Search this Thread |
Display Modes | |
|
|