Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* NAEV now also prints everything to it's internal console.

  • Loading branch information...
commit 09c3da454246b6a0d70b49aa18512772268fd4b2 1 parent 0e15c1b
Edgar Simo-Serra authored
4 configure.ac
@@ -375,8 +375,8 @@ esac
375 375
376 376 AC_SUBST([LIBLUA_CFLAGS])
377 377
378   -# utils/pack
379   -PACK_CFLAGS="$GLOBAL_CFLAGS $SDL_CFLAGS $SDLIMAGE_CFLAGS"
  378 +
  379 +PACK_CFLAGS="$GLOBAL_CFLAGS $SDL_CFLAGS $SDLIMAGE_CFLAGS -DNOLOGPRINTFCONSOLE"
380 380 PACK_LIBS="$GLOBAL_LIBS $SDL_LIBS $SDLIMAGE_LIBS"
381 381
382 382 AC_SUBST([PACK_CFLAGS])
1  src/Makefile.am
@@ -47,6 +47,7 @@ naev_SOURCES = \
47 47 land.c \
48 48 land_outfits.c \
49 49 land_shipyard.c \
  50 + log.c \
50 51 map.c \
51 52 map_overlay.c \
52 53 md5.c \
11 src/console.c
@@ -68,7 +68,6 @@ static int cli_firstline = 1; /**< Is this the first line? */
68 68 /*
69 69 * CLI stuff.
70 70 */
71   -static int cli_print( lua_State *L );
72 71 static int cli_script( lua_State *L );
73 72 static const luaL_Reg cli_methods[] = {
74 73 { "print", cli_print },
@@ -82,14 +81,14 @@ static const luaL_Reg cli_methods[] = {
82 81 * Prototypes.
83 82 */
84 83 static int cli_keyhandler( unsigned int wid, SDLKey key, SDLMod mod );
85   -static void cli_addMessage( const char *msg );
86 84 static void cli_render( double bx, double by, double w, double h, void *data );
87 85
88 86
89 87 /**
90 88 * @brief Replacement for the internal Lua print to print to console instead of terminal.
91 89 */
92   -static int cli_print( lua_State *L ) {
  90 +int cli_print( lua_State *L )
  91 +{
93 92 int n = lua_gettop(L); /* number of arguments */
94 93 int i;
95 94 char buf[LINE_LENGTH];
@@ -159,10 +158,14 @@ static int cli_script( lua_State *L )
159 158 *
160 159 * @param msg Message to add.
161 160 */
162   -static void cli_addMessage( const char *msg )
  161 +void cli_addMessage( const char *msg )
163 162 {
164 163 int n;
165 164
  165 + /* Not initialized. */
  166 + if (cli_state == NULL)
  167 + return;
  168 +
166 169 if (msg != NULL)
167 170 strncpy( cli_buffer[cli_cursor], msg, LINE_LENGTH );
168 171 else
1  src/console.h
@@ -17,6 +17,7 @@ void cli_exit (void);
17 17 * Misc.
18 18 */
19 19 void cli_open (void);
  20 +void cli_addMessage( const char *msg );
20 21
21 22
22 23 #endif /* CONSOLE_H */
34 src/font.c
@@ -886,22 +886,24 @@ static int gl_fontRenderCharacter( const glFont* font, int ch, const glColour *c
886 886 return 0;
887 887 }
888 888
889   - /*
890   - * Global Local
891   - * 0--1 0--1 4
892   - * | /| => | / /|
893   - * |/ | |/ / |
894   - * 3--2 2 3--5
895   - */
896   - ind[0] = 4*ch + 0;
897   - ind[1] = 4*ch + 1;
898   - ind[2] = 4*ch + 3;
899   - ind[3] = 4*ch + 1;
900   - ind[4] = 4*ch + 3;
901   - ind[5] = 4*ch + 2;
902   -
903   - /* Draw the element. */
904   - glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, ind );
  889 + if (!isspace(ch)) {
  890 + /*
  891 + * Global Local
  892 + * 0--1 0--1 4
  893 + * | /| => | / /|
  894 + * |/ | |/ / |
  895 + * 3--2 2 3--5
  896 + */
  897 + ind[0] = 4*ch + 0;
  898 + ind[1] = 4*ch + 1;
  899 + ind[2] = 4*ch + 3;
  900 + ind[3] = 4*ch + 1;
  901 + ind[4] = 4*ch + 3;
  902 + ind[5] = 4*ch + 2;
  903 +
  904 + /* Draw the element. */
  905 + glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, ind );
  906 + }
905 907
906 908 /* Translate matrix. */
907 909 gl_matrixTranslate( font->chars[ch].adv_x, font->chars[ch].adv_y );
17 src/log.h
@@ -8,16 +8,18 @@
8 8 #ifndef LOG_H
9 9 # define LOG_H
10 10
  11 +
11 12 #include <stdio.h>
12 13 #include <signal.h>
13 14
14   -#define LOG(str, args...) (fprintf(stdout,str"\n", ## args))
  15 +
  16 +#define LOG(str, args...) (logprintf(stdout,str"\n", ## args))
15 17 #ifdef DEBUG_PARANOID /* Will cause WARNs to blow up */
16   -#define WARN(str, args...) (fprintf(stderr,"Warning: [%s] "str"\n", __func__, ## args), abort())
  18 +#define WARN(str, args...) (logprintf(stderr,"Warning: [%s] "str"\n", __func__, ## args), abort())
17 19 #else /* DEBUG_PARANOID */
18   -#define WARN(str, args...) (fprintf(stderr,"Warning: [%s] "str"\n", __func__, ## args))
  20 +#define WARN(str, args...) (logprintf(stderr,"Warning: [%s] "str"\n", __func__, ## args))
19 21 #endif /* DEBUG_PARANOID */
20   -#define ERR(str, args...) (fprintf(stderr,"ERROR %s:%d [%s]: "str"\n", __FILE__, __LINE__, __func__, ## args), abort())
  22 +#define ERR(str, args...) (logprintf(stderr,"ERROR %s:%d [%s]: "str"\n", __FILE__, __LINE__, __func__, ## args), abort())
21 23 #ifdef DEBUG
22 24 # undef DEBUG
23 25 # define DEBUG(str, args...) LOG(str, ## args)
@@ -29,4 +31,11 @@
29 31 #endif /* DEBUG */
30 32
31 33
  34 +#ifdef NOLOGPRINTFCONSOLE
  35 +#define logprintf fprintf
  36 +#else /* NOLOGPRINTFCONSOLE */
  37 +int logprintf( FILE *stream, const char *fmt, ... );
  38 +#endif /* NOLOGPRINTFCONSOLE */
  39 +
  40 +
32 41 #endif /* LOG_H */
1  src/naev.c
@@ -288,6 +288,7 @@ int main( int argc, char** argv )
288 288 toolkit_init(); /* initializes the toolkit */
289 289 map_init(); /* initializes the map. */
290 290 cond_init(); /* Initialize conditional subsystem. */
  291 + cli_init(); /* Initialize console. */
291 292
292 293 /* Data loading */
293 294 load_all();
4 src/nlua.c
@@ -27,6 +27,7 @@
27 27 #include "nlua_pilot.h"
28 28 #include "nlua_vec2.h"
29 29 #include "nlua_diff.h"
  30 +#include "nlua_cli.h"
30 31
31 32
32 33 /*
@@ -105,6 +106,9 @@ int nlua_loadBasic( lua_State* L )
105 106 lua_setglobal(L, override[i]);
106 107 }
107 108
  109 + /* Override print to print in the console. */
  110 + lua_register(L, "print", cli_print);
  111 +
108 112 nlua_load(L,luaopen_math); /* open math. */
109 113 nlua_load(L,luaopen_table); /* open table. */
110 114 nlua_load(L, luaopen_string); /* open string. */
2  src/nlua_cli.h
@@ -11,6 +11,8 @@
11 11
12 12
13 13 int nlua_loadCLI( lua_State *L ); /* always write only */
  14 +int cli_print( lua_State *L );
  15 +int nlua_regPrint( lua_State *L );
14 16
15 17
16 18 #endif /* NLUA_CLI_H */

0 comments on commit 09c3da4

Please sign in to comment.
Something went wrong with that request. Please try again.