naev 0.12.6
nlua_naev.c File Reference

Contains Naev generic Lua bindings. More...

#include "nlua_naev.h"
#include "array.h"
#include "console.h"
#include "debug.h"
#include "difficulty.h"
#include "event.h"
#include "hook.h"
#include "info.h"
#include "input.h"
#include "land.h"
#include "menu.h"
#include "nlua_misn.h"
#include "nlua_system.h"
#include "nluadef.h"
#include "pause.h"
#include "player.h"
#include "plugin.h"
#include "semver.h"
Include dependency graph for nlua_naev.c:

Go to the source code of this file.

Macros

#define setfield(L, key, value)
#define setboolfield(L, key, value)
#define PUSH_STRING(L, name, value)
#define PUSH_DOUBLE(L, name, value)
#define PUSH_INT(L, name, value)
#define PUSH_BOOL(L, name, value)
#define STRING(x)
#define INTEGER(x)
#define BOOL(x)

Functions

static int naevL_version (lua_State *L)
 Naev generic Lua bindings.
static int naevL_versionTest (lua_State *L)
 Tests two semver version strings.
static int naevL_language (lua_State *L)
 Gets the current language locale.
static int naevL_lastplayed (lua_State *L)
 Gets how many days it has been since the player last played Naev.
static int naevL_date (lua_State *L)
 Equivalent to os.date from standard Lua.
static int naevL_ticks (lua_State *L)
 Gets the seconds since the program started running.
static int naevL_ticksGame (lua_State *L)
 Gets the game seconds since the program started running.
static int naevL_clock (lua_State *L)
 Gets the approximate CPU processing time.
static int naevL_fps (lua_State *L)
 Gets the current game FPS as displayed to the player.
static int naevL_keyGet (lua_State *L)
 Gets a human-readable name for the key bound to a function.
static int naevL_keyEnable (lua_State *L)
 Disables or enables a specific keybinding.
static int naevL_keyEnableAll (lua_State *L)
 Enables all inputs.
static int naevL_keyDisableAll (lua_State *L)
 Disables all inputs.
static int naevL_eventStart (lua_State *L)
 Starts an event, does not start check conditions.
static int naevL_eventReload (lua_State *L)
 Reloads an event's script, providing a convenient way to test and hopefully not corrupt the game's state. Use with caution, and only during development as a way to get quicker feedback.
static int naevL_missionList (lua_State *L)
 Lists all the missions in the game.
static int naevL_missionStart (lua_State *L)
 Starts a mission, does no check start conditions.
static int naevL_missionTest (lua_State *L)
 Tests a missions conditionals to see if it can be started by the player.
static int naevL_missionReload (lua_State *L)
 Reloads a mission's script, providing a convenient way to test and hopefully not corrupt the game's state. Use with caution, and only during development as a way to get quicker feedback.
static int naevL_shadersReload (lua_State *L)
 Reloads all the Naev shaders excluding those created by the shader library.
static int naevL_isSimulation (lua_State *L)
 Gets whether or not the universe is being simulated or not.
static int naevL_conf (lua_State *L)
 Gets the configuration information.
static int naevL_confSet (lua_State *L)
 Sets configuration variables. Note that not all are supported.
static int naevL_cache (lua_State *L)
 Gets the global Lua runtime cache. This is shared among all environments and is cleared when the game is closed.
static int naevL_trigger (lua_State *L)
 Triggers manually a hook stack. This is run deferred (next frame). Meant mainly to be used with hook.custom, but can work with other hooks too (if you know what you are doing).
static int naevL_claimTest (lua_State *L)
 Tests a claim of a system or strings.
static int naevL_plugins (lua_State *L)
 Gets the list of available plugins.
static int naevL_menuInfo (lua_State *L)
 Opens the info menu window.
static int naevL_menuSmall (lua_State *L)
 Opens the small menu window.
static int naevL_isPaused (lua_State *L)
 Checks to see if the game is paused.
static int naevL_pause (lua_State *L)
 Pauses the game.
static int naevL_unpause (lua_State *L)
 Unpauses the game.
static int naevL_hasTextInput (lua_State *L)
 Checks to see if text inputting is enabled.
static int naevL_setTextInput (lua_State *L)
 Enables or disables text inputting.
static int naevL_unit (lua_State *L)
 Gets the translated string corresponding to an in-game unit. Lua function parameter:[opt=nil] string str Name of the unit to get or nil to get a table with all of them. Lua return parameter: Translated string corresponding to the unit or table of all strings if no parameter is passed.
static int naevL_quadtreeParams (lua_State *L)
 Modifies the Naev internal quadtree lookup parameters.
static int naevL_difficulty (lua_State *L)
 Gets information about the current difficulty setting.
int nlua_loadNaev (nlua_env env)
 Loads the Naev Lua library.

Variables

static int cache_table = LUA_NOREF
static const luaL_Reg naev_methods []
static const char * unittbl []

Detailed Description

Contains Naev generic Lua bindings.

Definition in file nlua_naev.c.

Macro Definition Documentation

◆ BOOL

#define BOOL ( x)
Value:
lua_pushboolean( L, plg->x ); \
lua_setfield( L, -2, #x )

◆ INTEGER

#define INTEGER ( x)
Value:
lua_pushinteger( L, plg->x ); \
lua_setfield( L, -2, #x )

◆ PUSH_BOOL

#define PUSH_BOOL ( L,
name,
value )
Value:
lua_pushstring( L, name ); \
lua_pushboolean( L, value ); \
lua_rawset( L, -3 )

Definition at line 574 of file nlua_naev.c.

◆ PUSH_DOUBLE

#define PUSH_DOUBLE ( L,
name,
value )
Value:
lua_pushstring( L, name ); \
lua_pushnumber( L, value ); \
lua_rawset( L, -3 )

Definition at line 566 of file nlua_naev.c.

◆ PUSH_INT

#define PUSH_INT ( L,
name,
value )
Value:
lua_pushstring( L, name ); \
lua_pushinteger( L, value ); \
lua_rawset( L, -3 )

Definition at line 570 of file nlua_naev.c.

◆ PUSH_STRING

#define PUSH_STRING ( L,
name,
value )
Value:
lua_pushstring( L, name ); \
lua_pushstring( L, value ); \
lua_rawset( L, -3 )

Definition at line 562 of file nlua_naev.c.

◆ setboolfield

#define setboolfield ( L,
key,
value )
Value:
do { \
if ( value >= 0 ) { \
lua_pushinteger( L, value ); \
lua_setfield( L, -2, key ); \
} \
} while ( 0 )

◆ setfield

#define setfield ( L,
key,
value )
Value:
do { \
lua_pushinteger( L, value ); \
lua_setfield( L, -2, key ); \
} while ( 0 )

◆ STRING

#define STRING ( x)
Value:
lua_pushstring( L, plg->x ); \
lua_setfield( L, -2, #x )

Function Documentation

◆ naevL_cache()

int naevL_cache ( lua_State * L)
static

Gets the global Lua runtime cache. This is shared among all environments and is cleared when the game is closed.

Lua usage parameter: c = naev.cache()

Lua return parameter: table The Lua global cache.

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

Lua function: cache

Definition at line 678 of file nlua_naev.c.

◆ naevL_claimTest()

int naevL_claimTest ( lua_State * L)
static

Tests a claim of a system or strings.

Lua usage parameter: if not naev.claimTest( { system.get("Gamma Polaris") } ) then print("Failed to claim!") end

Lua function parameter: System|String|{System,String...} params Table of systems/strings to claim or a single system/string. Lua function parameter:[opt=false] boolean inclusive Whether or not to allow the claim to include other inclusive claims. Multiple missions/events can inclusively claim the same system, but only one system can exclusively claim it. Lua return parameter: boolean true if it is possible to claim, false otherwise.

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

Lua function: claimTest

Definition at line 734 of file nlua_naev.c.

◆ naevL_clock()

int naevL_clock ( lua_State * L)
static

Gets the approximate CPU processing time.

Lua return parameter: number Seconds elapsed since start of the process.

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

Lua function: clock

Definition at line 333 of file nlua_naev.c.

◆ naevL_conf()

int naevL_conf ( lua_State * L)
static

Gets the configuration information.

Lua return parameter: table Table of configuration values as they appear in the configuration file.

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

Lua function: conf

Definition at line 585 of file nlua_naev.c.

◆ naevL_confSet()

int naevL_confSet ( lua_State * L)
static

Sets configuration variables. Note that not all are supported.

Lua function parameter: string name Configuration variable name. Lua function parameter: number|string value Value to set to.

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

Lua function: confSet

Definition at line 662 of file nlua_naev.c.

◆ naevL_date()

int naevL_date ( lua_State * L)
static

Equivalent to os.date from standard Lua.

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

Lua function: date

Definition at line 239 of file nlua_naev.c.

◆ naevL_difficulty()

int naevL_difficulty ( lua_State * L)
static

Gets information about the current difficulty setting.

Lua function parameter: boolean internal Whether or not to get values using the internal format, or a human readable format. Lua return parameter: string Name (untranslated) of the difficulty setting. Lua return parameter: table Table containing the ship stats (name is key, while value is value).

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

Lua function: difficulty

Definition at line 1024 of file nlua_naev.c.

◆ naevL_eventReload()

int naevL_eventReload ( lua_State * L)
static

Reloads an event's script, providing a convenient way to test and hopefully not corrupt the game's state. Use with caution, and only during development as a way to get quicker feedback.

Lua usage parameter: naev.eventReload( "Some Event" ) Lua function parameter: string evtname Name of the event to start. Lua return parameter: boolean true on success.

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

Lua function: eventReload

Definition at line 508 of file nlua_naev.c.

◆ naevL_eventStart()

int naevL_eventStart ( lua_State * L)
static

Starts an event, does not start check conditions.

Lua usage parameter: naev.eventStart( "Some Event" ) Lua function parameter: string evtname Name of the event to start. Lua return parameter: boolean true on success.

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

Lua function: eventStart

Definition at line 423 of file nlua_naev.c.

◆ naevL_fps()

int naevL_fps ( lua_State * L)
static

Gets the current game FPS as displayed to the player.

Lua return parameter: number Current FPS as displayed to the player.

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

Lua function: fps

Definition at line 345 of file nlua_naev.c.

◆ naevL_hasTextInput()

int naevL_hasTextInput ( lua_State * L)
static

Checks to see if text inputting is enabled.

Lua return parameter: boolean Whether or not text inputting is enabled.

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

Lua function: hasTextInput

Definition at line 925 of file nlua_naev.c.

◆ naevL_isPaused()

int naevL_isPaused ( lua_State * L)
static

Checks to see if the game is paused.

Lua return parameter: boolean Whether or not the game is currently paused.

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

Lua function: pause

Definition at line 886 of file nlua_naev.c.

◆ naevL_isSimulation()

int naevL_isSimulation ( lua_State * L)
static

Gets whether or not the universe is being simulated or not.

Lua return parameter: boolean true if the world is being simulated.

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

Lua function: isSimulation

Definition at line 556 of file nlua_naev.c.

◆ naevL_keyDisableAll()

int naevL_keyDisableAll ( lua_State * L)
static

Disables all inputs.

Lua usage parameter: naev.keyDisableAll() – Disables all inputs

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

Lua function: keyDisableAll

Definition at line 408 of file nlua_naev.c.

◆ naevL_keyEnable()

int naevL_keyEnable ( lua_State * L)
static

Disables or enables a specific keybinding.

Use with caution, this can make the player get stuck.

Lua usage parameter: naev.keyEnable( "accel", false ) – Disables the acceleration key Lua function parameter: string keyname Name of the key to disable (for example "accel"). Lua function parameter:[opt=false] boolean enable Whether to enable or disable.

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

Lua function: keyEnable

Definition at line 380 of file nlua_naev.c.

◆ naevL_keyEnableAll()

int naevL_keyEnableAll ( lua_State * L)
static

Enables all inputs.

Lua usage parameter: naev.keyEnableAll() – Enables all inputs

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

Lua function: keyEnableAll

Definition at line 395 of file nlua_naev.c.

◆ naevL_keyGet()

int naevL_keyGet ( lua_State * L)
static

Gets a human-readable name for the key bound to a function.

Lua usage parameter: bindname = naev.keyGet( "accel" )

Lua function parameter: string keyname Name of the keybinding to get value of. Valid values are listed in src/input.c: keybind_info.

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

Lua function: keyGet

Definition at line 360 of file nlua_naev.c.

◆ naevL_language()

int naevL_language ( lua_State * L)
static

Gets the current language locale.

Lua return parameter: string Current language locale (such as "en" for English, "de" for German, or "ja" for Japanese).

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

Lua function: language

Definition at line 212 of file nlua_naev.c.

◆ naevL_lastplayed()

int naevL_lastplayed ( lua_State * L)
static

Gets how many days it has been since the player last played Naev.

Lua return parameter: number Number of days since the player last played. Lua return parameter: number Number of days since any of the save games were played.

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

Lua function: lastplayed

Definition at line 225 of file nlua_naev.c.

◆ naevL_menuInfo()

int naevL_menuInfo ( lua_State * L)
static

Opens the info menu window.

Possible window targets are:

  • "main" : Main window.
  • "ship" : Ship info window.
  • "weapons" : Weapon configuration window.
  • "cargo" : Cargo view window.
  • "missions" : Mission view window.
  • "standings" : Standings view window.

Lua usage parameter: naev.menuInfo( "ship" ) – Opens ship tab

Lua function parameter:[opt="main"] string window parameter indicating the tab to open at.

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

Lua function: menuInfo

Definition at line 824 of file nlua_naev.c.

◆ naevL_menuSmall()

int naevL_menuSmall ( lua_State * L)
static

Opens the small menu window.

Lua usage parameter: naev.menuSmall()

Lua function parameter:[opt=false] boolean info Show the info button. Lua function parameter:[opt=false] boolean options Show the options button. Lua function parameter:[opt=false] boolean allowsave Allow saving the game from the menu (either directly or by exiting the game from the menu).

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

Lua function: menuSmall

Definition at line 873 of file nlua_naev.c.

◆ naevL_missionList()

int naevL_missionList ( lua_State * L)
static

Lists all the missions in the game.

Lua return parameter: table A table of all the missions in the game, each as a table.

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

Lua function: missionList

Definition at line 442 of file nlua_naev.c.

◆ naevL_missionReload()

int naevL_missionReload ( lua_State * L)
static

Reloads a mission's script, providing a convenient way to test and hopefully not corrupt the game's state. Use with caution, and only during development as a way to get quicker feedback.

Lua usage parameter: naev.missionReload( "Some Mission" ) Lua function parameter: string misnname Name of the mission to start. Lua return parameter: boolean true on success.

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

Lua function: missionReload

Definition at line 527 of file nlua_naev.c.

◆ naevL_missionStart()

int naevL_missionStart ( lua_State * L)
static

Starts a mission, does no check start conditions.

Lua usage parameter: naev.missionStart( "Some Mission" ) Lua function parameter: string misnname Name of the mission to start. Lua return parameter: boolean true if mission was either accepted, or started without misn.finish() getting called in create. Lua return parameter: boolean true whether or not the mission was accepted.

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

Lua function: missionStart

Definition at line 463 of file nlua_naev.c.

◆ naevL_missionTest()

int naevL_missionTest ( lua_State * L)
static

Tests a missions conditionals to see if it can be started by the player.

Note that this tests the Lua conditionals, not the create function, so it may be possible that even though naev.missionTest returns true, the player can still not start the mission.

Lua usage parameter: naev.missionTest( "Some Mission" ) Lua function parameter: string misnname Name of the mission to test. Lua return parameter: boolean true if the mission can be can be started, or false otherwise.

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

Lua function: missionTest

Definition at line 492 of file nlua_naev.c.

◆ naevL_pause()

int naevL_pause ( lua_State * L)
static

Pauses the game.

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

Lua function: pause

Definition at line 897 of file nlua_naev.c.

◆ naevL_plugins()

int naevL_plugins ( lua_State * L)
static

Gets the list of available plugins.

Lua return parameter: table Table containing the list of plugins.

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

Lua function: plugins

Definition at line 768 of file nlua_naev.c.

◆ naevL_quadtreeParams()

int naevL_quadtreeParams ( lua_State * L)
static

Modifies the Naev internal quadtree lookup parameters.

Lua function parameter: number max_elem Maximum amount of elements to allow in a leaf node. Lua function parameter: number depth depth Maximum depth to allow.

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

Lua function: quadtreeParams

Definition at line 1006 of file nlua_naev.c.

◆ naevL_setTextInput()

int naevL_setTextInput ( lua_State * L)
static

Enables or disables text inputting.

Lua function parameter: boolean enable Whether text input events should be enabled. Lua function parameter: integer Text rectangle x position. Lua function parameter: integer Text rectangle y position. Lua function parameter: integer Text rectangle width. Lua function parameter: integer Text rectangle height.

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

Lua function: setTextInput

Definition at line 941 of file nlua_naev.c.

◆ naevL_shadersReload()

int naevL_shadersReload ( lua_State * L)
static

Reloads all the Naev shaders excluding those created by the shader library.

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

Lua function: shadersReload

Definition at line 542 of file nlua_naev.c.

◆ naevL_ticks()

int naevL_ticks ( lua_State * L)
static

Gets the seconds since the program started running.

Useful for doing timing on Lua functions.

Lua return parameter: number The seconds since the application started running.

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

Lua function: ticks

Definition at line 320 of file nlua_naev.c.

◆ naevL_ticksGame()

int naevL_ticksGame ( lua_State * L)
static

Gets the game seconds since the program started running.

These are modified by whatever speed up the player has.

Lua return parameter: number The seconds since the application started running.

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

Lua function: ticksGame

Definition at line 306 of file nlua_naev.c.

◆ naevL_trigger()

int naevL_trigger ( lua_State * L)
static

Triggers manually a hook stack. This is run deferred (next frame). Meant mainly to be used with hook.custom, but can work with other hooks too (if you know what you are doing).

Note
This will trigger all hooks waiting on a stack.

Lua usage parameter: naev.trigger( "my_event", data ) – data will be passed to the receiving end

Lua function parameter: string hookname Name of the hook to be run. Lua function parameter: arg Parameter to pass to the hooks.

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

Lua function: trigger

Definition at line 699 of file nlua_naev.c.

◆ naevL_unit()

int naevL_unit ( lua_State * L)
static

Gets the translated string corresponding to an in-game unit. Lua function parameter:[opt=nil] string str Name of the unit to get or nil to get a table with all of them. Lua return parameter: Translated string corresponding to the unit or table of all strings if no parameter is passed.

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

Lua function: unit

Definition at line 975 of file nlua_naev.c.

◆ naevL_unpause()

int naevL_unpause ( lua_State * L)
static

Unpauses the game.

Can not be run while landed.

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

Lua function: unpause

Definition at line 911 of file nlua_naev.c.

◆ naevL_version()

int naevL_version ( lua_State * L)
static

Naev generic Lua bindings.

Lua module: naev

Gets the version of Naev and the save game.

Lua usage parameter: game_version, save_version = naev.version()

Lua return parameter: string The version of the game. Lua return parameter: string Version of current loaded save or nil if not loaded.

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

Lua function: version

Definition at line 163 of file nlua_naev.c.

◆ naevL_versionTest()

int naevL_versionTest ( lua_State * L)
static

Tests two semver version strings.

Lua function parameter: string v1 Version 1 to test. Lua function parameter: string v2 Version 2 to test. Lua return parameter: number Positive if v1 is newer or negative if v2 is newer.

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

Lua function: versionTest

Definition at line 181 of file nlua_naev.c.

◆ nlua_loadNaev()

int nlua_loadNaev ( nlua_env env)

Loads the Naev Lua library.

Parameters
envLua environment.
Returns
0 on success.

Definition at line 135 of file nlua_naev.c.

Variable Documentation

◆ cache_table

int cache_table = LUA_NOREF
static

Definition at line 38 of file nlua_naev.c.

◆ naev_methods

const luaL_Reg naev_methods[]
static

Naev Lua methods.

Definition at line 84 of file nlua_naev.c.

◆ unittbl

const char* unittbl[]
static
Initial value:
= {
"time", _UNIT_TIME, "per_time", _UNIT_PER_TIME, "distance",
_UNIT_DISTANCE, "speed", _UNIT_SPEED, "accel", _UNIT_ACCEL,
"energy", _UNIT_ENERGY, "power", _UNIT_POWER, "angle",
_UNIT_ANGLE, "rotation", _UNIT_ROTATION, "mass", _UNIT_MASS,
"cpu", _UNIT_CPU, "unit", _UNIT_UNIT, "percent",
_UNIT_PERCENT,
}

Definition at line 959 of file nlua_naev.c.