naev 0.11.5
console.c File Reference

Handles the Lua console. More...

#include "console.h"
#include "array.h"
#include "conf.h"
#include "font.h"
#include "log.h"
#include "menu.h"
#include "naev.h"
#include "ndata.h"
#include "nfile.h"
#include "nlua.h"
#include "nlua_audio.h"
#include "nlua_bkg.h"
#include "nlua_camera.h"
#include "nlua_cli.h"
#include "nlua_colour.h"
#include "nlua_linopt.h"
#include "nlua_music.h"
#include "nlua_tex.h"
#include "nlua_tk.h"
#include "nluadef.h"
#include "nstring.h"
#include "toolkit.h"

Go to the source code of this file.

Macros

#define BUTTON_WIDTH   50
 
#define BUTTON_HEIGHT   20
 
#define CLI_MAX_INPUT   STRMAX_SHORT /** Maximum characters typed into console. */
 
#define CLI_WIDTH   (SCREEN_W - 100)
 
#define CLI_HEIGHT   (SCREEN_H - 100)
 
#define CLI_MAX_LINES   (cli_max_lines)
 

Functions

static int cli_script (lua_State *L)
 Would be like "dofile" from the base Lua lib.
 
static int cli_keyhandler (unsigned int wid, SDL_Keycode key, SDL_Keymod mod, int isrepeat)
 Key handler for the console window.
 
static void cli_render (double bx, double by, double w, double h, void *data)
 Render function for the custom widget.
 
static void cli_printCoreString (const char *s, int escape)
 Prints a string.
 
static int cli_printCore (lua_State *L, int cli_only, int escape)
 Back end for the Lua print functionality.
 
static void cli_addMessage (const char *msg)
 Adds a message to the buffer.
 
static void cli_addMessageMax (const char *msg, const int l)
 Adds a message to the buffer.
 
void cli_tabComplete (unsigned int wid)
 Basic tab completion for console.
 
static int cli_initLua (void)
 
static char * cli_escapeString (int *len_out, const char *s, int len)
 
int cli_warn (lua_State *L)
 Barebones warn implementation for Lua, allowing scripts to print warnings to stderr.
 
int cli_print (lua_State *L)
 Replacement for the internal Lua print to print to both the console and the terminal.
 
int cli_printRaw (lua_State *L)
 Prints raw markup to the console.
 
int cli_init (void)
 Initializes the CLI environment.
 
void cli_exit (void)
 Destroys the CLI environment.
 
static void cli_input (unsigned int wid, const char *unused)
 Handles the CLI input.
 
void cli_open (void)
 Opens the console.
 
int cli_isOpen (void)
 

Variables

static nlua_env cli_env = LUA_NOREF
 
static lua_State * cli_thread = NULL
 
static int cli_thread_ref = LUA_NOREF
 
static glFontcli_font = NULL
 
static char ** cli_buffer
 
static char * cli_prompt
 
static int cli_history = 0
 
static int cli_scroll_pos = -1
 
static int cli_firstOpen = 1
 
static int cli_firstline = 1
 
static int cli_height = 0
 
static int cli_max_lines = 0
 
static const luaL_Reg cli_methods []
 

Detailed Description

Handles the Lua console.

Definition in file console.c.

Macro Definition Documentation

◆ BUTTON_HEIGHT

#define BUTTON_HEIGHT   20

Button height.

Definition at line 45 of file console.c.

◆ BUTTON_WIDTH

#define BUTTON_WIDTH   50

Button width.

Definition at line 44 of file console.c.

◆ CLI_HEIGHT

#define CLI_HEIGHT   (SCREEN_H - 100)

Console height.

Definition at line 60 of file console.c.

◆ CLI_MAX_INPUT

#define CLI_MAX_INPUT   STRMAX_SHORT /** Maximum characters typed into console. */

Definition at line 58 of file console.c.

◆ CLI_MAX_LINES

#define CLI_MAX_LINES   (cli_max_lines)

Number of lines displayed at once

Definition at line 70 of file console.c.

◆ CLI_WIDTH

#define CLI_WIDTH   (SCREEN_W - 100)

Console width.

Definition at line 59 of file console.c.

Function Documentation

◆ cli_addMessage()

static void cli_addMessage ( const char * msg)
static

Adds a message to the buffer.

Parameters
msgMessage to add.

Definition at line 244 of file console.c.

◆ cli_addMessageMax()

static void cli_addMessageMax ( const char * msg,
const int l )
static

Adds a message to the buffer.

Parameters
msgMessage to add.
lMax message length.

Definition at line 261 of file console.c.

◆ cli_escapeString()

static char * cli_escapeString ( int * len_out,
const char * s,
int len )
static

Definition at line 94 of file console.c.

◆ cli_exit()

void cli_exit ( void )

Destroys the CLI environment.

Definition at line 516 of file console.c.

◆ cli_init()

int cli_init ( void )

Initializes the CLI environment.

Definition at line 499 of file console.c.

◆ cli_initLua()

static int cli_initLua ( void )
static

Definition at line 438 of file console.c.

◆ cli_input()

static void cli_input ( unsigned int wid,
const char * unused )
static

Handles the CLI input.

Parameters
widWindow receiving the input.
unusedUnused.

Definition at line 543 of file console.c.

◆ cli_isOpen()

int cli_isOpen ( void )

Definition at line 708 of file console.c.

◆ cli_keyhandler()

static int cli_keyhandler ( unsigned int wid,
SDL_Keycode key,
SDL_Keymod mod,
int isrepeat )
static

Key handler for the console window.

Definition at line 297 of file console.c.

◆ cli_open()

void cli_open ( void )

Opens the console.

Definition at line 654 of file console.c.

◆ cli_print()

int cli_print ( lua_State * L)

Replacement for the internal Lua print to print to both the console and the terminal.

Definition at line 178 of file console.c.

◆ cli_printCore()

static int cli_printCore ( lua_State * L,
int cli_only,
int escape )
static

Back end for the Lua print functionality.

Definition at line 131 of file console.c.

◆ cli_printCoreString()

static void cli_printCoreString ( const char * s,
int escape )
static

Prints a string.

Definition at line 111 of file console.c.

◆ cli_printRaw()

int cli_printRaw ( lua_State * L)

Prints raw markup to the console.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: printRaw

Definition at line 188 of file console.c.

◆ cli_render()

static void cli_render ( double bx,
double by,
double w,
double h,
void * data )
static

Render function for the custom widget.

Definition at line 275 of file console.c.

◆ cli_script()

static int cli_script ( lua_State * L)
static

Would be like "dofile" from the base Lua lib.

Definition at line 196 of file console.c.

◆ cli_tabComplete()

void cli_tabComplete ( unsigned int wid)

Basic tab completion for console.

Definition at line 375 of file console.c.

◆ cli_warn()

int cli_warn ( lua_State * L)

Barebones warn implementation for Lua, allowing scripts to print warnings to stderr.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: warn

Definition at line 166 of file console.c.

Variable Documentation

◆ cli_buffer

char** cli_buffer
static

CLI buffer.

Definition at line 61 of file console.c.

◆ cli_env

nlua_env cli_env = LUA_NOREF
static

Lua CLI env.

Definition at line 50 of file console.c.

◆ cli_firstline

int cli_firstline = 1
static

Original CLI: Is this the first line?

Definition at line 66 of file console.c.

◆ cli_firstOpen

int cli_firstOpen = 1
static

First time opening.

Definition at line 65 of file console.c.

◆ cli_font

glFont* cli_font = NULL
static

CLI font to use.

Definition at line 53 of file console.c.

◆ cli_height

int cli_height = 0
static

Definition at line 67 of file console.c.

◆ cli_history

int cli_history = 0
static

Position in history.

Definition at line 63 of file console.c.

◆ cli_max_lines

int cli_max_lines = 0
static

Definition at line 68 of file console.c.

◆ cli_methods

const luaL_Reg cli_methods[]
static
Initial value:
= {
{ "script", cli_script },
{ "warn", cli_warn },
{NULL, NULL}
}
int cli_warn(lua_State *L)
Barebones warn implementation for Lua, allowing scripts to print warnings to stderr.
Definition console.c:166
static int cli_script(lua_State *L)
Would be like "dofile" from the base Lua lib.
Definition console.c:196

Console only functions.

Definition at line 76 of file console.c.

◆ cli_prompt

char* cli_prompt
static

Prompt string (allocated).

Definition at line 62 of file console.c.

◆ cli_scroll_pos

int cli_scroll_pos = -1
static

Position in scrolling through output

Definition at line 64 of file console.c.

◆ cli_thread

lua_State* cli_thread = NULL
static

REPL coroutine's thread

Definition at line 51 of file console.c.

◆ cli_thread_ref

int cli_thread_ref = LUA_NOREF
static

Reference keeping cli_thread alive

Definition at line 52 of file console.c.