35 #include "sqstdstring.h" 45 int buffer_size = 2048;
47 for (;;buffer_size*=2)
49 tmp_buffer =
new SQChar [buffer_size];
50 int retvalue = vsnprintf(tmp_buffer, buffer_size, s, vl);
51 if (retvalue < buffer_size)
54 msg =
cbC2U(tmp_buffer);
71 s_ScriptErrors << msg;
89 : m_AttachedToMainWindow(false),
90 m_MenuItemsManager(false)
95 SquirrelVM::Init((SquirrelInitFlags)(sqifAll & ~sqifIO));
97 if (!SquirrelVM::GetVMPtr())
98 cbThrow(
_T(
"Can't create scripting engine!"));
115 TrustedScripts::iterator it;
118 if (!it->second.permanent)
122 myMap.
insert(myMap.end(), std::make_pair(key, value));
126 SquirrelVM::Shutdown();
187 s_ScriptErrors.
Clear();
190 SquirrelObject script;
193 script = SquirrelVM::CompileBuffer(
cbU2C(buffer),
cbU2C(debugName));
195 catch (SquirrelError e)
205 SquirrelVM::RunScript(script);
207 catch (SquirrelError e)
222 s_ScriptErrors.
Clear();
236 msg <<
cbC2U(exception->desc);
240 s_ScriptErrors.
Clear();
250 if (
cbMessageBox(
_(
"Script errors have occured...\nPress 'Yes' to see the exact errors."),
265 s_ScriptErrors << output;
282 for (
size_t i = 0; i < ids.GetCount(); ++i)
284 Connect(ids[i], -1, wxEVT_COMMAND_MENU_SELECTED,
285 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
306 item->
SetHelp(
_(
"Press SHIFT while clicking this menu item to edit the assigned script in the editor"));
308 Connect(
id, -1, wxEVT_COMMAND_MENU_SELECTED,
309 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
316 #if wxCHECK_VERSION(3, 0, 0) 349 if (crc == it->second.crc)
351 cbMessageBox(script +
_T(
"\n\n") +
_(
"The script was marked as \"trusted\" but it has been modified " 352 "since then.\nScript not trusted anymore."),
404 ConfigManagerContainer::StringToStringMap::iterator it;
405 for (it = myMap.begin(); it != myMap.end(); ++it)
443 catch (SquirrelError exception)
465 catch (SquirrelError exception)
wxString F(const wxChar *msg,...)
sprintf-like function
wxString m_CurrentlyRunningScriptFile
bool Open(const wxString &filename, wxFile::OpenMode mode=wxFile::read, int access=wxS_DEFAULT)
ConfigManager * GetConfigManager(const wxString &name_space) const
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
void LogWarning(const wxString &msg, int i=app_log)
Scripts folder in base dir.
Scripts folder in user's dir.
const TrustedScripts & GetTrustedScripts()
Access the script trusts container (const).
wxString & append(const wxString &str, size_t pos, size_t n)
bool IsScriptTrusted(const wxString &script)
Security function.
bool ToULong(unsigned long *val, int base=10) const
void TrustScript(const wxString &script, bool permanently)
Security function to trust a script.
void TrustCurrentlyRunningScript(bool permanently)
Security function to trust a script.
std::map< wxString, TrustedScriptProps > TrustedScripts
Script trusts container struct.
wxString AfterFirst(wxUniChar ch) const
static wxString LocateDataFile(const wxString &filename, int search_dirs=sdAllKnown)
Locate a file in an installation- and platform-independent way.
wxWindow * GetAppWindow() const
EditorManager * GetEditorManager() const
DLLIMPORT const wxWX2MBbuf cbU2C(const wxString &str)
Return multibyte (C string) representation of the string.
wxString BeforeFirst(wxUniChar ch, wxString *rest=NULL) const
bool LoadScript(const wxString &filename)
Loads a script.
DLLIMPORT wxString cbReadFileContents(wxFile &file, wxFontEncoding encoding=wxFONTENCODING_SYSTEM)
Reads a wxString from a non-unicode file. File must be open. File is closed automatically.
void Write(const wxString &name, const wxString &value, bool ignoreEmpty=false)
DLLIMPORT wxString UnixFilename(const wxString &filename, wxPathFormat format=wxPATH_NATIVE)
bool IsCurrentlyRunningScriptTrusted()
Security function.
static wxString s_ScriptErrors
DLLIMPORT wxString cbC2U(const char *str)
Return str as a proper unicode-compatible string.
wxFrame * GetAppFrame() const
wxString LoadBufferRedirectOutput(const wxString &buffer)
Loads a string buffer and captures its output.
void RegisterScriptFunctions()
wxString GetErrorString(SquirrelError *exception=nullptr, bool clearErrors=true)
Returns an accumulated error string.
LogManager * GetLogManager() const
wxString Read(const wxString &key, const wxString &defaultVal=wxEmptyString)
void DisplayErrors(SquirrelError *exception=nullptr, bool clearErrors=true)
Display error dialog.
const wxStringCharType * wx_str() const
void InjectScriptOutput(const wxString &output)
Injects script output.
static void ScriptsPrintFunc(HSQUIRRELVM, const SQChar *s,...)
cbEditor * Open(const wxString &filename, int pos=0, ProjectFile *data=nullptr)
const wxString & _(const wxString &string)
SQInteger sqstd_register_stringlib(HSQUIRRELVM v)
wxArray< int > wxArrayInt
void PrintSquirrelToWxString(wxString &msg, const SQChar *s, va_list &vl)
bool m_AttachedToMainWindow
wxString GetPath(int flags=wxPATH_GET_VOLUME, wxPathFormat format=wxPATH_NATIVE) const
static void CaptureScriptOutput(HSQUIRRELVM, const SQChar *s,...)
~ScriptingManager() override
Provides scripting in Code::Blocks.
void Log(const wxString &msg, int i=app_log, Logger::level lv=Logger::info)
void sq_setprintfunc(HSQUIRRELVM v, SQPRINTFUNCTION printfunc)
void RefreshTrusts()
Force refresh of script trusts.
wxString & insert(size_t nPos, const wxString &str)
void DebugLog(const wxString &msg, Logger::level lv=Logger::info)
bool RegisterScriptPlugin(const wxString &name, const wxArrayInt &ids)
Registers a script plugin menu IDs with the callback function.
Script trusts container struct.
bool RemoveTrust(const wxString &script)
Remove a script trust.
DLLIMPORT wxUint32 FromFile(const wxString &filename)
TrustedScripts m_TrustedScripts
bool LoadBuffer(const wxString &buffer, const wxString &debugName=_T("CommandLine"))
Loads a string buffer.
bool wxGetKeyState(wxKeyCode key)
static wxString Format(const wxString &format,...)
DLLIMPORT int cbMessageBox(const wxString &message, const wxString &caption=wxEmptyString, int style=wxOK, wxWindow *parent=NULL, int x=-1, int y=-1)
wxMessageBox wrapper.
std::map< wxString, wxString > StringToStringMap