🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

the compiler doesn't compile the script

Started by
28 comments, last by brightening-eyes 10 years, 6 months ago

hi

i'm making a game engine and i want to test my compiler

previously, it crashed

but with getting help, i fixed it

now, when i want to compile my script, it load's the file, and don't write's to it

the run function also crashed

now when i'm trying to run my application, it doesn't show anything

also when i'm trying to compile my application, it load's the file and it doesn't write to it

i've uploaded the code here

[attachment=18986:AGC.zip]

thanks in advance

when you can't see well like me, you can't test your applications and you can't read something

Github

Advertisement

Amir,

please do a little bit of investigation on your own and tell us more details. Help us help you.

First of all: Did the script compile successfully? Did you check the return code from the Build call?

Secondly: Was the Prepare call on the context successful? Did you chek the return code?

I want to continue to help you, but I can't do all the work for you.

Regards,

Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

yes, i updated the compile.cpp and moved the codes from save_byet to the compile function
i did checked the return code
this is the function:

void mainwin::compile(wxCommandEvent &evt)
{
asIScriptFunction *mainfunc=scripting::scriptengine->GetGlobalFunctionByDecl("void main()");
if(mainfunc==0)
{
scripting::scriptengine->WriteMessage(NULL, 0, 0, asMSGTYPE_ERROR, "the script should have void main() function");
}
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)
{
wxProgressDialog *dlg=new wxProgressDialog("compiling", "please wait while the script is being compiled", 100, this, wxPD_APP_MODAL|wxPD_AUTO_HIDE);
compilerstream scriptcomp;
CScriptBuilder builder;
builder.StartNewModule(scripting::scriptengine, "build");
builder.AddSectionFromMemory("sec", txt->GetText(), txt->GetTextLength());
int r=scriptcomp.open(compsavedialog->GetPath());
r= builder.BuildModule();
if(r<0)
{
scripting::scriptengine->WriteMessage("sec", 0, 0, asMSGTYPE_ERROR, "unknown error!");
return ;
}
asIScriptModule *mod=scripting::scriptengine->GetModule("build", asGM_ONLY_IF_EXISTS);
mod->SaveByteCode(&scriptcomp);
compsavedialog->Close(true);
dlg->Pulse(wxEmptyString, false);
}
}
this is compiler.h:
#ifndef _AGC_COMPILER_H
#define _AGC_COMPILER_H
#include <angelscript.h>
#include <stdio.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
what is the problem in this code?
i want to fix it!

when you can't see well like me, you can't test your applications and you can't read something

Github

The first thing you should do is organize your code logically. You're mixing everything up. It's no wonder you don't find the cause of the problem you're facing.

Why are you attempting to get the global function "void main()" from the engine? Unless you've registered this function from the application this will never be found. If you meant to retrieve the global function from the script, then you need to call the GetGlobalFunction method on the script module after you've built the script.

I see you're passing a script section from memory in the variable txt. But what exactly do you have in this variable? Are you certain the script is there?

Here's how I think you wanted to implement your function:


void mainwin::compile(wxCommandEvent &evt)
{
   // Ask the user where he wants to save the compiled bytecode
   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();
     return;
   }
   if(save_compile==wxID_OK)
   {
     // Show an "in progress" dialog
     wxProgressDialog *dlg=new wxProgressDialog("compiling", "please wait while the script is being compiled", 100, this, wxPD_APP_MODAL|wxPD_AUTO_HIDE);
 
     // Compile the script
     CScriptBuilder builder;
     builder.StartNewModule(scripting::scriptengine, "build");
     builder.AddSectionFromMemory("sec", txt->GetText(), txt->GetTextLength());
     r = builder.BuildModule();
     if(r<0)
     {
       scripting::scriptengine->WriteMessage("sec", 0, 0, asMSGTYPE_ERROR, "The script cannot be compiled due to errors!");
       return ;
     }
 
     // Check if the script has the required main function
     asIScriptModule *mod=scripting::scriptengine->GetModule("build", asGM_ONLY_IF_EXISTS);
     asIScriptFunction *mainfunc=mod->GetGlobalFunctionByDecl("void main()");
     if(mainfunc==0)
     {
        scripting::scriptengine->WriteMessage(NULL, 0, 0, asMSGTYPE_ERROR, "the script should have void main() function");
        return;
     }
 
     // Save the bytecode to the file
     compilerstream scriptcomp;
     int r=scriptcomp.open(compsavedialog->GetPath());
     mod->SaveByteCode(&scriptcomp);
     compsavedialog->Close(true);
     dlg->Pulse(wxEmptyString, false);
  }
}

There is an error in your compilerstream::open() method. It will always return -1, even though the file was successfully opened.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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

when you can't see well like me, you can't test your applications and you can't read something

Github

I see you've added checks for all of the return codes which is good.

Which of the function calls fail? What error message do you get when you run your application?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

i've got nothing just worked but my script doesn't compiled nothing in message callback this is the executable: http://amir-ramezani.3owl.com/AGC.exe

when you can't see well like me, you can't test your applications and you can't read something

Github

I downloaded the executable but it doesn't work. I'm not sure if there are any dependencies that I miss, perhaps some dlls that you need to provide together with the executable?.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

what is the error? witch of the dlls have not been found? say me, i upload them for you!

when you can't see well like me, you can't test your applications and you can't read something

Github

Unfortunately Windows doesn't tell me why it doesn't work. The only error I get is "This application can't be executed on your PC".

I'm using 64bit Windows 8.1 if that's of any help to you.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement