Merge branch 'master' into 'master'

Allow passing argc to EQL::ini

See merge request eql/EQL5!1
This commit is contained in:
P. Ruetz 2020-11-14 08:47:10 +00:00
commit cc3011dc0d
3 changed files with 36 additions and 5 deletions

View file

@ -7,6 +7,7 @@
#include <QApplication>
#include <QTimer>
#include <QStringList>
#include <QDebug>
const char EQL::version[] = "20.7.1"; // July 2020
@ -50,9 +51,26 @@ void EQL::ini(char** argv) {
cl_booted = true;
cl_boot(1, argv); }
void EQL::eval(const char* lisp_code) {
void EQL::ini(int argc, char** argv) {
cl_booted = true;
cl_boot(argc, argv); }
void EQL::eval(const char* lisp_code, const EvalMode mode) {
CL_CATCH_ALL_BEGIN(ecl_process_env()) {
si_safe_eval(2, ecl_read_from_cstring((char*)lisp_code), Cnil); }
switch(mode) {
case DebugOnError:
si_safe_eval(2, ecl_read_from_cstring((char*)lisp_code), Cnil);
break;
case LogOnError:
case DieOnError:
cl_object ret = si_safe_eval(3, ecl_read_from_cstring((char*)lisp_code), Cnil, ecl_make_fixnum(EVAL_ERROR_VALUE));
if (ecl_t_of(ret) == t_fixnum && fix(ret) == EVAL_ERROR_VALUE) {
qDebug()<<"Error evaluating " <<lisp_code;
if (mode == DieOnError)
exit(-1);
}
}
}
CL_CATCH_ALL_END; }
void EQL::ignoreIOStreams() {
@ -70,6 +88,9 @@ void EQL::exec(const QStringList& args) {
arguments.removeAll("-norc"); }
else {
eval("(x:when-it (probe-file \"~/.eclrc\") (load x:it))"); }
if (arguments.contains("-debug-on-error")) {
arguments.removeAll("-debug-on-error");
evalMode = DebugOnError; }
// Slime
int i_swank = arguments.indexOf(QRegExp("*start-swank*.lisp", Qt::CaseInsensitive, QRegExp::Wildcard));
if(arguments.contains("-slime") || (i_swank != -1)) {
@ -189,6 +210,7 @@ void EQL::runOnUiThread(void* function_or_closure) {
CL_UNWIND_PROTECT_END; }
CL_CATCH_ALL_END; }
EQL::EvalMode EQL::evalMode = DieOnError;
bool EQL::cl_booted = false;
bool EQL::return_value_p = false;
bool EQL::qexec = true;

View file

@ -17,6 +17,7 @@ QT_BEGIN_NAMESPACE
#define QSLOT(x) "1"#x
#define QSIGNAL(x) "2"#x
#define EVAL_ERROR_VALUE -1
typedef void (*lisp_ini)(cl_object);
@ -25,13 +26,21 @@ class EQL_EXPORT EQL : public QObject {
public:
EQL();
enum EvalMode {
DebugOnError,
LogOnError,
DieOnError,
};
static bool cl_booted;
static bool return_value_p;
static bool qexec;
static const char version[];
static QEventLoop* eventLoop;
static void ini(int, char**);
static void ini(char**);
static void eval(const char*);
static void eval(const char*, const EvalMode = evalMode);
static EvalMode evalMode;
void exec(const QStringList&);
void exec(lisp_ini, const QByteArray& = "nil", const QByteArray& = "eql-user"); // see my_app example

View file

@ -55,13 +55,13 @@ int catch_all_qexec() {
int main(int argc, char** argv) {
EQL::ini(argv); // best initialized here
EQL::ini(argc, argv); // best initialized here
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); // for Qt WebEngine
QApplication qapp(argc, argv);
QStringList args(QCoreApplication::arguments());
if(args.contains("-h") || (args.contains("--help"))) {
std::cout << "Usage: eql5 [file] [-qtpl] [-qgui] [-quic file.ui [:ui-package] [:maximized]] [-slime] [-norc]" << std::endl;
std::cout << "Usage: eql5 [file] [-qtpl] [-qgui] [-quic file.ui [:ui-package] [:maximized]] [-slime] [-norc] [-debug-on-error]" << std::endl;
exit(0); }
ini();