Archive: Function calls and arguments


Function calls and arguments
Sorry, 2nd post in 2 days. Quick q I hope, I'll give the question, then the problem I'm working on in case I don't explain myself very well.

Question:
a) can I define functions within the scripting language which take arguments without having to use the slightly less than elegant method of using the stack?
b) if not, I can see lots of built in functions which take arguments, can I edit the NSIS source to add my own argument?

Problem:
I want to log every time I place a file on the filesystem in a log that is separate to the install.log. ie I want an additional file list of everything that I install onto the client machine. To do this I could (for each file!) write out to a log and double the number of lines I write:

blah blah filename.file // some code which writes to a log file
File filename.file

Or I could have a function which does it all for me:

putFile filename.file

And tell putFile to a) use the File command to dump the file somewhere and b) write out to a log.

What I _don't_ want to have to do is this:

Push filename.file
putFile

Because that's just as clumsy as the first method.

So can I either using NSIS scripting or altering the source make something whose syntax would be this:

putFile filename.file

Thanks in advance

Rob


Afrow's post is what you're looking for:
http://forums.winamp.com/showthread....light=log+file

You can make it even shorter with the following trick:

!define mymacro "!insertmacro mymacro"
${mymacro} # inserts mymacro

First of all, thanks for helping.

What you showed me is interesting. Unfortunately for me there is a basic reference section, and there are code examples, but nothing in between so I have to do the fsr mandatory thing of messing around with the source til i know it well enough to understand all the code examples :)

So if I chuck that AdvDumpLog function into my code, do I simply need to write for each file:

Push "Unzip.exe"
Push "$INSTDIR\filelist.log"
Call AdvDumpLog

And it will add on another filename within the file? (Obviously changing the filename Unzip.exe to whatever file it is).

Thanks

Rob


Well, actually, as AdvDumpLog uses the first parameter to filter the log, you'd want it to read "extract".

But that's not the post I was referring to. See his next to last post. More specifically, you want:

!macro ADD_FILE FILEIN FILEOUT
File "/oname=${FILEOUT}" "${FILEIN}"
# do stuff with file here
!macroend

Aah sorry, ok. So you reckon the best way is to use a macro to pass the filename to an external program which will handle the log writing?

(Sorry to ask what's probably an obvious question, but I feel I need to be clear :) )

Thanks again

Rob


Oh er hang on, are you actually saying chuck it all in a macro, cos you can write to the file from there? Cos that actually makes more sense now I look at it :)


It doesn't have to be an external program. The macro can call FileWrite too.

The File command logs almost everything it does so it's the easiest (with logging enabled). But you've asked for a function that can be called without the stack ;)