naev 0.12.6
console.c
Go to the documentation of this file.
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
10#define lua_c
11#include <ctype.h>
12#include <lauxlib.h>
13#include <lua.h>
14#include <lualib.h>
15#include <stdlib.h>
16
17#include "naev.h"
19
20#include "console.h"
21
22#include "array.h"
23#include "conf.h"
24#include "font.h"
25#include "log.h"
26#include "menu.h"
27#include "naev.h"
28#include "ndata.h"
29#include "nlua.h"
30#include "nlua_bkg.h"
31#include "nlua_camera.h"
32#include "nlua_cli.h"
33#include "nlua_colour.h"
34#include "nlua_linopt.h"
35#include "nlua_music.h"
36#include "nlua_tex.h"
37#include "nlua_tk.h"
38#include "nluadef.h"
39#include "nstring.h"
40#include "toolkit.h"
41
42#define BUTTON_WIDTH 50
43#define BUTTON_HEIGHT 20
44
45/*
46 * Global stuff.
47 */
48static nlua_env cli_env = LUA_NOREF;
49static lua_State *cli_thread = NULL;
50static int cli_thread_ref =
51 LUA_NOREF;
52static glFont *cli_font = NULL;
53
54/*
55 * Buffers.
56 */
57#define CLI_MAX_INPUT \
58 STRMAX_SHORT
60#define CLI_WIDTH ( SCREEN_W - 100 )
61#define CLI_HEIGHT ( SCREEN_H - 100 )
62static char **cli_buffer;
63static char *cli_prompt;
64static int cli_history = 0;
65static int cli_scroll_pos = -1;
66static int cli_firstOpen = 1;
67static int cli_firstline = 1;
68static int cli_height = 0;
69static int cli_max_lines = 0;
71#define CLI_MAX_LINES ( cli_max_lines )
72
73/*
74 * CLI stuff.
75 */
76static int cli_script( lua_State *L );
77static const luaL_Reg cli_methods[] = {
78 { "script", cli_script },
79 { "warn", cli_warn },
80 { NULL, NULL } };
81
82/*
83 * Prototypes.
84 */
85static int cli_keyhandler( unsigned int wid, SDL_Keycode key, SDL_Keymod mod,
86 int isrepeat );
87static void cli_render( double bx, double by, double w, double h, void *data );
88static int cli_printCore( lua_State *L, int cli_only, int escape );
89static void cli_addMessage( const char *msg );
90static void cli_addMessageMax( const char *msg, const int l );
91void cli_tabComplete( unsigned int wid );
92static int cli_initLua( void );
93
94static char *cli_escapeString( int *len_out, const char *s, int len )
95{
96 char *buf = malloc( 2 * len + 1 ); /* worst case */
97 int b = 0;
98 for ( int i = 0; i < len; i++ ) {
99 if ( s[i] == FONT_COLOUR_CODE )
100 buf[b++] = FONT_COLOUR_CODE;
101 buf[b++] = s[i];
102 }
103 buf[b] = '\0';
104 *len_out = b;
105 return buf;
106}
107
110 */
111void cli_printCoreString( const char *s, int escape )
112{
113 int len;
115
117 while ( gl_printLineIteratorNext( &iter ) ) {
118 if ( escape ) {
119 char *buf = cli_escapeString( &len, &s[iter.l_begin],
120 iter.l_end - iter.l_begin );
121 cli_addMessageMax( buf, len );
122 free( buf );
123 } else
124 cli_addMessageMax( &s[iter.l_begin], iter.l_end - iter.l_begin );
125 }
126}
127
130 */
131static int cli_printCore( lua_State *L, int cli_only, int escape )
132{
133 int n = lua_gettop( L ); /* Number of arguments. */
134 lua_getglobal( L, "tostring" ); /* f */
135 lua_pushstring( L, "" ); /* f, s */
136 for ( int i = 1; i <= n; i++ ) {
137 const char *s;
138 lua_pushvalue( L, -2 ); /* f, s, f */
139 lua_pushvalue( L, i ); /* f, s, f, v */
140 if ( lua_pcall( L, 1, 1, 0 ) != 0 ) { /* f, s, r */
141 WARN( _( "Error calling 'tostring':\n%s" ), lua_tostring( L, -1 ) );
142 lua_pop( L, 1 );
143 continue;
144 }
145 s = lua_tostring( L, -1 );
146 if ( s == NULL )
147 return NLUA_ERROR(
148 L, LUA_QL( "tostring" ) " must return a string to " LUA_QL(
149 "print" ) );
150
151 lua_pushstring( L, "\t" ); /* f, s, '\t' */
152 lua_concat( L, 3 ); /* f, s */
153 }
154
155 const char *s = lua_tostring( L, -1 );
156 if ( !cli_only )
157 LOG( "%s", s );
158 cli_printCoreString( s, escape );
159
160 lua_pop( L, 2 ); /* */
161 return 0;
162}
163
169 */
170int cli_warn( lua_State *L )
171{
172 return nlua_warn( L, 1 );
173}
174
178 */
179int cli_print( lua_State *L )
180{
181 return cli_printCore( L, 0, 1 );
182}
183
188 */
189int cli_printRaw( lua_State *L )
190{
191 return cli_printCore( L, 1, 0 );
192}
193
196 */
197static int cli_script( lua_State *L )
198{
199 const char *fname;
200 char *buf;
201 size_t blen;
202 int n;
203
204 /* Handle parameters. */
205 fname = luaL_checkstring( L, 1 );
206 n = lua_gettop( L );
207
208 /* Clear cache. */
210
211 /* Reset loaded buffer. */
212 if ( cli_env != LUA_NOREF ) {
213 /* We can't just clear the table with a new one, because this is actually
214 * pointing to package.loaded, and we want to keep the table pointer
215 * valid. */
216 nlua_getenv( L, cli_env, NLUA_LOAD_TABLE );
217 if ( lua_istable( L, -1 ) ) {
218 lua_pushnil( L ); /* t, nil */
219 while ( lua_next( L, -2 ) != 0 ) { /* t, key, val */
220 lua_pop( L, 1 ); /* t, key */
221 lua_pushvalue( L, -1 ); /* t, key, key */
222 lua_pushnil( L ); /* t, key, key, nil */
223 lua_rawset( L, -4 ); /* t, key */
224 } /* t */
225 }
226 lua_pop( L, 1 ); /* */
227 }
228
229 /* Do the file from PHYSFS. */
230 buf = ndata_read( fname, &blen );
231 if ( luaL_loadbuffer( L, buf, blen, fname ) != 0 )
232 lua_error( L );
233 free( buf );
234
235 /* Return the stuff. */
236 if ( nlua_pcall( cli_env, 0, LUA_MULTRET ) != 0 ) {
237 WARN( _( "Error running 'script':\n%s" ), lua_tostring( L, -1 ) );
238 lua_pop( L, 1 );
239 return 0;
240 }
241 return lua_gettop( L ) - n;
242}
243
248 */
249static void cli_addMessage( const char *msg )
250{
251 char *buf;
252 /* Not initialized. */
253 if ( cli_env == LUA_NOREF )
254 return;
255 buf = strdup( ( msg != NULL ) ? msg : "" );
256 array_grow( &cli_buffer ) = buf;
258}
259
265 */
266static void cli_addMessageMax( const char *msg, const int l )
267{
268 char *buf;
269 /* Not initialized. */
270 if ( cli_env == LUA_NOREF )
271 return;
272 buf = strndup( ( msg != NULL ) ? msg : "", l );
273 array_grow( &cli_buffer ) = buf;
275}
276
279 */
280static void cli_render( double bx, double by, double w, double h, void *data )
281{
282 (void)data;
283 int start;
284 const glColour col = COL_ALPHA( cBlack, 0.5 );
285
286 gl_renderRect( bx, by, w, h, &col );
287
288 if ( cli_scroll_pos == -1 )
289 start = MAX( 0, array_size( cli_buffer ) - CLI_MAX_LINES );
290 else
291 start = cli_scroll_pos;
292
293 for ( int i = start; i < array_size( cli_buffer ); i++ )
294 gl_printMaxRaw( cli_font, w, bx,
295 by + h - ( i - start ) * ( cli_font->h + 5 ), &cFontWhite,
296 -1., cli_buffer[i] );
297}
298
301 */
302static int cli_keyhandler( unsigned int wid, SDL_Keycode key, SDL_Keymod mod,
303 int isrepeat )
304{
305 (void)mod;
306 (void)isrepeat;
307
308 switch ( key ) {
309
310 /* Go up in history. */
311 case SDLK_UP:
312 for ( int i = cli_history; i >= 0; i-- ) {
313 if ( strncmp( cli_buffer[i], "#C>", 3 ) == 0 ) {
314 /* Strip escape codes from beginning and end */
315 char *str =
316 strndup( cli_buffer[i] + 5, strlen( cli_buffer[i] ) - 7 );
317 if ( i == cli_history &&
318 strcmp( window_getInput( wid, "inpInput" ), str ) == 0 ) {
319 free( str );
320 continue;
321 }
322 window_setInput( wid, "inpInput", str );
323 free( str );
324 cli_history = i;
325 return 1;
326 }
327 }
328 return 1;
329
330 /* Go down in history. */
331 case SDLK_DOWN:
332 /* Clears buffer. */
333 if ( cli_history >= array_size( cli_buffer ) - 1 ) {
334 window_setInput( wid, "inpInput", NULL );
335 return 1;
336 }
337
338 /* Find next buffer. */
339 for ( int i = cli_history + 1; i < array_size( cli_buffer ); i++ ) {
340 if ( strncmp( cli_buffer[i], "#C>", 3 ) == 0 ) {
341 char *str =
342 strndup( cli_buffer[i] + 5, strlen( cli_buffer[i] ) - 7 );
343 window_setInput( wid, "inpInput", str );
344 free( str );
345 return 1;
346 }
347 }
349 window_setInput( wid, "inpInput", NULL );
350 return 1;
351
352 /* Scroll up */
353 case SDLK_PAGEUP:
354 if ( cli_scroll_pos == -1 )
357 return 1;
358
359 /* Scroll down */
360 case SDLK_PAGEDOWN:
361 if ( cli_scroll_pos != -1 ) {
364 cli_scroll_pos = -1;
365 }
366 return 1;
367
368 /* Tab completion */
369 case SDLK_TAB:
370 cli_tabComplete( wid );
371 return 1;
372
373 default:
374 break;
375 }
376
377 return 0;
378}
379
382 */
383void cli_tabComplete( unsigned int wid )
384{
385 const char *match, *old;
386 char *str, *cur, *new;
387
388 old = window_getInput( wid, "inpInput" );
389 str = strdup( old );
390
391 nlua_pushenv( naevL, cli_env );
392 cur = str;
393 for ( int i = 0; str[i] != '\0'; i++ ) {
394 if ( str[i] == '.' || str[i] == ':' ) {
395 str[i] = '\0';
396 lua_getfield( naevL, -1, cur );
397
398 /* If not indexable, replace with blank table */
399 if ( !lua_istable( naevL, -1 ) ) {
400 if ( luaL_getmetafield( naevL, -1, "__index" ) ) {
401 if ( lua_istable( naevL, -1 ) ) {
402 /* Handles the metatables used by Naev's userdatas */
403 lua_remove( naevL, -2 );
404 } else {
405 lua_pop( naevL, 2 );
406 lua_newtable( naevL );
407 }
408 } else {
409 lua_pop( naevL, 1 );
410 lua_newtable( naevL );
411 }
412 }
413
414 lua_remove( naevL, -2 );
415 cur = str + i + 1;
416 /* Start over on other non-identifier character */
417 } else if ( !isalnum( str[i] ) && str[i] != '_' ) {
418 lua_pop( naevL, 1 );
419 nlua_pushenv( naevL, cli_env );
420 cur = str + i + 1;
421 }
422 }
423
424 if ( strlen( cur ) > 0 ) {
425 lua_pushnil( naevL );
426 while ( lua_next( naevL, -2 ) != 0 ) {
427 if ( lua_isstring( naevL, -2 ) ) {
428 match = lua_tostring( naevL, -2 );
429 if ( strncmp( cur, match, strlen( cur ) ) == 0 ) {
430 new =
431 malloc( strlen( old ) + strlen( match ) - strlen( cur ) + 1 );
432 strcpy( new, old );
433 strcat( new, match + strlen( cur ) );
434 window_setInput( wid, "inpInput", new );
435 free( new );
436 lua_pop( naevL, 2 );
437 break;
438 }
439 }
440 lua_pop( naevL, 1 );
441 }
442 }
443 free( str );
444 lua_pop( naevL, 1 );
445}
446
447static int cli_initLua( void )
448{
449 int status;
450 size_t blen;
451 /* Already loaded. */
452 if ( cli_env != LUA_NOREF )
453 return 0;
454
455 /* Create the state. */
456 cli_env = nlua_newEnv( "console" );
466
467 nlua_pushenv( naevL, cli_env );
468 luaL_register( naevL, NULL, cli_methods );
469 lua_settop( naevL, 0 );
470
471 if ( conf.lua_repl ) {
472 char *buf = ndata_read( "rep.lua", &blen );
473 status = nlua_dobufenv( cli_env, buf, blen, "@rep.lua" );
474 free( buf );
475 if ( status ) {
476 WARN( _( "Lua console '%s' Lua error:\n%s" ), "rep.lua",
477 lua_tostring( naevL, -1 ) );
478 lua_settop( naevL, 0 );
479 return status;
480 }
481 if ( lua_gettop( naevL ) != 1 ) {
482 WARN( _( "rep.lua failed to return a single coroutine." ) );
483 lua_settop( naevL, 0 );
484 return -1;
485 }
486 cli_thread = lua_tothread( naevL, -1 );
487 cli_thread_ref = luaL_ref( naevL, LUA_REGISTRYINDEX );
488 if ( cli_thread == NULL ) {
489 WARN( _( "rep.lua failed to return a single coroutine." ) );
490 lua_settop( naevL, 0 );
491 return -1;
492 }
493 status = lua_resume( cli_thread, 0 );
494 cli_prompt = strdup( lua_tostring( cli_thread, -1 ) );
495 if ( status == 0 ) {
496 WARN( _( "REPL thread exited." ) );
497 return 1;
498 } else if ( status != LUA_YIELD ) {
499 WARN( "%s", cli_prompt );
500 return -1;
501 }
502 }
503 return 0;
504}
505
508 */
509int cli_init( void )
510{
511 /* Set the font. */
512 cli_font = malloc( sizeof( glFont ) );
513 gl_fontInit( cli_font, _( FONT_MONOSPACE_PATH ), conf.font_size_console,
514 FONT_PATH_PREFIX, 0 );
515
516 /* Allocate the buffer. */
517 cli_buffer = array_create( char * );
518
519 /* Initialize the Lua stuff. */
520 if ( cli_initLua() )
521 WARN( _( "Failed to initialize console Lua!" ) );
522
523 return 0;
524}
525
528 */
529void cli_exit( void )
530{
531 /* Destroy the state. */
532 luaL_unref( naevL, LUA_REGISTRYINDEX, cli_thread_ref );
533 nlua_freeEnv( cli_env );
534 cli_thread = NULL;
535 cli_env = cli_thread_ref = LUA_NOREF;
536
538 free( cli_font );
539 cli_font = NULL;
540
541 /* Free the buffer. */
542 for ( int i = 0; i < array_size( cli_buffer ); i++ )
543 free( cli_buffer[i] );
545 cli_buffer = NULL;
546 free( cli_prompt );
547 cli_prompt = NULL;
548}
549
555 */
556static void cli_input( unsigned int wid, const char *unused )
557{
558 (void)unused;
559 int status, len;
560 const char *str, *prompt;
561 char *escaped;
562 char buf[CLI_MAX_INPUT + 7];
563
564 /* Get the input. */
565 str = window_getInput( wid, "inpInput" );
566
567 /* Ignore useless stuff. */
568 if ( str == NULL || ( conf.lua_repl && cli_thread == NULL ) )
569 return;
570
571 /* Put the message in the console. */
572 escaped = cli_escapeString( &len, str, strlen( str ) );
573 if ( conf.lua_repl )
574 prompt =
575 cli_prompt; /* Remembered from last time lua-repl requested input */
576 else
577 prompt = cli_firstline ? "> " : ">>";
578 snprintf( buf, CLI_MAX_INPUT + 7, "#C%s %s#0", prompt, escaped );
579 free( escaped );
580 cli_printCoreString( buf, 0 );
581
582 if ( conf.lua_repl ) {
583 /* Resume the REPL. */
584 lua_pushstring( cli_thread, str );
585 status = lua_resume( cli_thread, 1 );
586 if ( status == 0 ) {
587 cli_printCoreString( _( "REPL thread exited." ), 0 );
588 luaL_unref( naevL, LUA_REGISTRYINDEX, cli_thread_ref );
589 cli_thread = NULL;
590 cli_thread_ref = LUA_NOREF;
591 } else {
592 free( cli_prompt );
593 cli_prompt = strdup( lua_tostring( cli_thread, -1 ) );
594 lua_settop( cli_thread, 0 );
595 if ( status != LUA_YIELD )
597 }
598 } else {
599 /* Set up for concat. */
600 if ( !cli_firstline ) /* o */
601 lua_pushliteral( naevL, "\n" ); /* o \n */
602
603 /* Load the string. */
604 lua_pushstring( naevL, str ); /* s */
605
606 /* Concat. */
607 if ( !cli_firstline ) /* o \n s */
608 lua_concat( naevL, 3 ); /* s */
609
610 status = luaL_loadbuffer( naevL, lua_tostring( naevL, -1 ),
611 lua_strlen( naevL, -1 ), "=cli" );
612
613 /* String isn't proper Lua yet. */
614 if ( status == LUA_ERRSYNTAX ) {
615 size_t lmsg;
616 const char *msg = lua_tolstring( naevL, -1, &lmsg );
617 const char *tp = msg + lmsg - ( sizeof( LUA_QL( "<eof>" ) ) - 1 );
618 if ( strstr( msg, LUA_QL( "<eof>" ) ) == tp ) {
619 /* Pop the loaded buffer. */
620 lua_pop( naevL, 1 );
621 cli_firstline = 0;
622 } else {
623 /* Real error, spew message and break. */
624 const char *s = lua_tostring( naevL, -1 );
625 WARN( "%s", s );
626 cli_printCoreString( s, 1 );
627 lua_settop( naevL, 0 );
628 cli_firstline = 1;
629 }
630 }
631 /* Print results - all went well. */
632 else if ( status == 0 ) {
633 lua_remove( naevL, 1 );
634
635 if ( nlua_pcall( cli_env, 0, LUA_MULTRET ) ) {
636 cli_printCoreString( lua_tostring( naevL, -1 ), 1 );
637 lua_pop( naevL, 1 );
638 }
639
640 if ( lua_gettop( naevL ) > 0 ) {
641 nlua_getenv( naevL, cli_env, "print" );
642 lua_insert( naevL, 1 );
643 if ( nlua_pcall( cli_env, lua_gettop( naevL ) - 1, 0 ) != 0 )
644 cli_addMessage( _( "Error printing results." ) );
645 }
646
647 /* Clear stack. */
648 lua_settop( naevL, 0 );
649 cli_firstline = 1;
650 }
651 }
652
653 /* Clear the box now. */
654 window_setInput( wid, "inpInput", NULL );
655
656 /* Scroll to bottom */
657 cli_scroll_pos = -1;
658}
659
662 */
663void cli_open( void )
664{
665 unsigned int wid;
666 int line_height;
667
668 /* Lazy loading. */
669 if ( cli_env == LUA_NOREF )
670 if ( cli_init() )
671 return;
672
673 if ( menu_isOpen( MENU_MAIN ) || cli_isOpen() )
674 return;
675
676 /* Put a friendly message at first. */
677 if ( cli_firstOpen ) {
678 char *buf;
679 cli_addMessage( "" );
680 cli_addMessage( _( "#gWelcome to the Lua console!" ) );
681 SDL_asprintf( &buf, "#g " APPNAME " v%s", naev_version( 0 ) );
682 cli_printCoreString( buf, 0 );
683 free( buf );
684 cli_addMessage( "" );
685 cli_firstOpen = 0;
686 }
687
688 /* Create the window. */
689 wid = window_create( "wdwLuaConsole", _( "Lua Console" ), -1, -1, CLI_WIDTH,
690 CLI_HEIGHT );
691
692 /* Window settings. */
696
697 /* Input box. */
698 window_addInput( wid, 20, 20, CLI_WIDTH - 60 - BUTTON_WIDTH, BUTTON_HEIGHT,
699 "inpInput", CLI_MAX_INPUT, 1, cli_font );
700
701 /* Buttons. */
702 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose",
703 _( "Close" ), window_close );
704
705 /* Custom console widget. */
706 line_height = cli_font->h * 1.5;
707 cli_max_lines =
708 ( ( CLI_HEIGHT - 60 - BUTTON_HEIGHT + ( line_height - cli_font->h ) ) /
709 line_height );
710 cli_height = line_height * cli_max_lines - ( line_height - cli_font->h );
711 window_addCust( wid, 20, -40, CLI_WIDTH - 40, cli_height, "cstConsole", 0,
712 cli_render, NULL, NULL, NULL, NULL );
713
714 /* Reinitilaized. */
715 cli_firstline = 1;
716}
717
718int cli_isOpen( void )
719{
720 return window_exists( "wdwLuaConsole" );
721}
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
Definition array.h:170
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Definition array.h:179
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
Definition array.h:122
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
Definition array.h:93
#define BUTTON_HEIGHT
Definition board.c:28
#define BUTTON_WIDTH
Definition board.c:27
void cli_open(void)
Opens the console.
Definition console.c:662
int cli_warn(lua_State *L)
Barebones warn implementation for Lua, allowing scripts to print warnings to stderr.
Definition console.c:169
static char * cli_prompt
Definition console.c:62
static int cli_printCore(lua_State *L, int cli_only, int escape)
Back end for the Lua print functionality.
Definition console.c:130
static int cli_history
Definition console.c:63
int cli_printRaw(lua_State *L)
Prints raw markup to the console.
Definition console.c:188
int cli_print(lua_State *L)
Replacement for the internal Lua print to print to both the console and the terminal.
Definition console.c:178
static void cli_addMessageMax(const char *msg, const int l)
Adds a message to the buffer.
Definition console.c:265
#define CLI_MAX_LINES
Definition console.c:70
void cli_exit(void)
Destroys the CLI environment.
Definition console.c:528
static char ** cli_buffer
Definition console.c:61
#define CLI_HEIGHT
Definition console.c:60
static lua_State * cli_thread
Definition console.c:49
int cli_init(void)
Initializes the CLI environment.
Definition console.c:508
static int cli_keyhandler(unsigned int wid, SDL_Keycode key, SDL_Keymod mod, int isrepeat)
Key handler for the console window.
Definition console.c:301
static nlua_env cli_env
Definition console.c:48
static const luaL_Reg cli_methods[]
Definition console.c:76
static glFont * cli_font
Definition console.c:52
static void cli_addMessage(const char *msg)
Adds a message to the buffer.
Definition console.c:248
static int cli_firstline
Definition console.c:66
void cli_printCoreString(const char *s, int escape)
Prints a string.
Definition console.c:110
static void cli_render(double bx, double by, double w, double h, void *data)
Render function for the custom widget.
Definition console.c:279
void cli_tabComplete(unsigned int wid)
Basic tab completion for console.
Definition console.c:382
static void cli_input(unsigned int wid, const char *unused)
Handles the CLI input.
Definition console.c:555
#define CLI_WIDTH
Definition console.c:59
static int cli_thread_ref
Definition console.c:50
static int cli_script(lua_State *L)
Would be like "dofile" from the base Lua lib.
Definition console.c:196
static int cli_firstOpen
Definition console.c:65
static int cli_scroll_pos
Definition console.c:64
int gl_printLineIteratorNext(glPrintLineIterator *iter)
Updates iter with the next line's information.
Definition font.c:550
void gl_freeFont(glFont *font)
Frees a loaded font. Caution: its glFontStash still has a slot in avail_fonts. At the time of writing...
Definition font.c:1881
void gl_printLineIteratorInit(glPrintLineIterator *iter, const glFont *ft_font, const char *text, int width)
Initialize an iterator object for breaking text into lines.
Definition font.c:528
int gl_printMaxRaw(const glFont *ft_font, const int max, double x, double y, const glColour *c, double outlineR, const char *text)
Behaves like gl_printRaw but stops displaying text after a certain distance.
Definition font.c:753
int gl_fontInit(glFont *font, const char *fname, const unsigned int h, const char *prefix, unsigned int flags)
Initializes a font.
Definition font.c:1670
Handles the important game menus.
#define MENU_MAIN
Definition menu.h:9
#define menu_isOpen(f)
Definition menu.h:16
Header file with generic functions and naev-specifics.
#define APPNAME
Definition naev.h:30
const char * naev_version(int long_version)
Returns the version in a human readable string.
#define MAX(x, y)
Definition naev.h:37
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
Definition ndata.c:207
int nlua_loadStandard(nlua_env env)
Loads the standard Naev Lua API.
Definition nlua.c:914
void lua_clearCache(void)
Clears the cached stuff.
Definition nlua.c:269
lua_State * naevL
Definition nlua.c:54
int nlua_loadBackground(nlua_env env)
Loads the graphics library.
Definition nlua_bkg.c:33
int nlua_loadCamera(nlua_env env)
Loads the camera library.
Definition nlua_camera.c:48
int nlua_loadCLI(nlua_env env)
Loads the CLI Lua library.
Definition nlua_cli.c:24
int nlua_loadCol(nlua_env env)
Loads the colour library.
Definition nlua_colour.c:57
int nlua_loadLinOpt(nlua_env env)
Loads the linopt library.
Definition nlua_linopt.c:73
int nlua_loadMusic(nlua_env env)
Music Lua module.
Definition nlua_music.c:52
int nlua_loadTex(nlua_env env)
Loads the texture library.
Definition nlua_tex.c:59
int nlua_loadTk(nlua_env env)
Loads the Toolkit Lua library.
Definition nlua_tk.c:98
char * strndup(const char *s, size_t n)
Return a pointer to a new string, which is a duplicate of the string s (or, if necessary,...
Definition nstring.c:69
void gl_renderRect(double x, double y, double w, double h, const glColour *c)
Renders a rectangle.
Represents a font in memory.
Definition font.h:17
The state of a line iteration. This matches the process of rendering text into an on-screen box: An e...
Definition font.h:44
unsigned int window_create(const char *name, const char *displayname, const int x, const int y, const int w, const int h)
Creates a window.
Definition toolkit.c:688
void window_setAccept(unsigned int wid, void(*accept)(unsigned int, const char *))
Sets the default accept function of the window.
Definition toolkit.c:846
void window_setCancel(unsigned int wid, void(*cancel)(unsigned int, const char *))
Sets the default cancel function of the window.
Definition toolkit.c:868
void window_handleKeys(unsigned int wid, int(*keyhandler)(unsigned int, SDL_Keycode, SDL_Keymod, int))
Sets the key handler for the window.
Definition toolkit.c:961
int window_exists(const char *wdwname)
Checks to see if a window exists.
Definition toolkit.c:591
void window_close(unsigned int wid, const char *str)
Helper function to automatically close the window calling it.
Definition toolkit.c:1028