If you don't like dealing with Scripting.dictionary you might want to try out this thing I whipped up yesterday evening and this morning.
Basically just a simple wrapper around Scripting.dictionary to make the API a little bit less stupid. By "stupid" I mean "not like the awesome Python dict API".
Created for the following reasons..
Wanted to get a basic understanding of AutoItObject. Wanted to get a basic understanding of the Micro unit test framework. As of 11/4/2014 AutoIt Stable has no native dict or associative array type. A >Map type is in the current AutoIt beta. It's laborious to use Scripting.dictionary all the time. The Python dict API is better than Scripting.dictionary's I thought about writing my own hash table implementation in AutoIt, but on balance I decided it wasn't worth the effort and just stuck to Scripting.dictionary to save time/effort.
As you can see I've got a decent number of unit tests for such a simple implementation, so it should be quite robust.
#include <Dict2.au3> #include <Array.au3> $dict = _DictCreate() ConsoleWrite($dict.len()) ; Outputs 0 $dict.set("key1", "value1") $dict.set("key2", "value2") $dict.set("key3", "value3") $dict.set("key4", 1) ConsoleWrite($dict.get("key2")) ; Outputs 'value2' ConsoleWrite($dict.len()) ; Outputs 3 ConsoleWrite($dict.contains("key2") ; Outputs True $dict.set("key4", $dict.get("key4") + 1) ConsoleWrite($dict.get("key4")) ; Outputs 2 $dict.del("key4") ConsoleWrite($dict.contains("key4")) ; Outputs False $aPairs = $dict.pairs() _ArrayDisplay($aPairs) ; Displays 2d array with column one contains keys, and column two ; containing associated values $aKeys = $dict.keys() _ArrayDisplay($aKeys) ; Displays array containing all keys $aValues = $dict.values() _ArrayDisplay($aValues) ; Displays array of all values $aDesiredKeys = ["key1", "key3"] $aValues = $dict.values($aDesiredKeys) _ArrayDisplay($aValues) ; Displays array of values for key1 and key3 GET IT HERE
I have a project where I wish to create a layout file for a drawing program using AutoIT.
The format for this program is simple: header, objects (1..n), properties. Most of it, I have in control.
But I need an idea about how best to add the objects. Here, an object has some properties such as coordinate, font etc. My idea is to call a function like add_object() which will add with default parameters.
Now to my question: how can I "override" parameters in the function call ? I do not know which parameters will be overridden, this depends on user choices. So thereby I do not know the number of parameters in my function call.
Do anyone have an idea about how to do achieve something like this, which is inspired from Perl
; pseudocode function call: add_object( 'xpos' => '123', 'font' => 'Arial', 'rotation' => '90' ) ; the remaining parameters will be default ; pseudo code func add_object(byref $paramsettings) $original = get_default_object() ; first load a default object type for each $key ($paramsettings) $original[$key] = $paramsettings[$key] ; override default here next write_out_object($original) ; now with modified original endfunc
I have looked at but I am not 100% sure how to pass as an argument and (specifically) how to check which keys are passed ? (as in "for each $keys in $passed_array")
Any help welcomed.