naev 0.11.5
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, int isrepeat );
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 : "");
251 array_grow(&cli_buffer) = buf;
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);
268 array_grow(&cli_buffer) = buf;
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, int isrepeat )
298{
299 (void) mod;
300 (void) isrepeat;
301
302 switch (key) {
303
304 /* Go up in history. */
305 case SDLK_UP:
306 for (int i=cli_history; i>=0; i--) {
307 if (strncmp(cli_buffer[i], "#C>", 3) == 0) {
308 /* Strip escape codes from beginning and end */
309 char *str = strndup(cli_buffer[i]+5, strlen(cli_buffer[i])-7);
310 if (i == cli_history &&
311 strcmp(window_getInput(wid, "inpInput"), str) == 0) {
312 free(str);
313 continue;
314 }
315 window_setInput( wid, "inpInput", str );
316 free(str);
317 cli_history = i;
318 return 1;
319 }
320 }
321 return 1;
322
323 /* Go down in history. */
324 case SDLK_DOWN:
325 /* Clears buffer. */
327 window_setInput( wid, "inpInput", NULL );
328 return 1;
329 }
330
331 /* Find next buffer. */
332 for (int i=cli_history+1; i<array_size(cli_buffer); i++) {
333 if (strncmp(cli_buffer[i], "#C>", 3) == 0) {
334 char *str = strndup(cli_buffer[i]+5, strlen(cli_buffer[i])-7);
335 window_setInput( wid, "inpInput", str );
336 free(str);
337 return 1;
338 }
339 }
341 window_setInput( wid, "inpInput", NULL );
342 return 1;
343
344 /* Scroll up */
345 case SDLK_PAGEUP:
346 if (cli_scroll_pos == -1)
349 return 1;
350
351 /* Scroll down */
352 case SDLK_PAGEDOWN:
353 if (cli_scroll_pos != -1) {
356 cli_scroll_pos = -1;
357 }
358 return 1;
359
360 /* Tab completion */
361 case SDLK_TAB:
362 cli_tabComplete(wid);
363 return 1;
364
365 default:
366 break;
367 }
368
369 return 0;
370}
371
375void cli_tabComplete( unsigned int wid )
376{
377 const char *match, *old;
378 char *str, *cur, *new;
379
380 old = window_getInput( wid, "inpInput" );
381 str = strdup(old);
382
383 nlua_pushenv(naevL, cli_env);
384 cur = str;
385 for (int i=0; str[i] != '\0'; i++) {
386 if (str[i] == '.' || str[i] == ':') {
387 str[i] = '\0';
388 lua_getfield(naevL, -1, cur);
389
390 /* If not indexable, replace with blank table */
391 if (!lua_istable(naevL, -1)) {
392 if (luaL_getmetafield(naevL, -1, "__index")) {
393 if (lua_istable(naevL, -1)) {
394 /* Handles the metatables used by Naev's userdatas */
395 lua_remove(naevL, -2);
396 } else {
397 lua_pop(naevL, 2);
398 lua_newtable(naevL);
399 }
400 } else {
401 lua_pop(naevL, 1);
402 lua_newtable(naevL);
403 }
404 }
405
406 lua_remove(naevL, -2);
407 cur = str + i + 1;
408 /* Start over on other non-identifier character */
409 } else if (!isalnum(str[i]) && str[i] != '_') {
410 lua_pop(naevL, 1);
411 nlua_pushenv(naevL, cli_env);
412 cur = str + i + 1;
413 }
414 }
415
416 if (strlen(cur) > 0) {
417 lua_pushnil(naevL);
418 while (lua_next(naevL, -2) != 0) {
419 if (lua_isstring(naevL, -2)) {
420 match = lua_tostring(naevL, -2);
421 if (strncmp(cur, match, strlen(cur)) == 0) {
422 new = malloc(strlen(old) + strlen(match) - strlen(cur) + 1);
423 strcpy(new, old);
424 strcat(new, match + strlen(cur));
425 window_setInput( wid, "inpInput", new);
426 free(new);
427 lua_pop(naevL, 2);
428 break;
429 }
430 }
431 lua_pop(naevL, 1);
432 }
433 }
434 free(str);
435 lua_pop(naevL, 1);
436}
437
438static int cli_initLua (void)
439{
440 int status;
441 size_t blen;
442 /* Already loaded. */
443 if (cli_env != LUA_NOREF)
444 return 0;
445
446 /* Create the state. */
447 cli_env = nlua_newEnv();
457
458 nlua_pushenv( naevL, cli_env );
459 luaL_register( naevL, NULL, cli_methods );
460 lua_settop( naevL, 0 );
461
462 if (conf.lua_repl) {
463 char *buf = ndata_read( "rep.lua", &blen );
464 status = nlua_dobufenv( cli_env, buf, blen, "@rep.lua" );
465 free( buf );
466 if (status) {
467 lua_settop( naevL, 0 );
468 return status;
469 }
470 if (lua_gettop( naevL ) != 1) {
471 WARN( _("rep.lua failed to return a single coroutine.") );
472 lua_settop( naevL, 0 );
473 return -1;
474 }
475 cli_thread = lua_tothread( naevL, -1 );
476 cli_thread_ref = luaL_ref( naevL, LUA_REGISTRYINDEX );
477 if (cli_thread == NULL) {
478 WARN( _("rep.lua failed to return a single coroutine.") );
479 lua_settop( naevL, 0 );
480 return -1;
481 }
482 status = lua_resume( cli_thread, 0 );
483 cli_prompt = strdup( lua_tostring( cli_thread, -1 ) );
484 if (status == 0) {
485 WARN( _("REPL thread exited.") );
486 return 1;
487 }
488 else if (status != LUA_YIELD) {
489 WARN( "%s", cli_prompt );
490 return -1;
491 }
492 }
493 return 0;
494}
495
499int cli_init (void)
500{
501 /* Set the font. */
502 cli_font = malloc( sizeof(glFont) );
503 gl_fontInit( cli_font, _(FONT_MONOSPACE_PATH), conf.font_size_console, FONT_PATH_PREFIX, 0 );
504
505 /* Allocate the buffer. */
506 cli_buffer = array_create(char*);
507
508 cli_initLua();
509
510 return 0;
511}
512
516void cli_exit (void)
517{
518 /* Destroy the state. */
519 luaL_unref( naevL, LUA_REGISTRYINDEX, cli_thread_ref );
520 nlua_freeEnv( cli_env );
521 cli_thread = NULL;
522 cli_env = cli_thread_ref = LUA_NOREF;
523
525 free( cli_font );
526 cli_font = NULL;
527
528 /* Free the buffer. */
529 for (int i=0; i<array_size(cli_buffer); i++)
530 free(cli_buffer[i]);
532 cli_buffer = NULL;
533 free(cli_prompt);
534 cli_prompt = NULL;
535}
536
543static void cli_input( unsigned int wid, const char *unused )
544{
545 (void) unused;
546 int status, len;
547 const char *str, *prompt;
548 char *escaped;
549 char buf[CLI_MAX_INPUT+7];
550
551 /* Get the input. */
552 str = window_getInput( wid, "inpInput" );
553
554 /* Ignore useless stuff. */
555 if (str == NULL || (conf.lua_repl && cli_thread == NULL))
556 return;
557
558 /* Put the message in the console. */
559 escaped = cli_escapeString( &len, str, strlen(str) );
560 if (conf.lua_repl)
561 prompt = cli_prompt; /* Remembered from last time lua-repl requested input */
562 else
563 prompt = cli_firstline ? "> " : ">>";
564 snprintf( buf, CLI_MAX_INPUT+7, "#C%s %s#0", prompt, escaped );
565 free(escaped);
566 cli_printCoreString( buf, 0 );
567
568 if (conf.lua_repl) {
569 /* Resume the REPL. */
570 lua_pushstring( cli_thread, str );
571 status = lua_resume( cli_thread, 1 );
572 if (status == 0) {
573 cli_printCoreString( _("REPL thread exited."), 0 );
574 luaL_unref( naevL, LUA_REGISTRYINDEX, cli_thread_ref );
575 cli_thread = NULL;
576 cli_thread_ref = LUA_NOREF;
577 }
578 else {
579 free( cli_prompt );
580 cli_prompt = strdup( lua_tostring( cli_thread, -1 ) );
581 lua_settop( cli_thread, 0 );
582 if (status != LUA_YIELD)
584 }
585 }
586 else {
587 /* Set up for concat. */
588 if (!cli_firstline) /* o */
589 lua_pushliteral(naevL, "\n"); /* o \n */
590
591 /* Load the string. */
592 lua_pushstring( naevL, str ); /* s */
593
594 /* Concat. */
595 if (!cli_firstline) /* o \n s */
596 lua_concat(naevL, 3); /* s */
597
598 status = luaL_loadbuffer( naevL, lua_tostring(naevL,-1), lua_strlen(naevL,-1), "=cli" );
599
600 /* String isn't proper Lua yet. */
601 if (status == LUA_ERRSYNTAX) {
602 size_t lmsg;
603 const char *msg = lua_tolstring(naevL, -1, &lmsg);
604 const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1);
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 const char *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 SDL_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:516
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:499
static int cli_keyhandler(unsigned int wid, SDL_Keycode key, SDL_Keymod mod, int isrepeat)
Key handler for the console window.
Definition console.c:297
#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:375
static void cli_input(unsigned int wid, const char *unused)
Handles the CLI input.
Definition console.c:543
#define CLI_WIDTH
Definition console.c:59
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:526
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:1723
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:506
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:721
int gl_fontInit(glFont *font, const char *fname, const unsigned int h, const char *prefix, unsigned int flags)
Initializes a font.
Definition font.c:1517
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.
#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
int nlua_loadStandard(nlua_env env)
Loads the standard Naev Lua API.
Definition nlua.c:798
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:49
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:54
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:93
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:67
void gl_renderRect(double x, double y, double w, double h, const glColour *c)
Renders a rectangle.
int lua_repl
Definition conf.h:160
int font_size_console
Definition conf.h:139
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
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:691
void window_setAccept(unsigned int wid, void(*accept)(unsigned int, const char *))
Sets the default accept function of the window.
Definition toolkit.c:847
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:960
int window_exists(const char *wdwname)
Checks to see if a window exists.
Definition toolkit.c:596
void window_close(unsigned int wid, const char *str)
Helper function to automatically close the window calling it.
Definition toolkit.c:1026