diff --git a/configure.ac b/configure.ac index 63441375d2..7f4bd721b5 100644 --- a/configure.ac +++ b/configure.ac @@ -375,8 +375,8 @@ esac AC_SUBST([LIBLUA_CFLAGS]) -# utils/pack -PACK_CFLAGS="$GLOBAL_CFLAGS $SDL_CFLAGS $SDLIMAGE_CFLAGS" + +PACK_CFLAGS="$GLOBAL_CFLAGS $SDL_CFLAGS $SDLIMAGE_CFLAGS -DNOLOGPRINTFCONSOLE" PACK_LIBS="$GLOBAL_LIBS $SDL_LIBS $SDLIMAGE_LIBS" AC_SUBST([PACK_CFLAGS]) diff --git a/src/Makefile.am b/src/Makefile.am index 94678d8e91..3add9b4bcf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -47,6 +47,7 @@ naev_SOURCES = \ land.c \ land_outfits.c \ land_shipyard.c \ + log.c \ map.c \ map_overlay.c \ md5.c \ diff --git a/src/console.c b/src/console.c index c8a8b8bf6d..327b5921df 100644 --- a/src/console.c +++ b/src/console.c @@ -68,7 +68,6 @@ static int cli_firstline = 1; /**< Is this the first line? */ /* * CLI stuff. */ -static int cli_print( lua_State *L ); static int cli_script( lua_State *L ); static const luaL_Reg cli_methods[] = { { "print", cli_print }, @@ -82,14 +81,14 @@ static const luaL_Reg cli_methods[] = { * Prototypes. */ static int cli_keyhandler( unsigned int wid, SDLKey key, SDLMod mod ); -static void cli_addMessage( const char *msg ); static void cli_render( double bx, double by, double w, double h, void *data ); /** * @brief Replacement for the internal Lua print to print to console instead of terminal. */ -static int cli_print( lua_State *L ) { +int cli_print( lua_State *L ) +{ int n = lua_gettop(L); /* number of arguments */ int i; char buf[LINE_LENGTH]; @@ -159,10 +158,14 @@ static int cli_script( lua_State *L ) * * @param msg Message to add. */ -static void cli_addMessage( const char *msg ) +void cli_addMessage( const char *msg ) { int n; + /* Not initialized. */ + if (cli_state == NULL) + return; + if (msg != NULL) strncpy( cli_buffer[cli_cursor], msg, LINE_LENGTH ); else diff --git a/src/console.h b/src/console.h index 2337a8586e..2ce0cc4c7c 100644 --- a/src/console.h +++ b/src/console.h @@ -17,6 +17,7 @@ void cli_exit (void); * Misc. */ void cli_open (void); +void cli_addMessage( const char *msg ); #endif /* CONSOLE_H */ diff --git a/src/font.c b/src/font.c index bbd9475941..e1ae77a793 100644 --- a/src/font.c +++ b/src/font.c @@ -886,22 +886,24 @@ static int gl_fontRenderCharacter( const glFont* font, int ch, const glColour *c return 0; } - /* - * Global Local - * 0--1 0--1 4 - * | /| => | / /| - * |/ | |/ / | - * 3--2 2 3--5 - */ - ind[0] = 4*ch + 0; - ind[1] = 4*ch + 1; - ind[2] = 4*ch + 3; - ind[3] = 4*ch + 1; - ind[4] = 4*ch + 3; - ind[5] = 4*ch + 2; - - /* Draw the element. */ - glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, ind ); + if (!isspace(ch)) { + /* + * Global Local + * 0--1 0--1 4 + * | /| => | / /| + * |/ | |/ / | + * 3--2 2 3--5 + */ + ind[0] = 4*ch + 0; + ind[1] = 4*ch + 1; + ind[2] = 4*ch + 3; + ind[3] = 4*ch + 1; + ind[4] = 4*ch + 3; + ind[5] = 4*ch + 2; + + /* Draw the element. */ + glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, ind ); + } /* Translate matrix. */ gl_matrixTranslate( font->chars[ch].adv_x, font->chars[ch].adv_y ); diff --git a/src/log.h b/src/log.h index 852a655752..21a9065595 100644 --- a/src/log.h +++ b/src/log.h @@ -8,16 +8,18 @@ #ifndef LOG_H # define LOG_H + #include #include -#define LOG(str, args...) (fprintf(stdout,str"\n", ## args)) + +#define LOG(str, args...) (logprintf(stdout,str"\n", ## args)) #ifdef DEBUG_PARANOID /* Will cause WARNs to blow up */ -#define WARN(str, args...) (fprintf(stderr,"Warning: [%s] "str"\n", __func__, ## args), abort()) +#define WARN(str, args...) (logprintf(stderr,"Warning: [%s] "str"\n", __func__, ## args), abort()) #else /* DEBUG_PARANOID */ -#define WARN(str, args...) (fprintf(stderr,"Warning: [%s] "str"\n", __func__, ## args)) +#define WARN(str, args...) (logprintf(stderr,"Warning: [%s] "str"\n", __func__, ## args)) #endif /* DEBUG_PARANOID */ -#define ERR(str, args...) (fprintf(stderr,"ERROR %s:%d [%s]: "str"\n", __FILE__, __LINE__, __func__, ## args), abort()) +#define ERR(str, args...) (logprintf(stderr,"ERROR %s:%d [%s]: "str"\n", __FILE__, __LINE__, __func__, ## args), abort()) #ifdef DEBUG # undef DEBUG # define DEBUG(str, args...) LOG(str, ## args) @@ -29,4 +31,11 @@ #endif /* DEBUG */ +#ifdef NOLOGPRINTFCONSOLE +#define logprintf fprintf +#else /* NOLOGPRINTFCONSOLE */ +int logprintf( FILE *stream, const char *fmt, ... ); +#endif /* NOLOGPRINTFCONSOLE */ + + #endif /* LOG_H */ diff --git a/src/naev.c b/src/naev.c index 3843520433..c20c84361c 100644 --- a/src/naev.c +++ b/src/naev.c @@ -288,6 +288,7 @@ int main( int argc, char** argv ) toolkit_init(); /* initializes the toolkit */ map_init(); /* initializes the map. */ cond_init(); /* Initialize conditional subsystem. */ + cli_init(); /* Initialize console. */ /* Data loading */ load_all(); diff --git a/src/nlua.c b/src/nlua.c index 81a7a68db1..0f9fbbf3b8 100644 --- a/src/nlua.c +++ b/src/nlua.c @@ -27,6 +27,7 @@ #include "nlua_pilot.h" #include "nlua_vec2.h" #include "nlua_diff.h" +#include "nlua_cli.h" /* @@ -105,6 +106,9 @@ int nlua_loadBasic( lua_State* L ) lua_setglobal(L, override[i]); } + /* Override print to print in the console. */ + lua_register(L, "print", cli_print); + nlua_load(L,luaopen_math); /* open math. */ nlua_load(L,luaopen_table); /* open table. */ nlua_load(L, luaopen_string); /* open string. */ diff --git a/src/nlua_cli.h b/src/nlua_cli.h index 35cb94d4a3..a9d3092266 100644 --- a/src/nlua_cli.h +++ b/src/nlua_cli.h @@ -11,6 +11,8 @@ int nlua_loadCLI( lua_State *L ); /* always write only */ +int cli_print( lua_State *L ); +int nlua_regPrint( lua_State *L ); #endif /* NLUA_CLI_H */