Code::Blocks

User forums => Using Code::Blocks => Topic started by: JATothrim on October 14, 2011, 01:53:17 am

Title: CodeBlocks Scripting
Post by: JATothrim on October 14, 2011, 01:53:17 am
Hey!

I was completly suprised that the IDE included a complete (http://www.squirrel-lang.org/) scripting language after using it more than two years. :lol:
I was wondering how I could execute a script when the Code::Blocks IDE quits? Executing script on startup is clear as it's documented on manuals.
I'm planing to use ImDisk (http://www.ltr-data.se/opencode.html/#ImDisk) to mount RAM Disk when the IDE starts. But as i said, I need to backup the disk contents and unmount the volume when the IDE quits.
I'm not asking how to use the ImDisk tool, but rather help for writing plugin script for the IDE to use the tool. C++ goes okay but squirrel doesn't.  :(

Editor commands... (http://wiki.codeblocks.org/index.php?title=Scripting_commands#cbEditor)
Scriptplugin template:
Code: [Select]
class RAMDiskMount extends cbScriptPlugin
{
    // mandatory to setup the plugin's info
constructor()
{
info.name = _T("Mount RAM DISK");
info.title = _T("Mount RAM DISK");
::Log(_T("Mounted 512MiB RAM DISK"));
}

    // how do I run something on "unregisterplugin"?

   
}

// this call actually registers the script plugin with Code::Blocks
RegisterPlugin(RAMDiskMount());

Btw. compiling using ramdisk is ridiculously fast.  :wink:
PS: sorry for typos, I'm not perfect on english.
-Registeration Captcha is funny. : D
Title: Re: CodeBlocks Scripting
Post by: oBFusCATed on October 14, 2011, 02:13:43 am
You have to handle the cbEVT_APP_START_SHUTDOWN,
but there is not script binding for it, so you'll have to modify C::B and then provide a patch we can apply.
Here you'll find some docs about script binding: http://wiki.codeblocks.org/index.php?title=Script_bindings

Another option is to make a shutdown.script, which is executed in MainFrame::OnApplicationClose or something more suitable.
This is the simpler approach and it will make the starting/shutdown symmetric...

Title: Re: CodeBlocks Scripting
Post by: MortenMacFly on October 14, 2011, 09:32:54 am
You have to handle the cbEVT_APP_START_SHUTDOWN,
but there is not script binding for it, so you'll have to modify C::B and then provide a patch we can apply.
That is true. And don't worry, a patch shouldn't be too hard, there are plenty of examples. Are you willing to try?
Title: Re: CodeBlocks Scripting
Post by: JATothrim on October 15, 2011, 02:09:04 am
Thank you for the info. I'll probaly just add menu item to unmount the disk and mount the disk at IDE start up - no time to start developing developer tools.  :)
I did succeed to compile the C::B from source on linux, but it was pain. Plus I got it crashing when I pasted some rare unicode chatters to the editor. (on purpose)

One problem is that the ImDisk also requires pure admin powers to be able to load a kernel driver on fly. :D