Difference between revisions of "Scripting commands"

From Code::Blocks
Line 821: Line 821:
 
!Arguments
 
!Arguments
 
!Remarks
 
!Remarks
 +
|-
 +
 +
|-
 +
| void || Assign || const wxFileName ||
 +
|-
 +
 +
|-
 +
| void || Assign || const wxString, wxPathFormat || arg1=full path, arg2=wxPATH_NATIVE ...
 
|-
 
|-
  

Revision as of 19:13, 6 February 2013

Scripting is no good if all you can do is use the scripting language's built-in commands only. The host application (Code::Blocks) needs to expose parts of its internals to scripts, so scripts can use and control the host.

Code::Blocks has exposed a very large chunk of its SDK to scripts. This makes scripting in Code::Blocks nearly as powerful as native code (C++).

In this page all the exported constants, functions and classes are documented as a quick reference. For detailed documentation on each function/class, refer to the Code::Blocks SDK documentation.


NOTE: Please remember that Squirrel is typeless. Data types mentioned below are only used for documentation purposes.

NOTE: Please keep in mind that if a function has default parameters in C++ (which can be ommitted), you still have to type them for scripts (for e.g. exposed wxWidgets functionality). This means you *have* to use e.g. wxFileName.GetFullPath(wxPATH_NATIVE) instead of e.g only wxFileName.GetFullPath().

Application object

The application object is accessed through the variable named App. Currently it has no bound functions...


Global functions

Return value Name Arguments Remarks
void Log wxString logs to the application log
void LogDebug wxString logs to the debug log
void LogWarning wxString logs a warning
void LogError wxString logs an error
int Message wxString,wxString,int arg1=msg, arg2=caption, arg3=buttons; see API docs for cbMessageBox()
void ShowMessage wxString
void ShowWarning wxString
void ShowError wxString
void ShowInfo wxString
wxString ReplaceMacros wxString,bool
ScriptingManager* GetScriptingManager
ProjectManager* GetProjectManager
EditorManager* GetEditorManager
ConfigManager* GetConfigManager
UserVariableManager* GetUserVariableManager
CompilerFactory* GetCompilerFactory
wxArrayString GetArrayFromString wxString,wxString,bool
wxString GetStringFromArray wxArrayString,wxString,bool
wxString EscapeSpaces wxString
wxString UnixFilename wxString, int arg1=filename, arg2=wxPATH_NATIVE, wxPATH_WIN, ...
FileType FileTypeOf wxString
wxString URLEncode wxString
void NotifyMissingFile wxString
int GetPlatformsFromString wxString
wxString GetStringFromPlatforms int,bool
void InfoWindow wxString,wxString,int,int pop-up box in the lower right, see infowindow.h
wxString GetFolder int see API docs for ConfigManager::GetFolder()
wxString LocateDataFile wxString, int see API docs for ConfigManager::LocateDataFile()
bool InstallPlugin wxString,bool, bool Install a binary plugin
int ExecuteToolPlugin wxString Execute a tool plugin (found in Plugins menu)
int ConfigureToolPlugin wxString Configure a tool plugin (found in Plugins menu)
void CallMenu wxString Call a menu entry describing its path using slashes (e.g. "/Valgrind/Run Valgrind::MemCheck")
void Include wxString similar to C/C++ #include "name"
int Require wxString script filename
bool IsNull void*
wxString _T const char* basically this is the wxString constructor
wxString _ const char* the same as _T, but should be used for translatable strings
bool wxLaunchDefaultBrowser wxString
wxColour wxGetColourFromUser [wxColour]
long wxGetNumberFromUser wxString,wxString,wxString
wxString wxGetPasswordFromUser wxString,wxString,wxString
wxString wxGetTextFromUser wxString,wxString,wxString
long wxString_ToLong wxString const

ScriptingManager

Return value Name Arguments Remarks
bool RegisterScriptMenu wxString, wxString registers the script file (arg1) under a menu item (arg2).

e.g. GetScriptingManager().RegisterScriptMenu(_T("sample.script"), _T("Scripts/Sample script"));

Notes about the RegisterScriptMenu function:

  • The second argument (menu item) is a string containing the full menu path to create the menu item. The path separator is a slash (/). For example, the string "Settings/Sample menu/Sample item" would create the menu path "Settings->Sample menu->Sample item".
  • When each part of the path is evaluated, it is checked whether it starts with a number followed by a colon (:). If so then this is considered to be a menu index in the parent menu and the menu is inserted at that index instead of being appended to the menu. The number and colon are removed from the string.
  • If the menu item starts with a dash (-), then a separator line is prepended in the menu before the menu item (e.g. "Scripts/-Sample script").
  • For your convenience, all menu items created using this function have one extra functionality: if you keep the SHIFT key pressed while clicking on any of these "script menu items", instead of running the attached script, Code::Blocks will open it in the editor for you to view/edit :).
  • Have a look at the startup script example.


ConfigManager

Return value Name Arguments Remarks
int Read int,int
bool Read bool,bool
float Read float,float
wxString Read wxString,wxString
void Write int,int
void Write bool,bool
void Write float,float
void Write wxString,wxString[,bool]


ProjectManager

Return value Name Arguments in Prototype Remarks
wxString GetDefaultPath ( )
void SetDefaultPath (const wxString& path)
cbProject* GetActiveProject ( )
int GetProjectCount ( )
cbProject* GetProject (int)
void SetProject (cbProject* project, bool refresh = true)
bool LoadWorkspace (const wxString& filename = DEFAULT_WORKSPACE)
bool SaveWorkspace ( )
bool SaveWorkspaceAs (const wxString& filename)
bool CloseWorkspace ( )
cbProject* IsOpen (const wxString& filename)
cbProject* LoadProject (const wxString& filename, bool activateIt = true)
bool SaveProject (cbProject* project)
bool SaveProjectAs (cbProject* project)
bool SaveActiveProject ( )
bool SaveActiveProjectAs ( )
bool SaveAllProjects ( )
bool CloseProject (cbProject* project, bool dontsave = false, bool refresh = true)
bool CloseActiveProject (bool dontsave = false)
bool CloseAllProjects (bool dontsave = false)
cbProject* NewProject (const wxString& filename = wxEmptyString)
int AddFileToProject (const wxString& filename, cbProject* project = 0L, int target = -1)
int AskForBuildTargetIndex (cbProject* project = 0L)
void RebuildTree ( )
bool AddProjectDependency (cbProject* base, cbProject* dependsOn)
void RemoveProjectDependency (cbProject* base, cbProject* doesNotDependOn)
void ClearProjectDependencies (cbProject* base)
void RemoveProjectFromAllDependencies (cbProject* base)
ProjectsArray* GetDependenciesForProject (cbProject* base)
void ConfigureProjectDependencies (cbProject* base = 0)

EditorManager

Return value Name Arguments in Prototype Remarks
void Configure ( )
cbEditor* New (const wxString& newFileName = wxEmptyString)
cbEditor* Open (const wxString& filename)
cbEditor* IsBuiltinOpen (const wxString& filename)
cbEditor* GetBuiltinEditor (int index)
cbEditor* GetBuiltinActiveEditor ( )
EditorBase* GetActiveEditor ( )
void ActivateNext ( )
void ActivatePrevious ( )
bool SwapActiveHeaderSource ( )
bool CloseActive (bool dontsave = false)
bool Close (int index,bool dontsave = false),(EditorBase* editor,bool dontsave = false)
bool CloseAll (bool dontsave=false)
bool Save (int index)
bool SaveActive ( )
bool SaveAs (int index)
bool SaveActiveAs ( )
bool SaveAll ( )
int ShowFindDialog (bool replace, bool explicitly_find_in_files = false)

UserVariableManager

Return value Name Arguments in Prototype Remarks
bool Exists (const wxString& variable)

IO namespace

Return value Name Arguments in Prototype Remarks
bool DirectoryExists (const wxString& dir)
wxString SelectDirectory (const wxString& message, const wxString& initialPath, bool showCreateDirButton)
bool CreateDirectory (const wxString& full_path, int perms) arg1=dir, arg2=permissions
bool RemoveDirectory (const wxString& src)
bool CopyFile (const wxString& src, const wxString& dst, bool overwrite) src,dest,overwrite
bool RenameFile (const wxString& src, const wxString& dst) old,new
bool RemoveFile (const wxString& src)
bool FileExists (const wxString& file)
wxString SelectFile (const wxString& title, const wxString& defaultFile, const wxString& filter)
wxString ReadFileContents (const wxString& filename)
bool WriteFileContents (const wxString& filename, const wxString& contents) filename,contents
int Execute (const wxString& command)
wxString ExecuteAndGetOutput (const wxString& command)
wxString ExecuteAndGetOutputAndError (const wxString& command, bool prepend_error) if 'prepend_error' is true gives an error string
wxString GetCwd ( )
void SetCwd (const wxString& dir) directory (currently working directory)


Notes: The namespaces are accesses by prepending it's name (e.g. "IO.") to the scripting function, e.g. "IO.DirectoryExists(...)". "::" is only used when declaring the members of the namespace. The functions in bold are going through the scripts security layer so there is no guarantee calling them will succeed. You should always examine the return value... There exists one constant too, named allowInsecureScripts, which allow you to test whether Code::Blocks was compiled with the functions going through the security layer.

CompilerFactory

Return value Name Arguments in Prototype Remarks
bool IsValidCompilerID (const wxString& id)
int GetCompilerIndex (const wxString& id)
wxString GetDefaultCompilerID ( )
wxString GetCompilerVersionString (const wxString& Id)
bool CompilerInheritsFrom ( )

wxString

Return value Name Arguments Remarks
bool operator+
bool operator<
bool operator<=
bool operator>=
bool operator>
int Find wxString
bool Matches wxString
void AddChar char
char GetChar int
bool IsEmpty
int Length
int length same as Length()
int len same as Length()
int size same as Length()
wxString Lower
wxString LowerCase same as Lower()
void MakeLower
wxString Upper
wxString UpperCase same as Upper()
void MakeUpper
wxString Mid int,int
wxString Remove int,int
void RemoveLast
int Replace wxString,wxString[,bool]
wxString Right int
wxString AfterFirst char
wxString AfterLast char
wxString BeforeFirst char
wxString BeforeLast char

NOTE: Is instantiated in a script using: local my_wxstring = ::wxString();

wxArrayString

Return value Name Arguments Remarks
void Add wxString, size_t arg1=string, arg2=number of copies to add
void Clear
int GetCount
int Index wxString -1 If not found
wxString Item int not work with wx 2.9.x ?!

NOTE: Is instantiated in a script using: local my_wxarraystring = ::wxArrayString();

wxColour

Return value Name Arguments Remarks
byte Red
byte Green
byte Blue
void Set byte,byte,byte

NOTE: Is instantiated in a script using: local my_wxcolour = ::wxColour();

wxFileName

''''UNDER CONSTRUCTION''''

'WARNING This is an attempt to open a sub-page 'wxFileName' in the 'Scripting commands''

Return value Name Arguments Remarks
void Assign const wxFileName
void Assign const wxString, wxPathFormat arg1=full path, arg2=wxPATH_NATIVE ...
void SetEmptyExt
void SetFullName wxString
void SetName wxString
void SetVolume wxString

NOTE: Is instantiated in a script using: local my_filename = ::wxFileName()

ProjectFile

Return value Name Arguments in Prototype Remarks
void AddBuildTarget (const wxString& targetName)
void RenameBuildTarget (const wxString& oldTargetName, const wxString& newTargetName)
void RemoveBuildTarget (const wxString& targetName)
wxString GetBaseName ( )
wxString GetObjName ( )
void SetObjName (const wxString& targetName)
cbProject* GetParentProject ( )
wxString GetCustomBuildCommand (const wxString& compilerId)
void SetCustomBuildCommand (const wxString& compilerId, const wxString& newBuildCommand)
bool GetUseCustomBuildCommand (const wxString& compilerId)
void SetUseCustomBuildCommand (const wxString& compilerId, bool useCustomBuildCommand)
wxFileName file (variable)
wxString relativeFilename (variable)
wxString relativeToCommonTopLevelPath (variable)
bool compile (variable)
bool link (variable)
int weight (variable)
wxString compilerVar (variable)
wxArrayString buildTargets (variable)

CompileOptionsBase

Return value Name Arguments in Prototype Remarks
void AddPlatform (int platform) windows,unix,mac
void RemovePlatform (int platform)
void SetPlatforms (int platform)
int GetPlatforms
bool SupportsCurrentPlatform
void SetLinkerOptions (const wxArrayString& linkerOpts)
void SetLinkLibs (const wxArrayString& linkLibs)
void SetCompilerOptions (const wxArrayString& compilerOpts)
void SetIncludeDirs (const wxArrayString& includeDirs)
void SetResourceIncludeDirs (const wxString& option)
void SetLibDirs (const wxArrayString& libDirs)
void SetCommandsBeforeBuild (const wxArrayString& commands)
void SetCommandsAfterBuild (const wxArrayString& commands)
wxArrayString GetLinkerOptions
wxArrayString GetLinkLibs
wxArrayString GetCompilerOptions
wxArrayString GetIncludeDirs
wxArrayString GetResourceIncludeDirs
wxArrayString GetLibDirs
wxArrayString GetCommandsBeforeBuild
wxArrayString GetCommandsAfterBuild
bool GetModified
void SetModified (bool modified)
void AddLinkerOption (const wxString& option)
void AddLinkLib (const wxString& lib)
void AddCompilerOption (const wxString& option)
void AddIncludeDir (const wxString& option)
void AddResourceIncludeDir (const wxString& option)
void AddLibDir (const wxString& option)
void AddCommandsBeforeBuild (const wxString& command)
void AddCommandsAfterBuild (const wxString& command)
void RemoveLinkerOption (const wxString& option)
void RemoveLinkLib (const wxString& lib)
void RemoveCompilerOption (const wxString& option)
void RemoveIncludeDir (const wxString& option)
void RemoveResourceIncludeDir (const wxString& option)
void RemoveLibDir (const wxString& option)
void RemoveCommandsBeforeBuild (const wxString& command)
void RemoveCommandsAfterBuild (const wxString& command)
bool GetAlwaysRunPostBuildSteps
void SetAlwaysRunPostBuildSteps (bool always)
void SetBuildScripts (const wxArrayString& scripts)
wxArrayString GetBuildScripts
void AddBuildScript (const wxString& script)
void RemoveBuildScript (const wxString& script)
bool SetVar (const wxString& key, const wxString& value, bool onlyIfExists = false)
wxString GetVar (const wxString& key)
bool UnsetVar (const wxString& key)
void UnsetAllVars ( )

CompileTargetBase

Extends CompileOptionsBase.

Return value Name Arguments Remarks
void SetTargetFilenameGenerationPolicy enum, enum
wxString GetFilename
wxString GetTitle
void SetTitle wxString
void SetOutputFilename wxString
void SetWorkingDir wxString
void SetObjectOutput wxString
void SetDepsOutput wxString
OptionsRelation GetOptionRelation OptionsRelationType
void SetOptionRelation OptionsRelationType,OptionsRelation
wxString GetWorkingDir
wxString GetObjectOutput
wxString GetDepsOutput
wxString GetOutputFilename
wxString SuggestOutputFilename
wxString GetExecutableFilename
wxString GetDynamicLibFilename
wxString GetDynamicLibDefFilename
wxString GetStaticLibFilename
wxString GetBasePath
void SetTargetType TargetType
TargetType GetTargetType
wxString GetExecutionParameters
void SetExecutionParameters wxString
wxString GetHostApplication
void SetHostApplication wxString
void SetCompilerID wxString
wxString GetCompilerID
wxString GetMakeCommandFor enum
void SetMakeCommandFor enum,wxString
bool MakeCommandsModified

ProjectBuildTarget

Extends CompileTargetBase.

Return value Name Arguments Remarks
cbProject* GetParentProject
wxString GetFullTitle
wxString GetExternalDeps
void SetExternalDeps wxString
void SetAdditionalOutputFiles wxString
wxString GetAdditionalOutputFiles
bool GetIncludeInTargetAll
void SetIncludeInTargetAll bool
bool GetCreateDefFile
void SetCreateDefFile bool
bool GetCreateStaticLib
void SetCreateStaticLib bool
bool GetUseConsoleRunner
void SetUseConsoleRunner bool
ProjectFile* GetFile int returns a file from the target
int GetFilesCount returns number of files of target

cbProject

Extends CompileTargetBase.

Return value Name Arguments Remarks
bool GetModified
void SetModified bool
wxString GetMakefile
void SetMakefile wxString
bool IsMakefileCustom
void SetMakefileCustom bool
bool CloseAllFiles bool
bool SaveAllFiles
bool Save
bool SaveLayout
bool LoadLayout
bool ShowOptions Display the project options dialog
wxString GetCommonTopLevelPath
int GetFilesCount Returns number of files in the project
ProjectFile* GetFile int
ProjectFile* GetFileByFilename wxString,bool,bool See API docs for cbProject::GetFileByName
bool RemoveFile int
ProjectFile* AddFile int,wxString,bool,bool,int See API docs for cbProject::AddFile
int GetBuildTargetsCount
ProjectBuildTarget* GetBuildTarget int
ProjectBuildTarget* AddBuildTarget wxString
bool RenameBuildTarget int,wxString
ProjectBuildTarget* DuplicateBuildTarget int,wxString
bool RemoveBuildTarget int
bool ExportTargetAsProject int
bool BuildTargetValid bool
wxString GetFirstValidBuildTargetName bool
void SetDefaultExecuteTarget wxString
wxString GetDefaultExecuteTarget wxString
bool SetActiveBuildTarget wxString
wxString GetActiveBuildTarget
int SelectTarget int,bool
ProjectBuildTarget* GetCurrentlyCompilingTarget
void SetCurrentlyCompilingTarget ProjectBuildTarget*
PCHMode GetModeForPCH
void SetModeForPCH PCHMode
void SetExtendedObjectNamesGeneration bool
bool GetExtendedObjectNamesGeneration
void SetNotes wxString
wxString GetNotes
void SetShowNotesOnLoad bool
bool GetShowNotesOnLoad
void ShowNotes bool,bool
void AddToExtensions wxString
bool DefineVirtualBuildTarget wxString,wxArrayString
bool HasVirtualBuildTarget wxSring
bool RemoveVirtualBuildTarget wxString
wxArrayString GetVirtualBuildTargets
wxArrayString GetVirtualBuildTargetGroup wxString
wxArrayString GetExpandedVirtualBuildTargetGroup wxString
bool CanAddToVirtualBuildTarget wxSring,wxString
void SetTitle wxSring

EditorBase

Return value Name Arguments Remarks
wxString GetFilename
void SetFilename wxString
wxString GetShortName
bool GetModified
void SetModified bool
wxString GetTitle
void SetTitle wxString
void Activate
bool Close
bool Save
bool IsBuiltinEditor
bool ThereAreOthers
void GotoLine int,bool
void ToggleBreakpoint int,bool
bool HasBreakpoint int
void GotoNextBreakpoint
void GotoPreviousBreakpoint
void ToggleBookmark int,bool
bool HasBookmark int
void GotoNextBookmark
void GotoPreviousBookmark
void Undo
void Redo
void Cut
void Copy
void Paste
bool CanUndo
bool CanRedo
bool CanPaste
bool HasSelection


cbEditor

Extends EditorBase.

Return value Name Arguments Remarks
void SetEditorTitle wxString
ProjectFile* GetProjectFile
bool Save
bool SaveAs
void FoldAll
void UnfoldAll
void ToggleAllFolds
void FoldBlockFromLine int
void UnfoldBlockFromLine int
void ToggleFoldBlockFromLine int
int GetLineIndentInSpaces int
wxString GetLineIndentString int
void Touch
bool Reload bool
void Print bool,PrintColourMode,bool
void AutoComplete
bool AddBreakpoint int,bool
bool RemoveBreakpoint int,bool
void SetText wxString this is not present in cbEditor; included to help scripts edit text
wxString GetText this is not present in cbEditor; included to help scripts edit text

Constants

Constant Type Remarks
PLATFORM int this defines the platform Code::Blocks is currently running on. It is equal to only one of the following PLATFORM_* constants
PLATFORM_MSW int All Windows platforms
PLATFORM_GTK int All GTK platforms (Linux, BSD, Solaris, Darwin, etc.)
PLATFORM_MAC int All Mac platforms
PLATFORM_OS2 int OS/2 platform
PLATFORM_X11 int All X11 platforms
PLATFORM_UNKNOWN int Unknown platform. Please inform us if PLATFORM == PLATFORM_UNKNOWN so we can make this platform known too ;)
Message dialog flags
wxOK int Flag for Message() 's third argument (flags).
wxYES_NO int -"-
wxCANCEL int -"-
wxICON_QUESTION int -"-
wxICON_INFORMATION int -"-
wxICON_WARNING int -"-
wxICON_ERROR int -"-
Message dialog return values
wxID_OK int
wxID_YES int
wxID_NO int
wxID_CANCEL int
enum OptionsRelationType
ortCompilerOptions enum
ortLinkerOptions enum
ortIncludeDirs enum
ortLibDirs enum
ortResDirs enum
enum OptionsRelation
orUseParentOptionsOnly enum
orUseTargetOptionsOnly enum
orPrependToParentOptions enum
orAppendToParentOptions enum
enum TargetType
ttExecutable enum
ttConsoleOnly enum
ttStaticLib enum
ttDynamicLib enum
ttCommandsOnly enum
enum MakeCommand
mcClean enum
mcDistClean enum
mcBuild enum
mcCompileFile enum
enum PCHMode
pchSourceDir enum
pchObjectDir enum
pchSourceFile enum
enum PrintScope
psSelection enum
psActiveEditor enum
psAllOpenEditors enum
enum PrintColourMode
pcmBlackAndWhite enum
pcmColourOnWhite enum
pcmInvertColours enum
pcmAsIs enum
enum TemplateOutputType
wizProject enum TemplateOutputType::totProject
wizTarget enum TemplateOutputType::totTarget
wizFiles enum TemplateOutputType::totFiles
wizCustom enum TemplateOutputType::totCustom
Other constants
wxFILE_SEP_PATH wxString Path separator. "\" for windows, "/" for all other platforms
File extensions (e.g. "cbp")
EXT_WORKSPACE wxString
EXT_CODEBLOCKS wxString
EXT_DEVCPP wxString
EXT_MSVC6 wxString
EXT_MSVC6_WORKSPACE wxString
EXT_MSVC7 wxString
EXT_MSVC7_WORKSPACE wxString
EXT_D wxString
EXT_F wxString
EXT_F77 wxString
EXT_F95 wxString
EXT_CPP wxString
EXT_C wxString
EXT_CC wxString
EXT_CXX wxString
EXT_HPP wxString
EXT_H wxString
EXT_HH wxString
EXT_HXX wxString
EXT_OBJECT wxString
EXT_XRCRESOURCE wxString
EXT_STATICLIB wxString
EXT_DYNAMICLIB wxString
EXT_EXECUTABLE wxString
EXT_RESOURCE wxString
EXT_RESOURCEBIN wxString
EXT_XML wxString
EXT_SCRIPT wxString
File extensions with leading dot (e.g. ".cbp")
DOT_EXT_WORKSPACE wxString
DOT_EXT_CODEBLOCKS wxString
DOT_EXT_DEVCPP wxString
DOT_EXT_MSVC6 wxString
DOT_EXT_MSVC6_WORKSPACE wxString
DOT_EXT_MSVC7 wxString
DOT_EXT_MSVC7_WORKSPACE wxString
DOT_EXT_D wxString
DOT_EXT_F wxString
DOT_EXT_F77 wxString
DOT_EXT_F95 wxString
DOT_EXT_CPP wxString
DOT_EXT_C wxString
DOT_EXT_CC wxString
DOT_EXT_CXX wxString
DOT_EXT_HPP wxString
DOT_EXT_H wxString
DOT_EXT_HH wxString
DOT_EXT_HXX wxString
DOT_EXT_OBJECT wxString
DOT_EXT_XRCRESOURCE wxString
DOT_EXT_STATICLIB wxString
DOT_EXT_DYNAMICLIB wxString
DOT_EXT_EXECUTABLE wxString
DOT_EXT_RESOURCE wxString
DOT_EXT_RESOURCEBIN wxString
DOT_EXT_XML wxString
DOT_EXT_SCRIPT wxString

See also