naev 0.10.4
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"
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 "nfile.h"
30#include "nlua.h"
31#include "nlua_audio.h"
32#include "nlua_bkg.h"
33#include "nlua_camera.h"
34#include "nlua_cli.h"
35#include "nlua_colour.h"
36#include "nlua_linopt.h"
37#include "nlua_music.h"
38#include "nlua_tex.h"
39#include "nlua_tk.h"
40#include "nluadef.h"
41#include "nstring.h"
42#include "toolkit.h"
43
44#define BUTTON_WIDTH 50
45#define BUTTON_HEIGHT 20
47/*
48 * Global stuff.
49 */
50static nlua_env cli_env = LUA_NOREF;
51static lua_State *cli_thread= NULL;
52static int cli_thread_ref = LUA_NOREF;
53static glFont *cli_font = NULL;
55/*
56 * Buffers.
57 */
58#define CLI_MAX_INPUT STRMAX_SHORT
59#define CLI_WIDTH (SCREEN_W - 100)
60#define CLI_HEIGHT (SCREEN_H - 100)
61static char **cli_buffer;
62static char *cli_prompt;
63static int cli_history = 0;
64static int cli_scroll_pos = -1;
65static int cli_firstOpen = 1;
66static int cli_firstline = 1;
67static int cli_height = 0;
68static int cli_max_lines = 0;
70#define CLI_MAX_LINES (cli_max_lines)
71
72/*
73 * CLI stuff.
74 */
75static int cli_script( lua_State *L );
76static const luaL_Reg cli_methods[] = {
77 { "script", cli_script },
78 { "warn", cli_warn },
79 {NULL, NULL}
80};
82/*
83 * Prototypes.
84 */
85static int cli_keyhandler( unsigned int wid, SDL_Keycode key, SDL_Keymod mod );
86static void cli_render( double bx, double by, double w, double h, void *data );
87static void cli_printCoreString( const char *s, int escape );
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
111static void 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], iter.l_end - iter.l_begin );
120 cli_addMessageMax( buf, len );
121 free(buf);
122 }
123 else
124 cli_addMessageMax( &s[iter.l_begin], iter.l_end - iter.l_begin );
125 }
126}
127
131static int cli_printCore( lua_State *L, int cli_only, int escape )
132{
133 int n = lua_gettop(L); /* Number of arguments. */
134
135 lua_getglobal(L, "tostring");
136 for (int i=1; i<=n; i++) {
137 const char *s;
138 lua_pushvalue(L, -1); /* function to be called */
139 lua_pushvalue(L, i); /* value to print */
140 if (lua_pcall(L, 1, 1, 0) != 0) {
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); /* get result */
146 if (s == NULL)
147 return NLUA_ERROR(L, LUA_QL("tostring") " must return a string to "
148 LUA_QL("print"));
149 if (!cli_only)
150 LOG( "%s", s );
151
152 /* Add to console. */
153 cli_printCoreString( s, escape );
154
155 lua_pop(L, 1); /* pop result */
156 }
157
158 return 0;
159}
160
166int cli_warn( lua_State *L )
167{
168 const char *msg = luaL_checkstring(L,1);
169 WARN("%s", msg );
170 /* Add to console. */
171 cli_printCoreString( msg, 1 );
172 return 0;
173}
174
178int cli_print( lua_State *L )
179{
180 return cli_printCore( L, 0, 1 );
181}
182
188int cli_printRaw( lua_State *L )
189{
190 return cli_printCore( L, 1, 0 );
191}
192
196static int cli_script( lua_State *L )
197{
198 const char *fname;
199 char *buf;
200 size_t blen;
201 int n;
202
203 /* Handle parameters. */
204 fname = luaL_checkstring(L, 1);
205 n = lua_gettop(L);
206
207 /* Reset loaded buffer. */
208 if (cli_env != LUA_NOREF) {
209 nlua_getenv( L, cli_env, "_LOADED" );
210 if (lua_istable(L,-1)) {
211 lua_pushnil(L); /* t, nil */
212 while (lua_next(L, -2) != 0) { /* t, key, val */
213 lua_pop(L,1); /* t, key */
214 lua_pushvalue(L,-1); /* t, key, key */
215 lua_pushnil(L); /* t, key, key, nil */
216 lua_rawset(L,-4); /* t, key */
217 } /* t */
218 }
219 lua_pop(L,1); /* */
220 }
221
222 /* Do the file from PHYSFS. */
223 buf = ndata_read( fname, &blen );
224 if (luaL_loadbuffer( L, buf, blen, fname ) != 0)
225 lua_error(L);
226 free( buf );
227
228 /* Return the stuff. */
229 nlua_pushenv(L, cli_env);
230 lua_setfenv(L, -2);
231 if (lua_pcall(L, 0, LUA_MULTRET, 0) != 0) {
232 WARN(_("Error running 'script':\n%s"), lua_tostring(L,-1));
233 lua_pop(L,1);
234 return 0;
235 }
236 return lua_gettop(L) - n;
237}
238
244static void cli_addMessage( const char *msg )
245{
246 char *buf;
247 /* Not initialized. */
248 if (cli_env == LUA_NOREF)
249 return;
250 buf = strdup((msg != NULL) ? msg : "");
253}
254
261static void cli_addMessageMax( const char *msg, const int l )
262{
263 char *buf;
264 /* Not initialized. */
265 if (cli_env == LUA_NOREF)
266 return;
267 buf = strndup((msg != NULL) ? msg : "", l);
270}
271
275static void cli_render( double bx, double by, double w, double h, void *data )
276{
277 (void) data;
278 int start;
279 const glColour col = COL_ALPHA( cBlack, 0.5 );
280
281 gl_renderRect( bx, by, w, h, &col );
282
283 if (cli_scroll_pos == -1)
285 else
286 start = cli_scroll_pos;
287
288 for (int i=start; i<array_size(cli_buffer); i++)
289 gl_printMaxRaw( cli_font, w, bx,
290 by + h - (i-start)*(cli_font->h+5),
291 &cFontWhite, -1., cli_buffer[i] );
292}
293
297static int cli_keyhandler( unsigned int wid, SDL_Keycode key, SDL_Keymod mod )
298{
299 (void) mod;
300
301 switch (key) {
302
303 /* Go up in history. */
304 case SDLK_UP:
305 for (int i=cli_history; i>=0; i--) {
306 if (strncmp(cli_buffer[i], "#C>", 3) == 0) {
307 /* Strip escape codes from beginning and end */
308 char *str = strndup(cli_buffer[i]+5, strlen(cli_buffer[i])-7);
309 if (i == cli_history &&
310 strcmp(window_getInput(wid, "inpInput"), str) == 0) {
311 free(str);
312 continue;
313 }
314 window_setInput( wid, "inpInput", str );
315 free(str);
316 cli_history = i;
317 return 1;
318 }
319 }
320 return 1;
321
322 /* Go down in history. */
323 case SDLK_DOWN:
324 /* Clears buffer. */
326 window_setInput( wid, "inpInput", NULL );
327 return 1;
328 }
329
330 /* Find next buffer. */
331 for (int i=cli_history+1; i<array_size(cli_buffer); i++) {
332 if (strncmp(cli_buffer[i], "#C>", 3) == 0) {
333 char *str = strndup(cli_buffer[i]+5, strlen(cli_buffer[i])-7);
334 window_setInput( wid, "inpInput", str );
335 free(str);
336 return 1;
337 }
338 }
340 window_setInput( wid, "inpInput", NULL );
341 return 1;
342
343 /* Scroll up */
344 case SDLK_PAGEUP:
345 if (cli_scroll_pos == -1)
348 return 1;
349
350 /* Scroll down */
351 case SDLK_PAGEDOWN:
352 if (cli_scroll_pos != -1) {
355 cli_scroll_pos = -1;
356 }
357 return 1;
358
359 /* Tab completion */
360 case SDLK_TAB:
361 cli_tabComplete(wid);
362 return 1;
363
364 default:
365 break;
366 }
367
368 return 0;
369}
370
374void cli_tabComplete( unsigned int wid )
375{
376 const char *match, *old;
377 char *str, *cur, *new;
378
379 old = window_getInput( wid, "inpInput" );
380 str = strdup(old);
381
382 nlua_pushenv(naevL, cli_env);
383 cur = str;
384 for (int i=0; str[i] != '\0'; i++) {
385 if (str[i] == '.' || str[i] == ':') {
386 str[i] = '\0';
387 lua_getfield(naevL, -1, cur);
388
389 /* If not indexable, replace with blank table */
390 if (!lua_istable(naevL, -1)) {
391 if (luaL_getmetafield(naevL, -1, "__index")) {
392 if (lua_istable(naevL, -1)) {
393 /* Handles the metatables used by Naev's userdatas */
394 lua_remove(naevL, -2);
395 } else {
396 lua_pop(naevL, 2);
397 lua_newtable(naevL);
398 }
399 } else {
400 lua_pop(naevL, 1);
401 lua_newtable(naevL);
402 }
403 }
404
405 lua_remove(naevL, -2);
406 cur = str + i + 1;
407 /* Start over on other non-identifier character */
408 } else if (!isalnum(str[i]) && str[i] != '_') {
409 lua_pop(naevL, 1);
410 nlua_pushenv(naevL, cli_env);
411 cur = str + i + 1;
412 }
413 }
414
415 if (strlen(cur) > 0) {
416 lua_pushnil(naevL);
417 while (lua_next(naevL, -2) != 0) {
418 if (lua_isstring(naevL, -2)) {
419 match = lua_tostring(naevL, -2);
420 if (strncmp(cur, match, strlen(cur)) == 0) {
421 new = malloc(strlen(old) + strlen(match) - strlen(cur) + 1);
422 strcpy(new, old);
423 strcat(new, match + strlen(cur));
424 window_setInput( wid, "inpInput", new);
425 free(new);
426 lua_pop(naevL, 2);
427 break;
428 }
429 }
430 lua_pop(naevL, 1);
431 }
432 }
433 free(str);
434 lua_pop(naevL, 1);
435}
436
437static int cli_initLua (void)
438{
439 int status;
440 size_t blen;
441 /* Already loaded. */
442 if (cli_env != LUA_NOREF)
443 return 0;
444
445 /* Create the state. */
446 cli_env = nlua_newEnv();
456
457 nlua_pushenv( naevL, cli_env );
458 luaL_register( naevL, NULL, cli_methods );
459 lua_settop( naevL, 0 );
460
461 if (conf.lua_repl) {
462 char *buf = ndata_read( "rep.lua", &blen );
463 status = nlua_dobufenv( cli_env, buf, blen, "@rep.lua" );
464 free( buf );
465 if (status) {
466 lua_settop( naevL, 0 );
467 return status;
468 }
469 if (lua_gettop( naevL ) != 1) {
470 WARN( _("rep.lua failed to return a single coroutine.") );
471 lua_settop( naevL, 0 );
472 return -1;
473 }
474 cli_thread = lua_tothread( naevL, -1 );
475 cli_thread_ref = luaL_ref( naevL, LUA_REGISTRYINDEX );
476 if (cli_thread == NULL) {
477 WARN( _("rep.lua failed to return a single coroutine.") );
478 lua_settop( naevL, 0 );
479 return -1;
480 }
481 status = lua_resume( cli_thread, 0 );
482 cli_prompt = strdup( lua_tostring( cli_thread, -1 ) );
483 if (status == 0) {
484 WARN( _("REPL thread exited.") );
485 return 1;
486 }
487 else if (status != LUA_YIELD) {
488 WARN( "%s", cli_prompt );
489 return -1;
490 }
491 }
492 return 0;
493}
494
498int cli_init (void)
499{
500 /* Set the font. */
501 cli_font = malloc( sizeof(glFont) );
502 gl_fontInit( cli_font, _(FONT_MONOSPACE_PATH), conf.font_size_console, FONT_PATH_PREFIX, 0 );
503
504 /* Allocate the buffer. */
505 cli_buffer = array_create(char*);
506
507 cli_initLua();
508
509 return 0;
510}
511
515void cli_exit (void)
516{
517 /* Destroy the state. */
518 luaL_unref( naevL, LUA_REGISTRYINDEX, cli_thread_ref );
519 nlua_freeEnv( cli_env );
520 cli_thread = NULL;
521 cli_env = cli_thread_ref = LUA_NOREF;
522
524 free( cli_font );
525 cli_font = NULL;
526
527 /* Free the buffer. */
528 for (int i=0; i<array_size(cli_buffer); i++)
529 free(cli_buffer[i]);
531 cli_buffer = NULL;
532 free(cli_prompt);
533 cli_prompt = NULL;
534}
535
542static void cli_input( unsigned int wid, const char *unused )
543{
544 (void) unused;
545 int status, len;
546 const char *str, *prompt;
547 char *escaped;
548 char buf[CLI_MAX_INPUT+7];
549
550 /* Get the input. */
551 str = window_getInput( wid, "inpInput" );
552
553 /* Ignore useless stuff. */
554 if (str == NULL || (conf.lua_repl && cli_thread == NULL))
555 return;
556
557 /* Put the message in the console. */
558 escaped = cli_escapeString( &len, str, strlen(str) );
559 if (conf.lua_repl)
560 prompt = cli_prompt; /* Remembered from last time lua-repl requested input */
561 else
562 prompt = cli_firstline ? "> " : ">>";
563 snprintf( buf, CLI_MAX_INPUT+7, "#C%s %s#0", prompt, escaped );
564 free(escaped);
565 cli_printCoreString( buf, 0 );
566
567 if (conf.lua_repl) {
568 /* Resume the REPL. */
569 lua_pushstring( cli_thread, str );
570 status = lua_resume( cli_thread, 1 );
571 if (status == 0) {
572 cli_printCoreString( _("REPL thread exited."), 0 );
573 luaL_unref( naevL, LUA_REGISTRYINDEX, cli_thread_ref );
574 cli_thread = NULL;
575 cli_thread_ref = LUA_NOREF;
576 }
577 else {
578 free( cli_prompt );
579 cli_prompt = strdup( lua_tostring( cli_thread, -1 ) );
580 lua_settop( cli_thread, 0 );
581 if (status != LUA_YIELD)
583 }
584 }
585 else {
586 /* Set up for concat. */
587 if (!cli_firstline) /* o */
588 lua_pushliteral(naevL, "\n"); /* o \n */
589
590 /* Load the string. */
591 lua_pushstring( naevL, str ); /* s */
592
593 /* Concat. */
594 if (!cli_firstline) /* o \n s */
595 lua_concat(naevL, 3); /* s */
596
597 status = luaL_loadbuffer( naevL, lua_tostring(naevL,-1), lua_strlen(naevL,-1), "=cli" );
598
599 /* String isn't proper Lua yet. */
600 if (status == LUA_ERRSYNTAX) {
601 size_t lmsg;
602 const char *msg = lua_tolstring(naevL, -1, &lmsg);
603 const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1);
604 const char *s;
605 if (strstr(msg, LUA_QL("<eof>")) == tp) {
606 /* Pop the loaded buffer. */
607 lua_pop(naevL, 1);
608 cli_firstline = 0;
609 }
610 else {
611 /* Real error, spew message and break. */
612 s = lua_tostring(naevL, -1);
613 WARN( "%s", s );
614 cli_printCoreString( s, 1 );
615 lua_settop(naevL, 0);
616 cli_firstline = 1;
617 }
618 }
619 /* Print results - all went well. */
620 else if (status == 0) {
621 lua_remove(naevL,1);
622
623 nlua_pushenv(naevL, cli_env);
624 lua_setfenv(naevL, -2);
625
626 if (nlua_pcall(cli_env, 0, LUA_MULTRET)) {
627 cli_printCoreString( lua_tostring(naevL, -1), 1 );
628 lua_pop(naevL, 1);
629 }
630
631 if (lua_gettop(naevL) > 0) {
632 nlua_getenv(naevL, cli_env, "print");
633 lua_insert(naevL, 1);
634 if (lua_pcall(naevL, lua_gettop(naevL)-1, 0, 0) != 0)
635 cli_addMessage( _("Error printing results.") );
636 }
637
638 /* Clear stack. */
639 lua_settop(naevL, 0);
640 cli_firstline = 1;
641 }
642 }
643
644 /* Clear the box now. */
645 window_setInput( wid, "inpInput", NULL );
646
647 /* Scroll to bottom */
648 cli_scroll_pos = -1;
649}
650
654void cli_open (void)
655{
656 unsigned int wid;
657 int line_height;
658
659 /* Lazy loading. */
660 if (cli_env == LUA_NOREF)
661 if (cli_init())
662 return;
663
664 if (menu_isOpen(MENU_MAIN) || cli_isOpen())
665 return;
666
667 /* Put a friendly message at first. */
668 if (cli_firstOpen) {
669 char *buf;
670 cli_addMessage( "" );
671 cli_addMessage( _("#gWelcome to the Lua console!") );
672 asprintf( &buf, "#g "APPNAME" v%s", naev_version(0) );
673 cli_printCoreString( buf, 0 );
674 free( buf );
675 cli_addMessage( "" );
676 cli_firstOpen = 0;
677 }
678
679 /* Create the window. */
680 wid = window_create( "wdwLuaConsole", _("Lua Console"), -1, -1, CLI_WIDTH, CLI_HEIGHT );
681
682 /* Window settings. */
686
687 /* Input box. */
688 window_addInput( wid, 20, 20,
690 "inpInput", CLI_MAX_INPUT, 1, cli_font );
691
692 /* Buttons. */
693 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
694 "btnClose", _("Close"), window_close );
695
696 /* Custom console widget. */
697 line_height = cli_font->h*1.5;
698 cli_max_lines = ((CLI_HEIGHT-60-BUTTON_HEIGHT+(line_height-cli_font->h)) / line_height);
699 cli_height = line_height * cli_max_lines - (line_height - cli_font->h);
700 window_addCust( wid, 20, -40,
701 CLI_WIDTH-40, cli_height,
702 "cstConsole", 0, cli_render, NULL, NULL, NULL, NULL );
703
704 /* Reinitilaized. */
705 cli_firstline = 1;
706}
707
708int cli_isOpen (void)
709{
710 return window_exists( "wdwLuaConsole" );
711}
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
Definition: array.h:158
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Definition: array.h:168
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
Definition: array.h:119
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
Definition: array.h:93
void cli_open(void)
Opens the console.
Definition: console.c:654
int cli_warn(lua_State *L)
Barebones warn implementation for Lua, allowing scripts to print warnings to stderr.
Definition: console.c:166
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:131
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:261
#define CLI_MAX_LINES
Definition: console.c:70
void cli_exit(void)
Destroys the CLI environment.
Definition: console.c:515
static char ** cli_buffer
Definition: console.c:61
#define CLI_HEIGHT
Definition: console.c:60
static lua_State * cli_thread
Definition: console.c:51
int cli_init(void)
Initializes the CLI environment.
Definition: console.c:498
#define BUTTON_HEIGHT
Definition: console.c:45
static nlua_env cli_env
Definition: console.c:50
static void cli_printCoreString(const char *s, int escape)
Prints a string.
Definition: console.c:111
static const luaL_Reg cli_methods[]
Definition: console.c:76
static glFont * cli_font
Definition: console.c:53
static void cli_addMessage(const char *msg)
Adds a message to the buffer.
Definition: console.c:244
static int cli_firstline
Definition: console.c:66
static void cli_render(double bx, double by, double w, double h, void *data)
Render function for the custom widget.
Definition: console.c:275
void cli_tabComplete(unsigned int wid)
Basic tab completion for console.
Definition: console.c:374
static void cli_input(unsigned int wid, const char *unused)
Handles the CLI input.
Definition: console.c:542
#define CLI_WIDTH
Definition: console.c:59
static int cli_keyhandler(unsigned int wid, SDL_Keycode key, SDL_Keymod mod)
Key handler for the console window.
Definition: console.c:297
static int cli_thread_ref
Definition: console.c:52
static int cli_script(lua_State *L)
Would be like "dofile" from the base Lua lib.
Definition: console.c:196
#define BUTTON_WIDTH
Definition: console.c:44
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:525
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:1722
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:505
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:720
int gl_fontInit(glFont *font, const char *fname, const unsigned int h, const char *prefix, unsigned int flags)
Initializes a font.
Definition: font.c:1516
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:34
const char * naev_version(int long_version)
Returns the version in a human readable string.
Definition: naev_version.c:25
#define MAX(x, y)
Definition: naev.h:39
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
Definition: ndata.c:154
static char buf[NEWS_MAX_LENGTH]
Definition: news.c:45
int nlua_loadStandard(nlua_env env)
Loads the standard Naev Lua API.
Definition: nlua.c:760
int nlua_loadBackground(nlua_env env)
Loads the graphics library.
Definition: nlua_bkg.c:38
int nlua_loadCamera(nlua_env env)
Loads the camera library.
Definition: nlua_camera.c:47
int nlua_loadCLI(nlua_env env)
Loads the CLI Lua library.
Definition: nlua_cli.c:36
int nlua_loadCol(nlua_env env)
Loads the colour library.
Definition: nlua_colour.c:52
int nlua_loadLinOpt(nlua_env env)
Loads the linopt library.
Definition: nlua_linopt.c:71
int nlua_loadMusic(nlua_env env)
Music Lua module.
Definition: nlua_music.c:58
int nlua_loadTex(nlua_env env)
Loads the texture library.
Definition: nlua_tex.c:62
int nlua_loadTk(nlua_env env)
Loads the Toolkit Lua library.
Definition: nlua_tk.c:90
int asprintf(char **strp, const char *fmt,...)
Like sprintf(), but it allocates a large-enough string and returns the pointer in the first argument....
Definition: nstring.c:161
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:94
void gl_renderRect(double x, double y, double w, double h, const glColour *c)
Renders a rectangle.
Definition: opengl_render.c:90
static const double b[]
Definition: rng.c:256
int lua_repl
Definition: conf.h:161
int font_size_console
Definition: conf.h:141
Represents a font in memory.
Definition: font.h:16
int h
Definition: font.h:18
The state of a line iteration. This matches the process of rendering text into an on-screen box: An e...
Definition: font.h:40
size_t l_end
Definition: font.h:45
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:696
void window_setAccept(unsigned int wid, void(*accept)(unsigned int, const char *))
Sets the default accept function of the window.
Definition: toolkit.c:879
void window_setCancel(unsigned int wid, void(*cancel)(unsigned int, const char *))
Sets the default cancel function of the window.
Definition: toolkit.c:900
void window_handleKeys(unsigned int wid, int(*keyhandler)(unsigned int, SDL_Keycode, SDL_Keymod))
Sets the key handler for the window.
Definition: toolkit.c:972
int window_exists(const char *wdwname)
Checks to see if a window exists.
Definition: toolkit.c:598
void window_close(unsigned int wid, const char *str)
Helper function to automatically close the window calling it.
Definition: toolkit.c:1031