naev 0.12.6
nlua_commodity.c File Reference

Handles the Lua commodity bindings. More...

#include "nlua_commodity.h"
#include "array.h"
#include "ndata.h"
#include "nlua_faction.h"
#include "nlua_spob.h"
#include "nlua_system.h"
#include "nlua_tex.h"
#include "nlua_time.h"
#include "nluadef.h"
Include dependency graph for nlua_commodity.c:

Go to the source code of this file.

Functions

static int commodityL_eq (lua_State *L)
 Checks to see if two commodities are the same.
static int commodityL_get (lua_State *L)
 Gets a commodity.
static int commodityL_getStandard (lua_State *L)
 Gets the list of standard commodities.
static int commodityL_flags (lua_State *L)
 Gets the flags that are set for a commodity.
static int commodityL_name (lua_State *L)
 Gets the translated name of the commodity.
static int commodityL_nameRaw (lua_State *L)
 Gets the raw (untranslated) name of the commodity.
static int commodityL_price (lua_State *L)
 Gets the base price of an commodity.
static int commodityL_priceAt (lua_State *L)
 Gets the base price of an commodity on a certain spob.
static int commodityL_priceAtTime (lua_State *L)
 Gets the price of an commodity on a certain spob at a certain time.
static int commodityL_canSell (lua_State *L)
 Sees if a commodity can be sold at either a spob or system.
static int commodityL_canBuy (lua_State *L)
 Sees if a commodity can be bought at either a spob or system.
static int commodityL_icon (lua_State *L)
 Gets the store icon of a commodity if it exists.
static int commodityL_description (lua_State *L)
 Gets the description of a commodity if it exists.
static int commodityL_new (lua_State *L)
 Creates a new temporary commodity. If a temporary commodity with the same name exists, that gets returned instead. "Temporary" is a relative term. The commodity will be saved with the player while it is in the inventory of their fleet. However, when all instances are gone, it will no longer be saved and disappear.
static int commodityL_illegalto (lua_State *L)
 Makes a temporary commodity illegal to a faction.
static int commodityL_illegality (lua_State *L)
 Gets the factions to which the commodity is illegal to.
int nlua_loadCommodity (nlua_env env)
 Loads the commodity library.
Commoditylua_tocommodity (lua_State *L, int ind)
 Lua bindings to interact with commodities.
CommodityluaL_checkcommodity (lua_State *L, int ind)
 Gets commodity at index or raises error if there is no commodity at index.
CommodityluaL_validcommodity (lua_State *L, int ind)
 Makes sure the commodity is valid or raises a Lua error.
Commodity ** lua_pushcommodity (lua_State *L, Commodity *commodity)
 Pushes a commodity on the stack.
int lua_iscommodity (lua_State *L, int ind)
 Checks to see if ind is a commodity.
static int spob_hasCommodity (const Commodity *c, const Spob *s)

Variables

static const luaL_Reg commodityL_methods []

Detailed Description

Handles the Lua commodity bindings.

Definition in file nlua_commodity.c.

Function Documentation

◆ commodityL_canBuy()

int commodityL_canBuy ( lua_State * L)
static

Sees if a commodity can be bought at either a spob or system.

It does not check faction standings, only if it is possible to buy at a spob or a system (checking all spobs in the system).

Lua function parameter: Commodity c Commodity to check. Lua function parameter: Spob|System where Either a spob or a system to see if the commodity is sold there.

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

Lua function: canBuy

Definition at line 457 of file nlua_commodity.c.

◆ commodityL_canSell()

int commodityL_canSell ( lua_State * L)
static

Sees if a commodity can be sold at either a spob or system.

It does not check faction standings, only if it is possible to sell at a spob or a system (checking all spobs in the system).

Lua function parameter: Commodity c Commodity to check. Lua function parameter: Spob|System where Either a spob or a system to see if the commodity can be sold there.

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

Lua function: canSell

Definition at line 419 of file nlua_commodity.c.

◆ commodityL_description()

int commodityL_description ( lua_State * L)
static

Gets the description of a commodity if it exists.

Lua function parameter: Commodity c Commodity to get decription of Lua return parameter: string|nil Description of the commodity if exists, otherwise nil.

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

Lua function: description

Definition at line 504 of file nlua_commodity.c.

◆ commodityL_eq()

int commodityL_eq ( lua_State * L)
static

Checks to see if two commodities are the same.

Lua usage parameter: if o1 == o2 then – Checks to see if commodity o1 and o2 are the same

Lua function parameter: Commodity o1 First commodity to compare. Lua function parameter: Commodity o2 Second commodity to compare. Lua return parameter: boolean true if both commodities are the same.

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

Lua function: __eq

Definition at line 190 of file nlua_commodity.c.

◆ commodityL_flags()

int commodityL_flags ( lua_State * L)
static

Gets the flags that are set for a commodity.

Lua return parameter: table A table containing the flags as key and value as boolean.

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

Lua function: flags

Definition at line 255 of file nlua_commodity.c.

◆ commodityL_get()

int commodityL_get ( lua_State * L)
static

Gets a commodity.

Lua usage parameter: s = commodity.get( "Food" ) – Gets the food commodity

Lua function parameter: string s Raw (untranslated) name of the commodity to get. Lua return parameter: Commodity|nil The commodity matching name or nil if error.

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

Lua function: get

Definition at line 211 of file nlua_commodity.c.

◆ commodityL_getStandard()

int commodityL_getStandard ( lua_State * L)
static

Gets the list of standard commodities.

Lua return parameter: table A table containing commodity objects, namely those which are standard (buyable/sellable anywhere).

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

Lua function: getStandard

Definition at line 234 of file nlua_commodity.c.

◆ commodityL_icon()

int commodityL_icon ( lua_State * L)
static

Gets the store icon of a commodity if it exists.

Lua function parameter: Commodity c Commodity to get icon of. Lua return parameter: Texture|nil Texture of the store icon if exists, otherwise nil.

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

Lua function: icon

Definition at line 487 of file nlua_commodity.c.

◆ commodityL_illegality()

int commodityL_illegality ( lua_State * L)
static

Gets the factions to which the commodity is illegal to.

Lua function parameter: c Commodity to get illegality status of. Lua return parameter: table Table of all the factions the commodity is illegal to.

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

Lua function: illegality

Definition at line 598 of file nlua_commodity.c.

◆ commodityL_illegalto()

int commodityL_illegalto ( lua_State * L)
static

Makes a temporary commodity illegal to a faction.

Lua function parameter: Commodity c Temporary commodity to make illegal to factions. Lua function parameter: Faction|table f Faction or table of factions to make illegal to.

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

Lua function: illegalto

Definition at line 574 of file nlua_commodity.c.

◆ commodityL_name()

int commodityL_name ( lua_State * L)
static

Gets the translated name of the commodity.

This translated name should be used for display purposes (e.g. messages). It cannot be used as an identifier for the commodity; for that, use commodity.nameRaw() instead.

Lua usage parameter: commodityname = c:name() – Equivalent to _(c:nameRaw())

Lua function parameter: Commodity c Commodity to get the translated name of. Lua return parameter: string The translated name of the commodity.

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

Lua function: name

Definition at line 285 of file nlua_commodity.c.

◆ commodityL_nameRaw()

int commodityL_nameRaw ( lua_State * L)
static

Gets the raw (untranslated) name of the commodity.

This untranslated name should be used for identification purposes (e.g. can be passed to commodity.get()). It should not be used directly for display purposes without manually translating it with _().

Lua usage parameter: commodityrawname = c:nameRaw()

Lua function parameter: Commodity c Commodity to get the raw name of. Lua return parameter: string The raw name of the commodity.

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

Lua function: nameRaw

Definition at line 306 of file nlua_commodity.c.

◆ commodityL_new()

int commodityL_new ( lua_State * L)
static

Creates a new temporary commodity. If a temporary commodity with the same name exists, that gets returned instead. "Temporary" is a relative term. The commodity will be saved with the player while it is in the inventory of their fleet. However, when all instances are gone, it will no longer be saved and disappear.

Lua usage parameter: commodity.new( N_("Cheesburgers"), N_("I can has cheezburger?") )

Lua function parameter: string cargo Name of the cargo to add. This must not match a cargo name defined in commodity.xml. Lua function parameter: string decription Description of the cargo to add. Lua function parameter:[opt=nil] table params Table of named parameters. Currently supported is "gfx_space". Lua return parameter: Commodity The newly created commodity or an existing temporary commodity with the same name.

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

Lua function: new

Definition at line 531 of file nlua_commodity.c.

◆ commodityL_price()

int commodityL_price ( lua_State * L)
static

Gets the base price of an commodity.

Lua usage parameter: print( c:price() ) – Prints the base price of the commodity

Lua function parameter: Commodity c Commodity to get information of. Lua return parameter: number The base price of the commodity.

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

Lua function: price

Definition at line 322 of file nlua_commodity.c.

◆ commodityL_priceAt()

int commodityL_priceAt ( lua_State * L)
static

Gets the base price of an commodity on a certain spob.

Lua usage parameter: if c:priceAt( spob.get("Polaris Prime") ) > 100 then – Checks price of a commodity at polaris prime

Lua function parameter: Commodity c Commodity to get information of. Lua function parameter: Spob p Spob to get price at. Lua return parameter: number The price of the commodity at the spob.

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

Lua function: priceAt

Definition at line 340 of file nlua_commodity.c.

◆ commodityL_priceAtTime()

int commodityL_priceAtTime ( lua_State * L)
static

Gets the price of an commodity on a certain spob at a certain time.

Lua usage parameter: if c:priceAtTime( spob.get("Polaris Prime"), time ) > 100 then – Checks price of a commodity at polaris prime

Lua function parameter: Commodity c Commodity to get information of. Lua function parameter: Spob p Spob to get price at. Lua function parameter: Time t Time to get the price at. Lua return parameter: number The price of the commodity at the spob.

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

Lua function: priceAtTime

Definition at line 374 of file nlua_commodity.c.

◆ lua_iscommodity()

int lua_iscommodity ( lua_State * L,
int ind )

Checks to see if ind is a commodity.

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

Definition at line 164 of file nlua_commodity.c.

◆ lua_pushcommodity()

Commodity ** lua_pushcommodity ( lua_State * L,
Commodity * commodity )

Pushes a commodity on the stack.

Parameters
LLua state to push commodity into.
commodityCommodity to push.
Returns
Newly pushed commodity.

Definition at line 149 of file nlua_commodity.c.

◆ lua_tocommodity()

Commodity * lua_tocommodity ( lua_State * L,
int ind )

Lua bindings to interact with commodities.

This will allow you to create and manipulate commodities in-game.

An example would be:

c = commodity.get( "Food" ) -- Gets the commodity by name
if c:price() > 500 then
-- Do something with high price
end
static const double c[]
Definition rng.c:256

Lua module: commodity

Gets commodity at index.

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

Definition at line 98 of file nlua_commodity.c.

◆ luaL_checkcommodity()

Commodity * luaL_checkcommodity ( lua_State * L,
int ind )

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

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

Definition at line 110 of file nlua_commodity.c.

◆ luaL_validcommodity()

Commodity * luaL_validcommodity ( lua_State * L,
int ind )

Makes sure the commodity is valid or raises a Lua error.

Parameters
LState currently running.
indIndex of the commodity to validate.
Returns
The commodity (doesn't return if fails - raises Lua error ).

Definition at line 124 of file nlua_commodity.c.

◆ nlua_loadCommodity()

int nlua_loadCommodity ( nlua_env env)

Loads the commodity library.

Parameters
envEnvironment to load commodity library into.
Returns
0 on success.

Definition at line 70 of file nlua_commodity.c.

◆ spob_hasCommodity()

int spob_hasCommodity ( const Commodity * c,
const Spob * s )
static

Definition at line 397 of file nlua_commodity.c.

Variable Documentation

◆ commodityL_methods

const luaL_Reg commodityL_methods[]
static
Initial value:
= {
{ "__tostring", commodityL_name },
{ "__eq", commodityL_eq },
{ "get", commodityL_get },
{ "getStandard", commodityL_getStandard },
{ "flags", commodityL_flags },
{ "name", commodityL_name },
{ "nameRaw", commodityL_nameRaw },
{ "price", commodityL_price },
{ "priceAt", commodityL_priceAt },
{ "priceAtTime", commodityL_priceAtTime },
{ "canSell", commodityL_canSell },
{ "canBuy", commodityL_canBuy },
{ "icon", commodityL_icon },
{ "description", commodityL_description },
{ "new", commodityL_new },
{ "illegalto", commodityL_illegalto },
{ "illegality", commodityL_illegality },
{ 0, 0 } }
static int commodityL_eq(lua_State *L)
Checks to see if two commodities are the same.
static int commodityL_price(lua_State *L)
Gets the base price of an commodity.
static int commodityL_name(lua_State *L)
Gets the translated name of the commodity.
static int commodityL_canBuy(lua_State *L)
Sees if a commodity can be bought at either a spob or system.
static int commodityL_icon(lua_State *L)
Gets the store icon of a commodity if it exists.
static int commodityL_description(lua_State *L)
Gets the description of a commodity if it exists.
static int commodityL_get(lua_State *L)
Gets a commodity.
static int commodityL_flags(lua_State *L)
Gets the flags that are set for a commodity.
static int commodityL_nameRaw(lua_State *L)
Gets the raw (untranslated) name of the commodity.
static int commodityL_priceAt(lua_State *L)
Gets the base price of an commodity on a certain spob.
static int commodityL_illegality(lua_State *L)
Gets the factions to which the commodity is illegal to.
static int commodityL_illegalto(lua_State *L)
Makes a temporary commodity illegal to a faction.
static int commodityL_new(lua_State *L)
Creates a new temporary commodity. If a temporary commodity with the same name exists,...
static int commodityL_canSell(lua_State *L)
Sees if a commodity can be sold at either a spob or system.
static int commodityL_getStandard(lua_State *L)
Gets the list of standard commodities.
static int commodityL_priceAtTime(lua_State *L)
Gets the price of an commodity on a certain spob at a certain time.

Commodity metatable methods.

Definition at line 44 of file nlua_commodity.c.