C++: AHK source code: append number to array

Post a reply

In an effort to prevent automatic submissions, we require that you complete the following challenge.
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review

Expand view Topic review: C++: AHK source code: append number to array

Re: C++: AHK source code: append number to array

Post by jeeswg » 21 May 2019, 17:43

- Fair points re. the Range object, I've updated the post to provide an enumerator object version.
- That said, I tested my original function, and it worked great at 1 million keys, and reasonably well up to 10 million keys. I'd be unlikely to use it for over a thousand keys.

- I don't mind what the C++ code what would like for a built-in Range function. However, the specifics of the start/end/step parameters are subtle, and what I wanted to pin down in the post.

- After writing this post, I saw essentially the same idea here:
Adding help function: TokensToScriptObject and two related macros. by HelgeffegleH · Pull Request #110 · Lexikos/AutoHotkey_L · GitHub
- Both you and Helgef have suggested that being able to easily add keys to an AHK basic object, within the C++ code, could be useful, and I agree.
- I wondered if you had any use cases in mind.

Re: C++: AHK source code: append number to array

Post by nnnik » 20 May 2019, 07:02

A range function should probably create a custom object rather than a built in object with all keys and values inside. You would need insane amounts of Ram for larger loops.
And the lookup cost of a single key value pair is probably greater than calculating the value on the spot.

Im not sure about the code you shared since object creation usually starts with the new operator in most languages.

C++: AHK source code: append number to array

Post by jeeswg » 17 May 2019, 11:17

In the AHK v1 source code, this function would return an empty array:

Code: Select all

	Object *output_array = Object::Create();
	aResultToken.symbol = SYM_OBJECT;
	aResultToken.object = output_array;
What is the best way to append an Integer/Float to that array?

Relevant functions: StrSplit (AHK v1/v2), WinGetList (AHK v2).

Potentially relevant code: Object::Append, which is inside script_object.cpp (AHK v1/v2).

The idea is to create arrays/objects containing integers/floats/strings.

One use would be for a Range function.
traditional for loop: for i = a to b (step c) possibilities - AutoHotkey Community