Empty script is considered as invalid

Started by
5 comments, last by foobar42 2 years ago

Hi,

I just realized that AngelScript considers an empty module as an error. The build function prints the TXT_NOTHING_WAS_BUILT message to the message handler and returns the asERROR error code.

However, IMHO an empty script (resp. a script which contains no code) is a totally valid use-case. Why should this be invalid? I don't know any other compiler or interpreter which considers an empty input file as an error ?

So, wouldn't it make more sense to remove this logic, i.e. don't output any message, and return asSUCCESS instead? An alternative would be to return a specific error code like asEMPTY_MODULE, then the user could decide whether this should be ignored or not.

Or is there any issue with modules containing no code? If there's no problem, I'd for now simply patch AngelScript in my application by removing this logic.

EDIT: Also note that a script containing a #include statement is not an empty file from user perspective, but still the compilation fails because CScriptBuilder removes that statement (well, it fails only if the included file does not contain any code…).

Advertisement

Why would compiling an empty script be considered valid? In what scenario would you compile an empty script?

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

For example, when using the AngelScript engine to provide autocompletion & syntax highlighting in an IDE. Then every script you write will be empty at the very beginning, which would make the autocompleter fail although there are no errors in the script. Same applies to an IDE which automatically compiles the script after each change (hot reloading), it would fail after creating the first script file.

But I think the question should not be why an empty module should not fail - the question should be, why should it fail? I mean, an empty module is not bad at all, there's no problem with it, and also probably every other script interpreter does not fail in that case as well. So why raising an error if there's no issue with the module?

What other script interpreters do or do not is quite irrelevant.

However, I agree with your use case. I still think it should be an error to try to compile an empty script, but I can agree that it should be easy to identify this case so that the application decide whether or not to treat this as an error or just ignore it.

I'll look into this.

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

Making it a warning may be a good compromise.

foobar42 said:
I don't know any other compiler or interpreter which considers an empty input file as an error

Then you didn't use my simulation language ?

You're supposed to write an experiment there. An empty file obviously doesn't have an experiment, so it's an error. This was all before auto-completion or background compiling existed though.

In the end it's all down to the question of "what is a valid program?". Opinions may vary.

WitchLord said:

I'll look into this.

Great, thanks!

Alberth said:
Making it a warning may be a good compromise.

I'd prefer no message output at all in that case. A message is trivial to output at user side if the “script empty” error code is returned, but it is not trivial to suppress a warning which is not desired.

Btw, for me the cleanest solution would be to silently accept empty modules (returning asSUCCESS) but adding the IsEmpty() method from asCModule to the asIScriptModule interface. If a user wants to do something special with empty modules, it's as easy as if (module->IsEmpty()) {…} and provides maximum flexibility. But of course an asMODULE_EMPTY error would also be fine.

This topic is closed to new replies.

Advertisement