Skip to content
⌘ NSIS Forum Archive

nsArray plug-in

54 posts

Afrow UK#
New version:
1.1.1.4 - 3rd September 2012
* Replaced Set /list with SetList.
* Replaced Remove /list with RemoveList.
Please update your code accordingly if you switch to the new version.

Stu
T.Slappy#
What is correct usage of nsArray::Get? I think nsArray corrupts my stack but I cannot find the problem.

This is my code - Is this usage correct?
1)
ClearErrors
nsArray::Get UrlTree $CompleteGroup
${If} ${Errors}
    ${DebugMsg} "UrlTree($CompleteGroup) is not set!"
${Else}
    Pop $CompleteTotal
    ; There are some files
${EndIf} 

In documentation I saw this usage:
2)
  ClearErrors
  nsArray::Get MyArray 2
  Pop $R0
  ${If} ${Errors}
    DetailPrint `Error!`
  ${EndIf} 

So in my example (1): I do POP only if ${Errors} is fine.

But the docs say (2): do the POP, then check ${Errors}.

I have many values in stack, so I think POP in (2) will remove element from stack even in case the nsArray does not contain required element.

Is this assumption correct?
Afrow UK#
Yes that is an error in the example script. It will not push anything onto the stack if an error occurs (element not found).

Stu
Fretje#edited
Is there a way to sort an array with version numbers using the versioncompare logic? I'm using "numeric" now, and it doesn't give the right result:

* 4.2.6_32
* 5.1.10.2_32
* 5.1.8.2_32
* 5.1.9.0_32

should be:

* 4.2.6_32
* 5.1.8.2_32
* 5.1.9.0_32
* 5.1.10.2_32

fretje
Afrow UK#
See attached.

Stu
Marshallx7#
Couldn't find this documented anywhere and I think it is worth mentioning:
/at= does not work with the Set command.
Further more /key= only works on keynames, not indexes, as follows:

nsArray::Set "myArray" "0"
nsArray::Set "myArray" "1"
nsArray::Set "myArray" "2"
nsArray::Set "myArray" "3"
;array now = {"0", "1", "2", "3"}
nsArray::Remove "myArray" /at=1
;array now = {"0", "2", "3"}
nsArray::Set "myArray" /key=2 "three"
;array now = {"0", "three", "3"}
Because elements with no specified keyname are presumably given a keyNAME of their initial index.
The above is correct behaviour as you might have keynames that consist only of numbers.

If you want to have /at= functionality with the Set command then you can add it yourself using the following macro

!macro ArraySetAt arrayname index value
Push $R0
ClearErrors
nsArray::Get "${arrayname}" "/at=${index}"
${IfNot} ${Errors}
Pop $R0 ;key
Exch $R0 ;discard value
Pop $R0 ;discard value
nsArray::Set "${arrayname}" "/key=$R0" "${value}"
${EndIf}
Pop $R0
!macroend
Afrow UK#
Originally Posted by Marshallx7 View Post
/at= does not work with the Set command.
That is correct - the readme does not show any uses of /at= with the Set instruction, but I could add it.
Originally Posted by Marshallx7 View Post
Further more /key= only works on keynames, not indexes
This is not true. Your array after the Remove call is:
myArray = {0 => 0, 2 => 2, 3 => 3}
After your Set call, it becomes:
myArray = {0 => 0, 2 => three, 3 => 3}
There is no distinction between numeric keys and string keys. It is just that numeric keys are assigned when no key is specified when adding elements.

Edit: You probably assumed that removing element with index 1 would result in the indexes after it being decreased by 1 also. This does not happen in hashed arrays because then the association is lost. I suppose the plug-in needs a reindex function. For example in PHP you'd use array_values().

Stu
Marshallx7#
Sorry I wasn't clear before, yes - what you say the arrays would be is what I concur with, I just didn't mention the keynames.

I fully accept that this is intended behaviour, and I did run my own tests to be sure, because I need Set /at functionality.

To make my position clear to anyone reading, there are NO bugs in nsArray (that I can see) - just Set /at functionality is not (presently) a feature (but you can emulate it using my macro above).

A reindex method might be useful, but I imagine it is more resource intensive than a Set /at command. Using Get /at, Remove /at and Set /at would mean a reindex is not necessary, because you can then choose to either use associative keynames (without /at) or positional indexes (with /at)
Afrow UK#
New version:
1.1.1.5 - 26th May 2013
* Added /at= for Set and SetList functions.
* Fixed SetList and RemoveList not setting the error flag on error if one element was not set/added or removed successfully.
* Added Iterate function which replaces iteration using Get with /next, /prev and /reset.
Note that if you use iteration using the Get function (/next, /prev and /reset) you must switch to the Iterate function (see the readme for usage).

Stu
Afrow UK#
New version:
1.1.1.6 - 1st June 2013
* Fixed memory access violation in Iterate function due to NULL pointer when an invalid array name is supplied.
Stu
Yathosho#
do you plan to add multidimensional arrays in the future? i guess an (un)serialize option like in your json plugin would do.
badcom#
Still compatible?

Hello,

I have tried using this plugin but it's not working as it should.

When I try to return the values I had set, it returns only the first letter of the string.

I have tried using Set, SetList, but no luck.

I'm using HM NIS Edit 2.0.3.

Let me know if you need more details.

Thank you!
Afrow UK#
It sounds like you're using the Unicode plug-in instead of the ANSI plug-in. There's two DLLs in the Zip file. You need to use the correct plug-in depending on your NSIS version/script.

Stu
badcom#
Still not working

Thanks for your quick response!

I don't think this is the cause of the problem because if I unzip NsArray.zip and edit "Examples\nsArray\nsArray.nsi" to read as below:


!include nsArray.nsh

OutFile nsArray.exe
Name nsArray
ShowInstDetails show
XPStyle on
RequestExecutionLevel user

Page Components
Page InstFiles

Section

nsArray::SetList MyArray appbuttonc_aurora appbuttonc_blue appbuttonc_black appbuttonc_palemo appbuttonc_transp appbuttonc_green appbuttonc_gray appbuttonc_purple appbuttonc_white appbuttonc_red /end

nsArray::Get MyArray 0
Pop $R0
DetailPrint `MyArray[0] is $R0`

SectionEnd
When I run nsArray.exe, the output is 'MyArray[0] is a'

Have I done anything wrong? I tried deleting the Unicode dir and got the same result.
simplix#
Dear Stu! Please add x64 version of the plugin, if it is not difficult. By the way the source code is now an older version 1.1.1.5.
Afrow UK#
Uploaded a new version with x64 builds and updated the versions in the source/DLL.



Stu
pkonduru#
Hi Afrow,

How can I make my array global? I use the nsArray plugin in my oninit function or say some custom page. How can I make the array visible in other custom pages or functions?