Embedded console into REPL
This commit is contained in:
parent
0f90215b7a
commit
9bdb7ce9cb
5
Makefile
5
Makefile
|
@ -11,7 +11,7 @@ PTYPE != uname -m
|
|||
# DBG=0,1 --- build with debugging symbols and logging
|
||||
# ED=0,1 --- build with or without editor
|
||||
|
||||
NAME = yugine
|
||||
|
||||
|
||||
|
||||
ifeq ($(DBG), 1)
|
||||
|
@ -65,12 +65,15 @@ ifeq ($(OS), WIN32)
|
|||
LINKER_FLAGS = $(QFLAGS) -static
|
||||
ELIBS = engine ucrt yughc portaudio glfw3 opengl32 gdi32 ws2_32 ole32 winmm setupapi m
|
||||
CLIBS =
|
||||
EXT = .exe
|
||||
else
|
||||
LINKER_FLAGS = $(QFLAGS) -L/usr/local/lib
|
||||
ELIBS = engine pthread yughc portaudio asound glfw3 c m dl
|
||||
CLIBS =
|
||||
endif
|
||||
|
||||
NAME = yugine$(EXT)
|
||||
|
||||
ELIBS != $(call prefix, $(ELIBS), -l)
|
||||
CLIBS != $(call prefix, $(CLIBS), -l);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define logLevel 0
|
||||
|
||||
|
@ -15,6 +16,16 @@ char *catstr[] = {"ENGINE", "SCRIPT"};
|
|||
|
||||
FILE *logfile = NULL;
|
||||
|
||||
#define CONSOLE_BUF 1024*1024/* 1MB */
|
||||
char con[CONSOLE_BUF] = {'\0'};
|
||||
int coni = 0;
|
||||
|
||||
char lastlog[ERROR_BUFFER] = {'\0'};
|
||||
|
||||
const char *console() {
|
||||
return console;
|
||||
}
|
||||
|
||||
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...)
|
||||
{
|
||||
if (priority >= logLevel) {
|
||||
|
@ -39,6 +50,10 @@ void mYughLog(int category, int priority, int line, const char *file, const char
|
|||
fflush(logfile);
|
||||
}
|
||||
|
||||
snprintf(con+coni, CONSOLE_BUF-coni, "%s\n", buffer);
|
||||
coni += strlen(buffer);
|
||||
|
||||
snprintf(lastlog, ERROR_BUFFER, "%s", buffer);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
#define LOG_ERROR 2
|
||||
#define LOG_CRITICAL 3
|
||||
|
||||
extern char con[];
|
||||
extern int coni;
|
||||
extern char lastlog[];
|
||||
|
||||
#define YughLog(cat, pri, msg, ...) mYughLog(cat, pri, __LINE__, __FILE__, msg, ##__VA_ARGS__)
|
||||
#define YughInfo(msg, ...) mYughLog(0, 0, __LINE__, __FILE__, msg, ##__VA_ARGS__);
|
||||
#define YughWarn(msg, ...) mYughLog(0, 1, __LINE__, __FILE__, msg, ##__VA_ARGS__);
|
||||
|
@ -25,4 +29,6 @@ int TestSDLError(int sdlErr);
|
|||
void log_setfile(char *file);
|
||||
void log_cat(FILE *f);
|
||||
|
||||
const char *console();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,6 +40,8 @@ struct gameproject *cur_project = NULL;
|
|||
struct vec *projects = NULL;
|
||||
static char setpath[MAXPATH];
|
||||
|
||||
|
||||
|
||||
// Menus
|
||||
// TODO: Pack this into a bitfield
|
||||
static struct editorVars editor = {0};
|
||||
|
@ -577,9 +579,13 @@ void editor_project_gui() {
|
|||
|
||||
|
||||
*/
|
||||
nk_layout_row_dynamic(ctx, 300, 1);
|
||||
//nk_text(ctx, con, coni, NK_TEXT_ALIGN_TOP|NK_TEXT_ALIGN_LEFT);
|
||||
nk_edit_string_zero_terminated(ctx, NK_EDIT_MULTILINE|NK_EDIT_READ_ONLY|NK_EDIT_GOTO_END_ON_ACTIVATE, lastlog, ERROR_BUFFER, NULL);
|
||||
//nuke_label(lastlog);
|
||||
static char buffer[512] = {'\0'};
|
||||
nk_layout_row_dynamic(ctx, 25, 2);
|
||||
nk_flags active = nk_edit_string_zero_terminated(ctx, NK_EDIT_BOX | NK_EDIT_SIG_ENTER, buffer, 512-1, nk_filter_ascii);
|
||||
nk_flags active = nk_edit_string_zero_terminated(ctx, NK_EDIT_BOX | NK_EDIT_SIG_ENTER|NK_EDIT_AUTO_SELECT, buffer, 512-1, nk_filter_ascii);
|
||||
if (active & NK_EDIT_COMMITED || nuke_btn("Submit")) {
|
||||
char bigbuf[1024];
|
||||
snprintf(bigbuf, 1024, "(loginfo %s)", buffer);
|
||||
|
|
|
@ -31,6 +31,13 @@ void script_init() {
|
|||
}
|
||||
|
||||
void script_run(const char *script) {
|
||||
s7_pointer old_port = s7_set_current_error_port(s7, s7_open_output_string(s7));
|
||||
int gc_loc = -1;
|
||||
if (old_port != s7_nil(s7)) gc_loc = s7_gc_protect(s7, old_port);
|
||||
|
||||
|
||||
|
||||
|
||||
s7_eval_c_string(s7, script);
|
||||
|
||||
const char *errmsg = s7_get_output_string(s7, s7_current_error_port(s7));
|
||||
|
@ -38,7 +45,10 @@ void script_run(const char *script) {
|
|||
if (errmsg && (*errmsg))
|
||||
mYughLog(1, 2, 0, "script", "Scripting error: %s", errmsg);
|
||||
|
||||
s7_flush_output_port(s7, s7_current_error_port(s7));
|
||||
s7_close_output_port(s7, s7_current_error_port(s7));
|
||||
s7_set_current_error_port(s7, old_port);
|
||||
if (gc_loc != -1) s7_gc_unprotect_at(s7, gc_loc);
|
||||
|
||||
}
|
||||
|
||||
int script_dofile(const char *file) {
|
||||
|
|
Loading…
Reference in a new issue