i updated the compile as you've sed
compiler.cpp
/*
*the compilation Process
*/
void mainwin::compile(wxCommandEvent &evt)
{
wxString wildcard;
#ifdef __WXMSW__
wildcard="Executable Files(*.exe)|*.exe";
#else
wildcard="All Files(*.*)|*.*";
#endif // __WXMSW__
wxFileDialog *compsavedialog=new wxFileDialog(this, "compile", "", "", wildcard, wxFD_SAVE|wxFD_OVERWRITE_PROMPT, wxDefaultPosition, wxDefaultSize, "compilesavedlg");
int save_compile=compsavedialog->ShowModal();
if(save_compile==wxID_CANCEL)
{
compsavedialog->Close();
}
if(save_compile==wxID_OK)
{
compilerstream scriptcomp;
CScriptBuilder builder;
int r=builder.StartNewModule(scripting::scriptengine, "build");
if(r<0)
{
scripting::scriptengine->WriteMessage("sec", 0, 0, asMSGTYPE_ERROR, "can't start compilation");
return ;
}
r=builder.AddSectionFromMemory("sec", txt->GetText(), txt->GetTextLength());
if(r<0)
{
scripting::scriptengine->WriteMessage("sec", 0, 0, asMSGTYPE_ERROR, "can't get the script!");
return ;
}
r= builder.BuildModule();
if(r<0)
{
scripting::scriptengine->WriteMessage("sec", 0, 0, asMSGTYPE_ERROR, "unknown error!");
return ;
}
r=scriptcomp.open(compsavedialog->GetPath());
if(r<0)
{
scripting::scriptengine->WriteMessage("sec", 0, 0, asMSGTYPE_ERROR, "can't Open the given file for compilation!");
return ;
}
asIScriptModule *mod=scripting::scriptengine->GetModule("build", asGM_ONLY_IF_EXISTS);
if(mod==0)
{
scripting::scriptengine->WriteMessage("sec", 0, 0, asMSGTYPE_ERROR, "can't load the compile byet code");
return ;
}
asIScriptFunction *mainfunc=mod->GetFunctionByDecl("void main()");
if(mainfunc==0)
{
scripting::scriptengine->WriteMessage("sec", 0, 0, asMSGTYPE_ERROR, "your script must have Void Main() function");
return ;
}
compsavedialog->Close(true);
wxProgressDialog *dlg=new wxProgressDialog("compiling", "please wait while the script is being compiled", 100, this, wxPD_APP_MODAL|wxPD_AUTO_HIDE);
mod->SaveByteCode(&scriptcomp);
dlg->Pulse(wxEmptyString, (bool)false);
}
}
compiler.h:
/*
*the compiler class that is to be used for compile the scripts
*/
class compilerstream: public asIBinaryStream
{
public:
compilerstream()
{
f=NULL;
}
~compilerstream()
{
if(f)
{
fclose(f);
}
}
int open(wxString filename)
{
if(f)
{
return -1;
}
#if _MSC_VER >= 1500
fopen_s(&f, filename, "wb");
#else
f = fopen(filename, "wb");
#endif
if( f == 0 )
{
return -1;
}
return 0;
}
void Write(const void *ptr, asUINT size)
{
if( size == 0 || f == 0 )
{
return;
}
fwrite(ptr, size, 1, f);
}
void Read(void *, asUINT ) {}
private:
FILE *f;
};
#endif // _AGC_COMPILER_H
i saw the samples and documentation and updated my code like those
and actually, i've removed builder.AddSectionFromMemory("sec", txt->GetText(), txt->GetTextLength());
and tested and nothing happens
now, it doesn't open the file
it doesn't give any executable, or anything
i'm working on it for 2 and a half hours!
i've checked all of the compiler.cpp and compiler.h and in my idea, no problem now
but as i see now, it doesn't compile!
this is the script that i'm debugging:
script.AGC:
void main()
{
agc_lz_compress("C:\\Dev-Cpp", "C:\\Dev-Cpp.compressed", 1024*1024);
}
it doesn't compile
no message has been occured and it work's like a working application
but the compilation and run functions don't work properly
i can update run function like that, but i don't know the compilation problem
i've debugged it
but the debugger doesn't found the problem