Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   Shortening the Asc macro (wiki/Asc) (http://forums.winamp.com/showthread.php?t=282266)

MSG 28th November 2007 13:11

Shortening the Asc macro (wiki/Asc)
 
A very short question, really: I want to get the ascii-number of the first character of a string. so I've taken a look at the Asc macro on the wiki. But I'm wondering if it can be made shorter. Can I use
PHP Code:

System::Call "*(&t1 r11)i.r11"
System::Call "*$R1(&i1 .r11)" 

Without creating memory leaks or whatnot? I'm skipping the System::Free command because I'm using only one variable now, but I'm not entirely sure if that's legal.


Edit: After discussion with Anders, I guess the above is indeed not correct. $R1 is made to point at some allocated memory, which is afterwards not freed. Should be:
PHP Code:

System::Call "*(&t1 r12)i.r11"
System::Call "*$11(&i1 .r12)"
System::Free $R1 


kichik 28th November 2007 21:21

As Anders probably have noted, your first System::Call line allocates a buffer, so without System::Free memory will leak.

To do this without any allocation, you can use:
code:
StrCpy $0 asdasd
Math::Script "r0 = c(r0[0])"
DetailPrint $0



All times are GMT. The time now is 18:04.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.