15#include "nlua_commodity.h"
20#include "nlua_faction.h"
22#include "nlua_system.h"
102 return *((
Commodity**) lua_touserdata(L,ind));
115 luaL_typerror(L, ind, COMMODITY_METATABLE);
131 else if (lua_isstring(L, ind))
134 luaL_typerror(L, ind, COMMODITY_METATABLE);
139 NLUA_ERROR(L, _(
"Commodity is invalid."));
154 luaL_getmetatable(L, COMMODITY_METATABLE);
155 lua_setmetatable(L, -2);
169 if (lua_getmetatable(L,ind)==0)
171 lua_getfield(L, LUA_REGISTRYINDEX, COMMODITY_METATABLE);
174 if (lua_rawequal(L, -1, -2))
197 lua_pushboolean(L,1);
199 lua_pushboolean(L,0);
215 const char *name = luaL_checkstring(L,1);
219 if (commodity == NULL) {
220 return NLUA_ERROR(L,_(
"Commodity '%s' not found!"), name);
242 lua_rawseti( L, -2, i+1 );
259 lua_pushboolean(L, commodity_isFlag(
c,COMMODITY_FLAG_STANDARD));
260 lua_setfield(L, -2,
"standard");
262 lua_pushboolean(L, commodity_isFlag(
c,COMMODITY_FLAG_ALWAYS_CAN_SELL));
263 lua_setfield(L, -2,
"always_can_sell");
265 lua_pushboolean(L, commodity_isFlag(
c,COMMODITY_FLAG_PRICE_CONSTANT));
266 lua_setfield(L, -2,
"price_constant");
287 lua_pushstring(L, _(
c->name));
308 lua_pushstring(L,
c->name);
324 lua_pushnumber(L,
c->price);
342 const StarSystem *sys;
349 return NLUA_ERROR( L, _(
"Spob '%s' does not belong to a system."), p->name );
352 return NLUA_ERROR( L, _(
"Spob '%s' can not find its system '%s'."), p->name, sysname );
373 const StarSystem *sys;
381 return NLUA_ERROR( L, _(
"Spob '%s' does not belong to a system."), p->name );
384 return NLUA_ERROR( L, _(
"Spob '%s' can not find its system '%s'."), p->name, sysname );
414 if (commodity_isFlag(
c, COMMODITY_FLAG_ALWAYS_CAN_SELL )) {
415 lua_pushboolean(L,1);
422 if (spob_hasCommodity(
c, s->spobs[i] )) {
423 lua_pushboolean(L,1);
430 lua_pushboolean(L, spob_hasCommodity(
c, s ) );
434 lua_pushboolean(L,0);
454 if (spob_hasCommodity(
c, s->spobs[i] )) {
455 lua_pushboolean(L,1);
462 lua_pushboolean(L, spob_hasCommodity(
c, s ) );
466 lua_pushboolean(L,0);
480 if (
c->gfx_store==NULL)
496 if (
c->description==NULL)
498 lua_pushstring(L,
c->description);
517 const char *cname, *cdesc;
518 char str[STRMAX_SHORT];
522 cname = luaL_checkstring(L,1);
523 cdesc = luaL_checkstring(L,2);
526 if ((cargo != NULL) && !cargo->
istemp)
527 return NLUA_ERROR(L,_(
"Trying to create new cargo '%s' that would shadow existing non-temporary cargo!"), cname);
532 if (!lua_isnoneornil(L,3)) {
534 lua_getfield(L,3,
"gfx_space");
535 buf = luaL_optstring(L,-1,NULL);
538 snprintf( str,
sizeof(str), COMMODITY_GFX_PATH
"space/%s", buf );
557 if (lua_istable(L,2)) {
559 while (lua_next(L,-2) != 0) {
585 lua_rawseti( L, -2, i+1 );
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Commodity * commodity_get(const char *name)
Gets a commodity by name.
Commodity * commodity_newTemp(const char *name, const char *desc)
Creates a new temporary commodity.
Commodity ** standard_commodities(void)
Return an array (array.h) of standard commodities. Free with array_free. (Don't free contents....
Commodity * commodity_getW(const char *name)
Gets a commodity by name without warning.
int commodity_tempIllegalto(Commodity *com, int faction)
Makes a temporary commodity illegal to something.
Header file with generic functions and naev-specifics.
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.
Commodity * lua_tocommodity(lua_State *L, int ind)
Lua bindings to interact with commodities.
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.
int nlua_loadCommodity(nlua_env env)
Loads the commodity library.
Commodity ** lua_pushcommodity(lua_State *L, Commodity *commodity)
Pushes a commodity on the stack.
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 const luaL_Reg commodityL_methods[]
Commodity * luaL_validcommodity(lua_State *L, int ind)
Makes sure the commodity is valid or raises a Lua error.
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.
int lua_iscommodity(lua_State *L, int ind)
Checks to see if ind is a commodity.
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 * luaL_checkcommodity(lua_State *L, int ind)
Gets commodity at index or raises error if there is no commodity at index.
LuaFaction * lua_pushfaction(lua_State *L, LuaFaction faction)
Pushes a faction on the stack.
LuaFaction luaL_validfaction(lua_State *L, int ind)
Gets faction (or faction name) at index, raising an error if type isn't a valid faction.
Spob * luaL_validspob(lua_State *L, int ind)
Gets a spob directly.
StarSystem * luaL_validsystem(lua_State *L, int ind)
Gets system (or system name) at index raising an error if type doesn't match.
int lua_issystem(lua_State *L, int ind)
Checks to see if ind is a system.
glTexture ** lua_pushtex(lua_State *L, glTexture *texture)
Pushes a texture on the stack.
ntime_t luaL_validtime(lua_State *L, int ind)
Gets a time directly.
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
void gl_freeTexture(glTexture *texture)
Frees a texture.
StarSystem * system_get(const char *sysname)
Get the system from its name.
const char * spob_getSystem(const char *spobname)
Get the name of a system from a spobname.
credits_t spob_commodityPrice(const Spob *p, const Commodity *c)
Gets the price of a commodity at a spob.
credits_t spob_commodityPriceAtTime(const Spob *p, const Commodity *c, ntime_t t)
Gets the price of a commodity at a spob at given time.
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...