naev 0.12.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 "nlua.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"
Include dependency graph for console.c:

Go to the source code of this file.

Macros

#define BUTTON_WIDTH   50
#define BUTTON_HEIGHT   20
#define CLI_MAX_INPUT
#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 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)
void cli_printCoreString (const char *s, int escape)
 Prints a string.
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
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 43 of file console.c.

◆ BUTTON_WIDTH

#define BUTTON_WIDTH   50

Button width.

Definition at line 42 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
Value:
STRMAX_SHORT

Definition at line 57 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()

void cli_addMessage ( const char * msg)
static

Adds a message to the buffer.

Parameters
msgMessage to add.

Definition at line 248 of file console.c.

◆ cli_addMessageMax()

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 265 of file console.c.

◆ cli_escapeString()

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

Definition at line 93 of file console.c.

◆ cli_exit()

void cli_exit ( void )

Destroys the CLI environment.

Definition at line 528 of file console.c.

◆ cli_init()

int cli_init ( void )

Initializes the CLI environment.

Definition at line 508 of file console.c.

◆ cli_initLua()

int cli_initLua ( void )
static

Definition at line 446 of file console.c.

◆ cli_input()

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

Handles the CLI input.

Parameters
widWindow receiving the input.
unusedUnused.

Definition at line 555 of file console.c.

◆ cli_isOpen()

int cli_isOpen ( void )

Definition at line 717 of file console.c.

◆ cli_keyhandler()

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

Key handler for the console window.

Definition at line 301 of file console.c.

◆ cli_open()

void cli_open ( void )

Opens the console.

Definition at line 662 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()

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

Back end for the Lua print functionality.

Definition at line 130 of file console.c.

◆ cli_printCoreString()

void cli_printCoreString ( const char * s,
int escape )

Prints a string.

Definition at line 110 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()

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

Render function for the custom widget.

Definition at line 279 of file console.c.

◆ cli_script()

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 382 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 169 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 48 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 52 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:169
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 49 of file console.c.

◆ cli_thread_ref

int cli_thread_ref
static
Initial value:
=
LUA_NOREF

Reference keeping cli_thread alive

Definition at line 50 of file console.c.