naev 0.12.5
nlua_news.c File Reference

Lua news module. More...

#include "nlua_news.h"
#include "array.h"
#include "land.h"
#include "news.h"
#include "nlua_time.h"
#include "nluadef.h"
#include "ntime.h"
Include dependency graph for nlua_news.c:

Go to the source code of this file.

Functions

static news_tluaL_validnews (lua_State *L, int ind)
 Makes sure the news is valid or raises a Lua error.
static int lua_isnews (lua_State *L, int ind)
 Checks to see if ind is a news.
static LuaNews_t * lua_pushnews (lua_State *L, LuaNews_t news)
 Pushes a news on the stack.
static int newsL_add (lua_State *L)
 Lua bindings to interact with the news.
static int newsL_rm (lua_State *L)
 Frees a news article or a table of articles. Lua function parameter: News n News article to free.
static int newsL_get (lua_State *L)
 Gets all matching news articles in a table.
static int newsL_eq (lua_State *L)
 Check news articles for equality.
static int newsL_title (lua_State *L)
 Gets the news article title. Lua function parameter: Article a article to get the title of Lua return parameter: string title.
static int newsL_desc (lua_State *L)
 Gets the news article description. Lua function parameter: Article a article to get the desc of Lua return parameter: string desc.
static int newsL_faction (lua_State *L)
 Gets the news article faction. Lua function parameter: Article a article to get the faction of Lua return parameter: Faction faction.
static int newsL_date (lua_State *L)
 Gets the news article date. Lua function parameter: Article a article to get the date of Lua return parameter: number date.
static int newsL_bind (lua_State *L)
 Tags a news article or a table of articles with a string. Lua function parameter: Article a Article to bind Lua function parameter: string tag Tag to bind to the article.
int nlua_loadNews (nlua_env env)
 Loads the news library.
LuaNews_t * lua_tonews (lua_State *L, int ind)
 Gets news at index.
LuaNews_t * luaL_checknews (lua_State *L, int ind)
 Gets news at index or raises error if there is no news at index.

Variables

news_tnews_list
int land_loaded
static const luaL_Reg news_methods []

Detailed Description

Lua news module.

Definition in file nlua_news.c.

Function Documentation

◆ lua_isnews()

int lua_isnews ( lua_State * L,
int ind )
static

Checks to see if ind is a news.

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

Definition at line 105 of file nlua_news.c.

◆ lua_pushnews()

LuaNews_t * lua_pushnews ( lua_State * L,
LuaNews_t news )
static

Pushes a news on the stack.

Parameters
LLua state to push news into.
newsNews to push.
Returns
Newly pushed news.

Definition at line 90 of file nlua_news.c.

◆ lua_tonews()

LuaNews_t * lua_tonews ( lua_State * L,
int ind )

Gets news at index.

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

Definition at line 65 of file nlua_news.c.

◆ luaL_checknews()

LuaNews_t * luaL_checknews ( lua_State * L,
int ind )

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

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

Definition at line 76 of file nlua_news.c.

◆ luaL_validnews()

news_t * luaL_validnews ( lua_State * L,
int ind )
static

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

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

Definition at line 128 of file nlua_news.c.

◆ newsL_add()

int newsL_add ( lua_State * L)
static

Lua bindings to interact with the news.

This will allow you to interact and manipulate the in-game news.

Lua module: news

Adds a news article. Lua usage parameter: news.add(faction,title,body,[date_to_rm, [date]])

Lua usage parameter: s = news.add( "Empire", "Hello world!", "The Empire wishes to say hello!", 0 ) – Adds an Empire specific article, with date 0. Lua usage parameter: s = news.add( { { faction = "Empire", title = "Hello World!", body = "The Empire wishes to say hello!" } } ) – Can also be passed as tables

Lua function parameter: Faction|string faction of the article, "Generic" for non-factional Lua function parameter: string title Title of the article Lua function parameter: string body What's in the article Lua function parameter:[opt] number|Time date_to_rm date to remove the article Lua function parameter:[opt] number|Time date What time to put, defaults to current date, use 0 to not use a date Lua function parameter:[opt=5] number Priority to use. Lower is more important and will appear first. Lua return parameter: Article The article matching name or nil if error.

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

Lua function: add

Definition at line 165 of file nlua_news.c.

◆ newsL_bind()

int newsL_bind ( lua_State * L)
static

Tags a news article or a table of articles with a string. Lua function parameter: Article a Article to bind Lua function parameter: string tag Tag to bind to the article.

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

Lua function: bind

Definition at line 460 of file nlua_news.c.

◆ newsL_date()

int newsL_date ( lua_State * L)
static

Gets the news article date. Lua function parameter: Article a article to get the date of Lua return parameter: number date.

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

Lua function: date

Definition at line 447 of file nlua_news.c.

◆ newsL_desc()

int newsL_desc ( lua_State * L)
static

Gets the news article description. Lua function parameter: Article a article to get the desc of Lua return parameter: string desc.

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

Lua function: desc

Definition at line 421 of file nlua_news.c.

◆ newsL_eq()

int newsL_eq ( lua_State * L)
static

Check news articles for equality.

Allows you to use the '==' operator in Lua with articles.

Lua function parameter: Article a1 article 1 Lua function parameter: Article a2 article 2 Lua return parameter: boolean true if both systems are the same.

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

Lua function: __eq

Definition at line 393 of file nlua_news.c.

◆ newsL_faction()

int newsL_faction ( lua_State * L)
static

Gets the news article faction. Lua function parameter: Article a article to get the faction of Lua return parameter: Faction faction.

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

Lua function: faction

Definition at line 434 of file nlua_news.c.

◆ newsL_get()

int newsL_get ( lua_State * L)
static

Gets all matching news articles in a table.

characteristic can be any of the following:

  • Title of the news articles
  • Body (text) of the articles
  • Faction name of the articles ("Generic" for generic)
  • Tag of the articles (applied with news.bind())
  • Date of the articles in number form


The returned table is populated with all articles matching the specified characteristic.

Lua function parameter:[opt] number|String characteristic characteristic to match, or no parameter for all articles Lua return parameter: {Article,...} a table with matching articles

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

Lua function: get

Definition at line 343 of file nlua_news.c.

◆ newsL_rm()

int newsL_rm ( lua_State * L)
static

Frees a news article or a table of articles. Lua function parameter: News n News article to free.

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

Lua function: rm

Definition at line 299 of file nlua_news.c.

◆ newsL_title()

int newsL_title ( lua_State * L)
static

Gets the news article title. Lua function parameter: Article a article to get the title of Lua return parameter: string title.

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

Lua function: title

Definition at line 408 of file nlua_news.c.

◆ nlua_loadNews()

int nlua_loadNews ( nlua_env env)

Loads the news library.

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

Definition at line 52 of file nlua_news.c.

Variable Documentation

◆ land_loaded

int land_loaded
extern

Finished loading?

Definition at line 79 of file land.c.

◆ news_list

news_t* news_list
extern

Linked list containing all newss

Linked list containing all articles

Definition at line 31 of file news.c.

◆ news_methods

const luaL_Reg news_methods[]
static
Initial value:
= {
{ "add", newsL_add }, { "rm", newsL_rm },
{ "get", newsL_get }, { "title", newsL_title },
{ "desc", newsL_desc }, { "faction", newsL_faction },
{ "date", newsL_date }, { "bind", newsL_bind },
{ "__eq", newsL_eq }, { 0, 0 } }
static int newsL_bind(lua_State *L)
Tags a news article or a table of articles with a string. Lua function parameter: Article a Article t...
Definition nlua_news.c:460
static int newsL_eq(lua_State *L)
Check news articles for equality.
Definition nlua_news.c:393
static int newsL_rm(lua_State *L)
Frees a news article or a table of articles. Lua function parameter: News n News article to free.
Definition nlua_news.c:299
static int newsL_get(lua_State *L)
Gets all matching news articles in a table.
Definition nlua_news.c:343
static int newsL_desc(lua_State *L)
Gets the news article description. Lua function parameter: Article a article to get the desc of Lua r...
Definition nlua_news.c:421
static int newsL_add(lua_State *L)
Lua bindings to interact with the news.
Definition nlua_news.c:165
static int newsL_title(lua_State *L)
Gets the news article title. Lua function parameter: Article a article to get the title of Lua return...
Definition nlua_news.c:408
static int newsL_date(lua_State *L)
Gets the news article date. Lua function parameter: Article a article to get the date of Lua return p...
Definition nlua_news.c:447
static int newsL_faction(lua_State *L)
Gets the news article faction. Lua function parameter: Article a article to get the faction of Lua re...
Definition nlua_news.c:434

News metatable methods.

Definition at line 39 of file nlua_news.c.