Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: ironhead on December 01, 2009, 04:25:25 pm

Title: Pre-build Squirrel scripting question
Post by: ironhead on December 01, 2009, 04:25:25 pm
I'm trying to get a pre-build step to check to see if a file exists, to that end I have:

Code
[[ if ( !exist( "svnversion.h" ) ) { printl( "Hello" ); } ]]

But I get an error stating "the index 'exist' does not exist".

Can someone please point out what I'm doing wrong?

Thank you!
Title: Re: Pre-build Squirrel scripting question
Post by: MortenMacFly on December 01, 2009, 05:14:09 pm
Can someone please point out what I'm doing wrong?
"exist" and "printl" are not valid Squirrel script functions. They are not even C++ btw...
Title: Re: Pre-build Squirrel scripting question
Post by: ironhead on December 01, 2009, 05:48:50 pm
"exist" and "printl" are not valid Squirrel script functions. They are not even C++ btw...

Hrmm...  interesting, I got 'exist' and 'printl' from:

http://www.ibm.com/developerworks/aix/library/au-spunix_squirrel/index.html (http://www.ibm.com/developerworks/aix/library/au-spunix_squirrel/index.html)

Is there definitive guide as to what functions are provided in the version of squirrel used by C::B?
Title: Re: Pre-build Squirrel scripting question
Post by: ironhead on December 01, 2009, 07:06:21 pm
I tried using the 'file' command:

Code
[[ local svnfile = file("svnversion.h", "r"); if ( !svnfile ) { printl( "Hello" ); } ]]

But also received an error: "the index 'file' does not exist"

Yet, as I understand it, it should have worked (at least attempted to read the file):

http://squirrel-lang.org/doc/sqstdlib2.html#d0e159 (http://squirrel-lang.org/doc/sqstdlib2.html#d0e159)
Title: Re: Pre-build Squirrel scripting question
Post by: ironhead on December 02, 2009, 12:42:50 pm
I've got it to work:

Code
[[ local svnfile = _T("svnversion.h"); local svncmd = _T("cmd /c svn info --revision HEAD | grep Revision | sed -f svnversion.sed > svnversion.h"); if ( !IO.FileExists(svnfile) ) { IO.Execute(svncmd); } ]]

My question is, is IO.Execute the best way to make a system call?
Title: Re: Pre-build Squirrel scripting question
Post by: MortenMacFly on December 02, 2009, 03:26:13 pm
My question is, is IO.Execute the best way to make a system call?
Yes. Notice the C::B script security must be configured correctly to allow (system) IO calls.
Title: Re: Pre-build Squirrel scripting question
Post by: ironhead on December 02, 2009, 03:52:45 pm
My question is, is IO.Execute the best way to make a system call?
Yes. Notice the C::B script security must be configured correctly to allow (system) IO calls.
Agreed...  I had to allow the script to launch executables

Is it possible to have the Pre-build step call a script?  I tried with:

Code
[[ Include(_T("svnversion.script")); GenerateSvnVersion(); ]]

Where svnversion.script contained the GenerateSvnVersion() function.  It gave me an error when I tried this implementation.