naev 0.12.6
nlua_asteroid.c File Reference

Bindings for asteroids from Lua. More...

#include "nlua_asteroid.h"
#include "array.h"
#include "nlua_commodity.h"
#include "nlua_pilot.h"
#include "nlua_vec2.h"
#include "nluadef.h"
#include "rng.h"
#include "space.h"
Include dependency graph for nlua_asteroid.c:

Go to the source code of this file.

Functions

static int asteroidL_eq (lua_State *L)
 Lua bindings to interact with asteroid.
static int asteroidL_tostring (lua_State *L)
 Gets the asteroid's current (translated) name or notes it is inexistent.
static int asteroidL_getAll (lua_State *L)
 Gets all the asteroids in the system.
static int asteroidL_get (lua_State *L)
 Gets an asteroid in the system.
static int asteroidL_exists (lua_State *L)
 Checks to see if an asteroid exists.
static int asteroidL_state (lua_State *L)
 Gets the state of an asteroid.
static int asteroidL_setState (lua_State *L)
 Sets the state of an asteroid.
static int asteroidL_field (lua_State *L)
 Gets the field the asteroid belongs to (useful for getting more asteroids from the same field).
static int asteroidL_pos (lua_State *L)
 Gets the position of an asteroid.
static int asteroidL_vel (lua_State *L)
 Gets the velocity of an asteroid.
static int asteroidL_setPos (lua_State *L)
 Sets the position of an asteroid.
static int asteroidL_setVel (lua_State *L)
 Sets the velocity of an asteroid.
static int asteroidL_scanned (lua_State *L)
 Gets whether or not an asteroid got scanned.
static int asteroidL_timer (lua_State *L)
 Gets the time left on the asteroid.
static int asteroidL_setTimer (lua_State *L)
 Sets the time left on the asteroid.
static int asteroidL_armour (lua_State *L)
 Gets the armour (health) left on the asteroid.
static int asteroidL_setArmour (lua_State *L)
 Sets the armour of the asteroid.
static int asteroidL_alertRange (lua_State *L)
 Gets the alert range of an asteroid.
static int asteroidL_materials (lua_State *L)
 Gets the materials the asteroid can potentially drop.
int nlua_loadAsteroid (nlua_env env)
 Loads the asteroid library.
LuaAsteroid_tlua_toasteroid (lua_State *L, int ind)
 Gets asteroid at index.
LuaAsteroid_tluaL_checkasteroid (lua_State *L, int ind)
 Gets asteroid at index or raises error if there is no asteroid at index.
AsteroidluaL_validasteroid (lua_State *L, int ind)
 Gets asteroid at index raising an error if type doesn't match.
LuaAsteroid_tlua_pushasteroid (lua_State *L, LuaAsteroid_t asteroid)
 Pushes a asteroid on the stack.
int lua_isasteroid (lua_State *L, int ind)
 Checks to see if ind is a asteroid.

Variables

static const luaL_Reg asteroidL_methods []

Detailed Description

Bindings for asteroids from Lua.

Definition in file nlua_asteroid.c.

Function Documentation

◆ asteroidL_alertRange()

int asteroidL_alertRange ( lua_State * L)
static

Gets the alert range of an asteroid.

Lua function parameter: Asteroid a Asteroid to get alert range of. Lua return parameter: number Alert range of the asteroid.

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

Lua function: alertRange

Definition at line 618 of file nlua_asteroid.c.

◆ asteroidL_armour()

int asteroidL_armour ( lua_State * L)
static

Gets the armour (health) left on the asteroid.

Lua function parameter: Asteroid a Asteroid to get armour of. Lua return parameter: number Armour left before the asteroid is destroyed.

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

Lua function: armour

Definition at line 587 of file nlua_asteroid.c.

◆ asteroidL_eq()

int asteroidL_eq ( lua_State * L)
static

Lua bindings to interact with asteroid.

Lua module: asteroid

Compares two asteroids to see if they are the same.

Lua function parameter: Asteroid a1 Asteroid 1 to compare. Lua function parameter: Asteroid a2 Asteroid 2 to compare. Lua return parameter: boolean true if both asteroids are the same.

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

Lua function: __eq

Definition at line 200 of file nlua_asteroid.c.

◆ asteroidL_exists()

int asteroidL_exists ( lua_State * L)
static

Checks to see if an asteroid exists.

Lua function parameter: Asteroid a Asteroid to check to see if exists. Lua return parameter: boolean true if te asteroid exists, false otherwise.

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

Lua function: exists

Definition at line 362 of file nlua_asteroid.c.

◆ asteroidL_field()

int asteroidL_field ( lua_State * L)
static

Gets the field the asteroid belongs to (useful for getting more asteroids from the same field).

Lua function parameter: Asteroid a Asteroid to get what field it belongs to. Lua return parameter: number ID of the field the asteroid belongs to.

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

Lua function: field

Definition at line 470 of file nlua_asteroid.c.

◆ asteroidL_get()

int asteroidL_get ( lua_State * L)
static

Gets an asteroid in the system.

Lua function parameter: nil|number|Vector|Pilot If not supplied, gets a random asteroid, if not it tries to get the asteroid closest to the Vector or Pilot. In the case of a number, it tries to get a random asteroid from the asteroid field with the number as an id. Lua return parameter: Asteroid The closest asteroid or nil if not found.

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

Lua function: get

Definition at line 265 of file nlua_asteroid.c.

◆ asteroidL_getAll()

int asteroidL_getAll ( lua_State * L)
static

Gets all the asteroids in the system.

Lua return parameter: table t A list of all asteroids in the system.

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

Lua function: getAll

Definition at line 234 of file nlua_asteroid.c.

◆ asteroidL_materials()

int asteroidL_materials ( lua_State * L)
static

Gets the materials the asteroid can potentially drop.

Lua function parameter: Asteroid a Asteroid to get materials of. Lua return parameter: table Table containing the materials.

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

Lua function: materials

Definition at line 632 of file nlua_asteroid.c.

◆ asteroidL_pos()

int asteroidL_pos ( lua_State * L)
static

Gets the position of an asteroid.

Lua function parameter: Asteroid a Asteroid to get position of. Lua return parameter: Vector Position of the asteroid.

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

Lua function: pos

Definition at line 484 of file nlua_asteroid.c.

◆ asteroidL_scanned()

int asteroidL_scanned ( lua_State * L)
static

Gets whether or not an asteroid got scanned.

Lua function parameter: Asteroid a Asteroid to get scanned state of. Lua return parameter: boolean Whether or not the asteroid was scanned.

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

Lua function: scanned

Definition at line 542 of file nlua_asteroid.c.

◆ asteroidL_setArmour()

int asteroidL_setArmour ( lua_State * L)
static

Sets the armour of the asteroid.

Lua function parameter: Asteroid a Asteroid to set armour of. Lua function parameter: number Amount to set the armour to (negative values will explode it).

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

Lua function: setTimer

Definition at line 602 of file nlua_asteroid.c.

◆ asteroidL_setPos()

int asteroidL_setPos ( lua_State * L)
static

Sets the position of an asteroid.

Lua function parameter: Asteroid a Asteroid to set position of. Lua function parameter: vec2 v Position to set to.

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

Lua function: setPos

Definition at line 512 of file nlua_asteroid.c.

◆ asteroidL_setState()

int asteroidL_setState ( lua_State * L)
static

Sets the state of an asteroid.

Lua function parameter: Asteroid a Asteroid to set state of. Lua function parameter: string s State to set. Has to be one of "FG", "XB", "BX", "XX_TO_BG", "FG_TO_BG", "BG_TO_FG", "BG_TO_XX", or "XX".

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

Lua function: state

Definition at line 437 of file nlua_asteroid.c.

◆ asteroidL_setTimer()

int asteroidL_setTimer ( lua_State * L)
static

Sets the time left on the asteroid.

Lua function parameter: Asteroid a Asteroid to set time left of. Lua function parameter: number Time left to set to in seconds.

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

Lua function: setTimer

Definition at line 572 of file nlua_asteroid.c.

◆ asteroidL_setVel()

int asteroidL_setVel ( lua_State * L)
static

Sets the velocity of an asteroid.

Lua function parameter: Asteroid a Asteroid to set velocity of. Lua function parameter: vec2 v Velocity to set to.

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

Lua function: setVel

Definition at line 527 of file nlua_asteroid.c.

◆ asteroidL_state()

int asteroidL_state ( lua_State * L)
static

Gets the state of an asteroid.

Lua function parameter: Asteroid a Asteroid to check state of. Lua return parameter: string State of the asteroid. Can be one of "FG", "XB", "BX", "XX_TO_BG", "FG_TO_BG", "BG_TO_FG", "BG_TO_XX", or "XX".

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

Lua function: state

Definition at line 395 of file nlua_asteroid.c.

◆ asteroidL_timer()

int asteroidL_timer ( lua_State * L)
static

Gets the time left on the asteroid.

Lua function parameter: Asteroid a Asteroid to get time left on. Lua return parameter: number Seconds left before the asteroid is unavailable. Lua return parameter: number Total number of seconds the asteroid had to live.

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

Lua function: timer

Definition at line 557 of file nlua_asteroid.c.

◆ asteroidL_tostring()

int asteroidL_tostring ( lua_State * L)
static

Gets the asteroid's current (translated) name or notes it is inexistent.

Lua usage parameter: tostring(a)

Lua function parameter: Asteroid a Asteroid to convert to string. Lua return parameter: string A string representation of the asteroid. if not existent.

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

Lua function: __tostring

Definition at line 219 of file nlua_asteroid.c.

◆ asteroidL_vel()

int asteroidL_vel ( lua_State * L)
static

Gets the velocity of an asteroid.

Lua function parameter: Asteroid a Asteroid to get velocity of. Lua return parameter: Vector Position of the asteroid.

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

Lua function: vel

Definition at line 498 of file nlua_asteroid.c.

◆ lua_isasteroid()

int lua_isasteroid ( lua_State * L,
int ind )

Checks to see if ind is a asteroid.

Parameters
LLua state to check.
indIndex position to check.
Returns
1 if ind is a asteroid.

Definition at line 170 of file nlua_asteroid.c.

◆ lua_pushasteroid()

LuaAsteroid_t * lua_pushasteroid ( lua_State * L,
LuaAsteroid_t asteroid )

Pushes a asteroid on the stack.

Parameters
LLua state to push asteroid into.
asteroidAsteroid to push.
Returns
Newly pushed asteroid.

Definition at line 154 of file nlua_asteroid.c.

◆ lua_toasteroid()

LuaAsteroid_t * lua_toasteroid ( lua_State * L,
int ind )

Gets asteroid at index.

Parameters
LLua state to get asteroid from.
indIndex position to find the asteroid.
Returns
Asteroid found at the index in the state.

Definition at line 87 of file nlua_asteroid.c.

◆ luaL_checkasteroid()

LuaAsteroid_t * luaL_checkasteroid ( lua_State * L,
int ind )

Gets asteroid at index or raises error if there is no asteroid at index.

Parameters
LLua state to get asteroid from.
indIndex position to find asteroid.
Returns
Asteroid found at the index in the state.

Definition at line 99 of file nlua_asteroid.c.

◆ luaL_validasteroid()

Asteroid * luaL_validasteroid ( lua_State * L,
int ind )

Gets asteroid at index raising an error if type doesn't match.

Parameters
LLua state to get system from.
indIndex position of system.
Returns
The Asteroid at ind.

Definition at line 113 of file nlua_asteroid.c.

◆ nlua_loadAsteroid()

int nlua_loadAsteroid ( nlua_env env)

Loads the asteroid library.

Parameters
envLua environment.
Returns
0 on success.

Definition at line 74 of file nlua_asteroid.c.

Variable Documentation

◆ asteroidL_methods

const luaL_Reg asteroidL_methods[]
static
Initial value:
= {
{ "__eq", asteroidL_eq },
{ "__tostring", asteroidL_tostring },
{ "getAll", asteroidL_getAll },
{ "get", asteroidL_get },
{ "exists", asteroidL_exists },
{ "state", asteroidL_state },
{ "setState", asteroidL_setState },
{ "field", asteroidL_field },
{ "pos", asteroidL_pos },
{ "vel", asteroidL_vel },
{ "setPos", asteroidL_setPos },
{ "setVel", asteroidL_setVel },
{ "scanned", asteroidL_scanned },
{ "timer", asteroidL_timer },
{ "setTimer", asteroidL_setTimer },
{ "armour", asteroidL_armour },
{ "setArmour", asteroidL_setArmour },
{ "alertRange", asteroidL_alertRange },
{ "materials", asteroidL_materials },
{ 0, 0 } }
static int asteroidL_state(lua_State *L)
Gets the state of an asteroid.
static int asteroidL_vel(lua_State *L)
Gets the velocity of an asteroid.
static int asteroidL_setState(lua_State *L)
Sets the state of an asteroid.
static int asteroidL_field(lua_State *L)
Gets the field the asteroid belongs to (useful for getting more asteroids from the same field).
static int asteroidL_scanned(lua_State *L)
Gets whether or not an asteroid got scanned.
static int asteroidL_exists(lua_State *L)
Checks to see if an asteroid exists.
static int asteroidL_materials(lua_State *L)
Gets the materials the asteroid can potentially drop.
static int asteroidL_setVel(lua_State *L)
Sets the velocity of an asteroid.
static int asteroidL_tostring(lua_State *L)
Gets the asteroid's current (translated) name or notes it is inexistent.
static int asteroidL_get(lua_State *L)
Gets an asteroid in the system.
static int asteroidL_alertRange(lua_State *L)
Gets the alert range of an asteroid.
static int asteroidL_setTimer(lua_State *L)
Sets the time left on the asteroid.
static int asteroidL_getAll(lua_State *L)
Gets all the asteroids in the system.
static int asteroidL_eq(lua_State *L)
Lua bindings to interact with asteroid.
static int asteroidL_pos(lua_State *L)
Gets the position of an asteroid.
static int asteroidL_setPos(lua_State *L)
Sets the position of an asteroid.
static int asteroidL_setArmour(lua_State *L)
Sets the armour of the asteroid.
static int asteroidL_armour(lua_State *L)
Gets the armour (health) left on the asteroid.
static int asteroidL_timer(lua_State *L)
Gets the time left on the asteroid.

AsteroidLua methods.

Definition at line 46 of file nlua_asteroid.c.