naev 0.10.4
Data Structures | Macros | Functions | Variables
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 "log.h"
#include "nlua_colour.h"
#include "nlua_gfx.h"
#include "nlua_outfit.h"
#include "nluadef.h"
#include "toolkit.h"

Go to the source code of this file.

Data Structures

struct  custom_functions_t
 

Macros

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

Functions

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, 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. More...
 
static int tkL_query (lua_State *L)
 Gets the position and dimensions of either a window or a widget. More...
 
static int tkL_msg (lua_State *L)
 Creates a window with an ok button, and optionally an image. More...
 
static int tkL_yesno (lua_State *L)
 Displays a window with Yes and No buttons. More...
 
static int tkL_input (lua_State *L)
 Creates a window that allows player to write text input. More...
 
static int tkL_choice (lua_State *L)
 Creates a window with a number of selectable options. More...
 
static int tkL_list (lua_State *L)
 Creates a window with an embedded list of choices. More...
 
static int tkL_merchantOutfit (lua_State *L)
 Opens an outfit merchant window. More...
 
static int tkL_custom (lua_State *L)
 Creates a custom widget window. More...
 
static int tkL_customRename (lua_State *L)
 Renames the custom widget window. More...
 
static int tkL_customFullscreen (lua_State *L)
 Sets the custom widget fullscreen. More...
 
static int tkL_customResize (lua_State *L)
 Sets the custom widget fullscreen. More...
 
static int tkL_customSize (lua_State *L)
 Gets the size of a custom widget. More...
 
static int tkL_customDone (lua_State *L)
 Ends the execution of a custom widget. More...
 
int nlua_loadTk (nlua_env env)
 Loads the Toolkit Lua library. More...
 
static int cust_pcall (lua_State *L, int nargs, int nresults)
 

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_CUSTOMDONE

#define TK_CUSTOMDONE   "__customDone"

Definition at line 31 of file nlua_tk.c.

Function Documentation

◆ cust_event()

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

Definition at line 600 of file nlua_tk.c.

◆ cust_event_window()

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

Definition at line 703 of file nlua_tk.c.

◆ cust_key()

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

Definition at line 642 of file nlua_tk.c.

◆ cust_mouse()

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

Definition at line 676 of file nlua_tk.c.

◆ cust_pcall()

static int cust_pcall ( lua_State *  L,
int  nargs,
int  nresults 
)
static

Definition at line 542 of file nlua_tk.c.

◆ cust_render()

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

Definition at line 583 of file nlua_tk.c.

◆ cust_text()

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

Definition at line 660 of file nlua_tk.c.

◆ cust_update()

static int cust_update ( double  dt,
void *  data 
)
static

Definition at line 562 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 90 of file nlua_tk.c.

◆ tkL_choice()

static 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 271 of file nlua_tk.c.

◆ tkL_custom()

static 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.

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

Lua function: custom

Definition at line 416 of file nlua_tk.c.

◆ tkL_customDone()

static int tkL_customDone ( lua_State *  L)
static

Ends the execution of a custom widget.

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

Lua function: customDone

Definition at line 532 of file nlua_tk.c.

◆ tkL_customFullscreen()

static 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 480 of file nlua_tk.c.

◆ tkL_customRename()

static 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 464 of file nlua_tk.c.

◆ tkL_customResize()

static 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 497 of file nlua_tk.c.

◆ tkL_customSize()

static 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 516 of file nlua_tk.c.

◆ tkL_input()

static 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 238 of file nlua_tk.c.

◆ tkL_isOpen()

static 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 123 of file nlua_tk.c.

◆ tkL_list()

static 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 323 of file nlua_tk.c.

◆ tkL_merchantOutfit()

static 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).

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

Lua function: merchantOutfit

Definition at line 367 of file nlua_tk.c.

◆ tkL_msg()

static 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 182 of file nlua_tk.c.

◆ tkL_query()

static 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 140 of file nlua_tk.c.

◆ tkL_yesno()

static 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 214 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 },
{0,0}
}
static int tkL_customSize(lua_State *L)
Gets the size of a custom widget.
Definition: nlua_tk.c:516
static int tkL_customRename(lua_State *L)
Renames the custom widget window.
Definition: nlua_tk.c:464
static int tkL_isOpen(lua_State *L)
Bindings for interacting with the Toolkit.
Definition: nlua_tk.c:123
static int tkL_msg(lua_State *L)
Creates a window with an ok button, and optionally an image.
Definition: nlua_tk.c:182
static int tkL_input(lua_State *L)
Creates a window that allows player to write text input.
Definition: nlua_tk.c:238
static int tkL_choice(lua_State *L)
Creates a window with a number of selectable options.
Definition: nlua_tk.c:271
static int tkL_query(lua_State *L)
Gets the position and dimensions of either a window or a widget.
Definition: nlua_tk.c:140
static int tkL_yesno(lua_State *L)
Displays a window with Yes and No buttons.
Definition: nlua_tk.c:214
static int tkL_customFullscreen(lua_State *L)
Sets the custom widget fullscreen.
Definition: nlua_tk.c:480
static int tkL_list(lua_State *L)
Creates a window with an embedded list of choices.
Definition: nlua_tk.c:323
static int tkL_customDone(lua_State *L)
Ends the execution of a custom widget.
Definition: nlua_tk.c:532
static int tkL_customResize(lua_State *L)
Sets the custom widget fullscreen.
Definition: nlua_tk.c:497
static int tkL_merchantOutfit(lua_State *L)
Opens an outfit merchant window.
Definition: nlua_tk.c:367
static int tkL_custom(lua_State *L)
Creates a custom widget window.
Definition: nlua_tk.c:416

Toolkit Lua methods.

Definition at line 66 of file nlua_tk.c.