naev 0.12.6
nlua_tk.c File Reference

Naev toolkit Lua module. More...

#include "nlua_tk.h"
#include "array.h"
#include "dialogue.h"
#include "input.h"
#include "land.h"
#include "land_outfits.h"
#include "nlua_colour.h"
#include "nlua_gfx.h"
#include "nlua_outfit.h"
#include "nluadef.h"
#include "toolkit.h"
Include dependency graph for nlua_tk.c:

Go to the source code of this file.

Data Structures

struct  custom_functions_t

Macros

#define TK_CUSTNAME   "__cstdlg"
#define TK_CUSTOMDONE   "__customDone"
#define GETFUNC(address, pos)

Functions

static void cust_cleanup (void *data)
 Cleans up after the window.
static int cust_update (double dt, void *data)
static void cust_render (double x, double y, double w, double h, void *data)
static int cust_event (unsigned int wid, SDL_Event *event, void *data)
static int cust_key (SDL_Keycode key, SDL_Keymod mod, int pressed, int isrepeat, custom_functions_t *cf)
static int cust_text (const char *str, custom_functions_t *cf)
static int cust_mouse (int type, int button, double x, double y, custom_functions_t *cf)
static int cust_event_window (SDL_WindowEventID event, Sint32 w, Sint32 h, custom_functions_t *cf)
static int tkL_isOpen (lua_State *L)
 Bindings for interacting with the Toolkit.
static int tkL_query (lua_State *L)
 Gets the position and dimensions of either a window or a widget.
static int tkL_msg (lua_State *L)
 Creates a window with an ok button, and optionally an image.
static int tkL_yesno (lua_State *L)
 Displays a window with Yes and No buttons.
static int tkL_input (lua_State *L)
 Creates a window that allows player to write text input.
static int tkL_choice (lua_State *L)
 Creates a window with a number of selectable options.
static int tkL_list (lua_State *L)
 Creates a window with an embedded list of choices.
static int tkL_merchantOutfit (lua_State *L)
 Opens an outfit merchant window.
static int tkL_custom (lua_State *L)
 Creates a custom widget window.
static int tkL_customRename (lua_State *L)
 Renames the custom widget window.
static int tkL_customFullscreen (lua_State *L)
 Sets the custom widget fullscreen.
static int tkL_customResize (lua_State *L)
 Sets the custom widget fullscreen.
static int tkL_customSize (lua_State *L)
 Gets the size of a custom widget.
static int tkL_customDone (lua_State *L)
 Ends the execution of a custom widget.
static int tkL_refresh (lua_State *L)
 Forces the toolkit to rerender the screen.
int nlua_loadTk (nlua_env env)
 Loads the Toolkit Lua library.
static unsigned int dlgWid (lua_State *L)

Variables

static const luaL_Reg tkL_methods []

Detailed Description

Naev toolkit Lua module.

Definition in file nlua_tk.c.

Macro Definition Documentation

◆ GETFUNC

#define GETFUNC ( address,
pos )
Value:
do { \
lua_pushvalue( L, ( pos ) ); \
luaL_checktype( L, -1, LUA_TFUNCTION ); \
( address ) = luaL_ref( L, LUA_REGISTRYINDEX ); \
} while ( 0 )

◆ TK_CUSTNAME

#define TK_CUSTNAME   "__cstdlg"

Definition at line 31 of file nlua_tk.c.

◆ TK_CUSTOMDONE

#define TK_CUSTOMDONE   "__customDone"

Definition at line 32 of file nlua_tk.c.

Function Documentation

◆ cust_cleanup()

void cust_cleanup ( void * data)
static

Cleans up after the window.

Definition at line 418 of file nlua_tk.c.

◆ cust_event()

int cust_event ( unsigned int wid,
SDL_Event * event,
void * data )
static

Definition at line 651 of file nlua_tk.c.

◆ cust_event_window()

int cust_event_window ( SDL_WindowEventID event,
Sint32 w,
Sint32 h,
custom_functions_t * cf )
static

Definition at line 771 of file nlua_tk.c.

◆ cust_key()

int cust_key ( SDL_Keycode key,
SDL_Keymod mod,
int pressed,
int isrepeat,
custom_functions_t * cf )
static

Definition at line 698 of file nlua_tk.c.

◆ cust_mouse()

int cust_mouse ( int type,
int button,
double x,
double y,
custom_functions_t * cf )
static

Definition at line 736 of file nlua_tk.c.

◆ cust_render()

void cust_render ( double x,
double y,
double w,
double h,
void * data )
static

Definition at line 633 of file nlua_tk.c.

◆ cust_text()

int cust_text ( const char * str,
custom_functions_t * cf )
static

Definition at line 719 of file nlua_tk.c.

◆ cust_update()

int cust_update ( double dt,
void * data )
static

Definition at line 611 of file nlua_tk.c.

◆ dlgWid()

unsigned int dlgWid ( lua_State * L)
static

Definition at line 515 of file nlua_tk.c.

◆ nlua_loadTk()

int nlua_loadTk ( nlua_env env)

Loads the Toolkit Lua library.

Parameters
envLua environment.
Returns
0 on success.

Definition at line 98 of file nlua_tk.c.

◆ tkL_choice()

int tkL_choice ( lua_State * L)
static

Creates a window with a number of selectable options.

Lua usage parameter: num, chosen = tk.choice( "Title", "Ready to go?", "Yes", "No" ) – If "No" was clicked it would return 2, "No"

Lua function parameter: string title Title of the window. Lua function parameter: string msg Message to display. Lua function parameter: string choices Option choices. Lua return parameter: number The number of the choice chosen. Lua return parameter: string The name of the choice chosen.

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

Lua function: choice

Definition at line 279 of file nlua_tk.c.

◆ tkL_custom()

int tkL_custom ( lua_State * L)
static

Creates a custom widget window.

Lua function parameter: String title Title of the window. Lua function parameter: Number width Width of the drawable area of the widget. Lua function parameter: Number height Height of the drawable area of the widget. Lua function parameter: Function update Function to call when updating. Should take a single parameter which is a number indicating how many seconds passed from previous update. Lua function parameter: Function draw Function to call when drawing. Lua function parameter: Function keyboard Function to call when keyboard events are received. Lua function parameter: Function mouse Function to call when mouse events are received. Lua function parameter: Function resize Function to call when mouse events are received. Lua function parameter: Function textinput Function to call when textinput events are received. Lua function parameter: boolean nodynamic Whether or not the dialogue should be not dynamic, or use tk.refresh to force rerenders.

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

Lua function: custom

Definition at line 453 of file nlua_tk.c.

◆ tkL_customDone()

int tkL_customDone ( lua_State * L)
static

Ends the execution of a custom widget.

Can only stop the execution from the same environment that spawned it.

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

Lua function: customDone

Definition at line 600 of file nlua_tk.c.

◆ tkL_customFullscreen()

int tkL_customFullscreen ( lua_State * L)
static

Sets the custom widget fullscreen.

Lua function parameter: boolean enable Enable fullscreen or not.

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

Lua function: customFullscreen

Definition at line 545 of file nlua_tk.c.

◆ tkL_customRename()

int tkL_customRename ( lua_State * L)
static

Renames the custom widget window.

Lua function parameter: string displayname Name to give the custom widget window.

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

Lua function: customRename

Definition at line 529 of file nlua_tk.c.

◆ tkL_customResize()

int tkL_customResize ( lua_State * L)
static

Sets the custom widget fullscreen.

Lua function parameter: number width Width of the widget to resize to. Lua function parameter: number height Height of the widget to resize to.

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

Lua function: customResize

Definition at line 562 of file nlua_tk.c.

◆ tkL_customSize()

int tkL_customSize ( lua_State * L)
static

Gets the size of a custom widget.

Lua return parameter: number Width of the window. Lua return parameter: number Height of the window.

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

Lua function: customSize

Definition at line 581 of file nlua_tk.c.

◆ tkL_input()

int tkL_input ( lua_State * L)
static

Creates a window that allows player to write text input.

Lua usage parameter: name = tk.input( "Name", 3, 20, "Enter your name:" )

Lua function parameter: string title Title of the window. Lua function parameter: number min Minimum characters to accept (must be greater than 0). Lua function parameter: number max Maximum characters to accept. Lua function parameter: string str Text to display in the window. Lua return parameter: string|nil nil if input was canceled or a string with the text written.

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

Lua function: input

Definition at line 246 of file nlua_tk.c.

◆ tkL_isOpen()

int tkL_isOpen ( lua_State * L)
static

Bindings for interacting with the Toolkit.

These toolkit bindings are all blocking, meaning that your Lua code won't continue executing until the user closes the dialogue that popped up.

A typical example would be:

tk.msg( "Title", "This is a message." )
if tk.yesno( "YesNo popup box", "Click yes to do something." ) then
-- Player clicked yes, do something
else
-- Player clicked no
end

Lua module: tk

Gets if the toolkit is open. This include any love2d windows.

Lua return parameter: boolean Whether or not the toolkit is open.

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

Lua function: isOpen

Definition at line 131 of file nlua_tk.c.

◆ tkL_list()

int tkL_list ( lua_State * L)
static

Creates a window with an embedded list of choices.

Lua usage parameter: num, chosen = tk.list( "Title", "Foo or bar?", "Foo", "Bar" ) – If "Bar" is clicked, it would return 2, "Bar"

Lua function parameter: string title Title of the window. Lua function parameter: string msg Message to display. Lua function parameter: string choices Option choices. Lua return parameter: number The number of the choice chosen. Lua return parameter: string The name of the choice chosen.

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

Lua function: list

Definition at line 332 of file nlua_tk.c.

◆ tkL_merchantOutfit()

int tkL_merchantOutfit ( lua_State * L)
static

Opens an outfit merchant window.

Lua usage parameter: tk.merchantOutfit( 'Laser Merchant', {'Laser Cannon MK0', 'Laser Cannon MK1'} ) Lua usage parameter: tk.merchantOutfit( 'Laser Merchant', {outfit.get('Laser Cannon MK0'), outfit.get('Laser Cannon MK1')} )

Lua function parameter: String name Name of the window. Lua function parameter: Table outfits Table of outfits to sell/buy. It is possible to use either outfits or outfit names (strings). Lua function parameter: boolean blackmarket Whether or not the merchant is a black market merchant.

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

Lua function: merchantOutfit

Definition at line 381 of file nlua_tk.c.

◆ tkL_msg()

int tkL_msg ( lua_State * L)
static

Creates a window with an ok button, and optionally an image.

Lua usage parameter: tk.msg( "Title", "This is a message." ) Lua usage parameter: tk.msg( "Title", "This is a message.", "character.png" )

Lua function parameter: string title Title of the window. Lua function parameter: string message Message to display in the window. Lua function parameter:[opt=-1] string image Image file to display in the window. Lua function parameter:[opt=-1] number width width of the image to display. Negative values use image width. Lua function parameter:[opt=-1] number height height of the image to display. Negative values use image height.

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

Lua function: msg

Definition at line 192 of file nlua_tk.c.

◆ tkL_query()

int tkL_query ( lua_State * L)
static

Gets the position and dimensions of either a window or a widget.

Lua function parameter: string wdwname Name of the window. Lua function parameter:[opt] string wgtname Name of the widget to get dimensions of. If not specified, the dimensions of the window are returned. Lua return parameter: number X position of the window/widget. Lua return parameter: number Y position of the window/widget. Lua return parameter: number Width of the window/widget. Lua return parameter: number Height of the window/widget.

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

Lua function: query

Definition at line 149 of file nlua_tk.c.

◆ tkL_refresh()

int tkL_refresh ( lua_State * L)
static

Forces the toolkit to rerender the screen.

Definition at line 798 of file nlua_tk.c.

◆ tkL_yesno()

int tkL_yesno ( lua_State * L)
static

Displays a window with Yes and No buttons.

Lua usage parameter: if tk.yesno( "YesNo popup box", "Click yes to do something." ) then – Clicked yes

Lua function parameter: string title Title of the window. Lua function parameter: string message Message to display in the window. Lua return parameter: boolean true if yes was clicked, false if no was clicked.

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

Lua function: yesno

Definition at line 223 of file nlua_tk.c.

Variable Documentation

◆ tkL_methods

const luaL_Reg tkL_methods[]
static
Initial value:
= {
{ "isOpen", tkL_isOpen },
{ "query", tkL_query },
{ "msg", tkL_msg },
{ "yesno", tkL_yesno },
{ "input", tkL_input },
{ "choice", tkL_choice },
{ "list", tkL_list },
{ "merchantOutfit", tkL_merchantOutfit },
{ "custom", tkL_custom },
{ "customRename", tkL_customRename },
{ "customFullscreen", tkL_customFullscreen },
{ "customResize", tkL_customResize },
{ "customSize", tkL_customSize },
{ "customDone", tkL_customDone },
{ "refresh", tkL_refresh },
{ 0, 0 } }
static int tkL_customSize(lua_State *L)
Gets the size of a custom widget.
Definition nlua_tk.c:581
static int tkL_customRename(lua_State *L)
Renames the custom widget window.
Definition nlua_tk.c:529
static int tkL_isOpen(lua_State *L)
Bindings for interacting with the Toolkit.
Definition nlua_tk.c:131
static int tkL_msg(lua_State *L)
Creates a window with an ok button, and optionally an image.
Definition nlua_tk.c:192
static int tkL_input(lua_State *L)
Creates a window that allows player to write text input.
Definition nlua_tk.c:246
static int tkL_choice(lua_State *L)
Creates a window with a number of selectable options.
Definition nlua_tk.c:279
static int tkL_refresh(lua_State *L)
Forces the toolkit to rerender the screen.
Definition nlua_tk.c:798
static int tkL_query(lua_State *L)
Gets the position and dimensions of either a window or a widget.
Definition nlua_tk.c:149
static int tkL_yesno(lua_State *L)
Displays a window with Yes and No buttons.
Definition nlua_tk.c:223
static int tkL_customFullscreen(lua_State *L)
Sets the custom widget fullscreen.
Definition nlua_tk.c:545
static int tkL_list(lua_State *L)
Creates a window with an embedded list of choices.
Definition nlua_tk.c:332
static int tkL_customDone(lua_State *L)
Ends the execution of a custom widget.
Definition nlua_tk.c:600
static int tkL_customResize(lua_State *L)
Sets the custom widget fullscreen.
Definition nlua_tk.c:562
static int tkL_merchantOutfit(lua_State *L)
Opens an outfit merchant window.
Definition nlua_tk.c:381
static int tkL_custom(lua_State *L)
Creates a custom widget window.
Definition nlua_tk.c:453

Toolkit Lua methods.

Definition at line 74 of file nlua_tk.c.