Logical extensions

While working on a new NSIS header file to properly handle Windows versions, I thought of something really cool. The LogicLib is a cool library dselkirk and eccles wrote a long time ago. It allows you to avoid using labels, Goto, StrCmp, IntCmp, relative jumps and other cool beans. Instead, you get a bunch of macros wrapped in defines that make your life so much easier.

${If} $0 == "good"
  DetailPrint "it's not evil"

It struck me while I was thinking of the interface I want to use for the new version checking stuff, I originally started with a function taking an argument. However, functions and header files don’t work too well together. A warning is spewed, if the function isn’t used. The code was also meant to be short, as there isn’t too much to do. So, combine those two together and of course you get macros. But what will the macro get? Labels to jump to? What if the user passes relative jumps? What if the user wants to skip a label definition and just jump to the next line? Why can’t it be like LogicLib? Because these checks don’t fit into LogicLib.nsh? So what? Why can’t I define more tests for LogicLib? Who said I can’t? I can.

And it turns out adding more tests to LogicLib is quite easy as well. Just define a macro with a name prefixed with an underscore and give it four parameters. Two operands and jump labels for true and false. The LogicLib will handle creating the labels and all that is left for this little macro is the actual test.

!macro _= _a _b _t _f
  IntCmp `${_a}` `${_b}` `${_t}` `${_f}` `${_f}`

The end result is quite cool. Instead of yet another new interface for another functionality, there are just a few new operators for LogicLib.

${If} ${AtLeastWin2000}
  DetailPrint "2000 or better. Fun!"

The new code is available on CVS for your eager browsing. Crave code. Craving is good.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.