Discussion:
adding errorcodes on luajit.exe failures
Stefan Hett
2014-09-09 10:38:36 UTC
Permalink
Hi,

we've set-up a script which calls luajit.exe to create precompiled lua
files. In some weird cases we end-up with luajit.exe silently not
writing the output file at all (reason unknown).

I see from the code-base that in case of an error LuaJIT (aka: pmain)
doesn't return any errorcodes at all. I was wondering if it wouldn't be
useful to change that behavior. Shouldn't it be better to return the
status (s->status) as the error code, if it was set instead of 0? Or
alternatively: In those cases where the status is != 0, change the
return value to a fixed (non-null) return value to indicate some error?

Regards,
Stefan
Mike Pall
2014-09-09 10:46:32 UTC
Permalink
pmain) doesn't return any errorcodes at all.
That's not true. A simple test could have shown you that before
posting. If you throw an error to the top level or use os.exit(n),
it *does* set the error code (POSIX shell examples):

$ luajit -e ''; echo $?
0

$ luajit -e 'error("foo")' 2>/dev/null; echo $?
1

$ luajit -e 'os.exit(42)'; echo $?
42

--Mike
Stefan Hett
2014-10-13 12:37:51 UTC
Permalink
Hi Mike,

thanks for the fast reply and sry for my late response (got distracted
from this issue the past weeks).

Of course u're absolutely right. I obviously mistook the pmain-return
value for the actual status return value. So everything is fine on
LuaJIT's end and the errorlevel correctly shows a problem as well as
records the error in the errorchannel.

The issue was actually on our side (our script not correctly checking
the errorlevel and not redirecting the error-channel, but rather only
checking/redirecting the standard output channel).

So sorry for the noise.

Regards,
Stefan
Post by Mike Pall
pmain) doesn't return any errorcodes at all.
That's not true. A simple test could have shown you that before
posting. If you throw an error to the top level or use os.exit(n),
$ luajit -e ''; echo $?
0
$ luajit -e 'error("foo")' 2>/dev/null; echo $?
1
$ luajit -e 'os.exit(42)'; echo $?
42
--Mike
Loading...