27static LuaNews_t *
lua_pushnews( lua_State *L, LuaNews_t news );
67 return (LuaNews_t *)lua_touserdata( L, ind );
80 luaL_typerror( L, ind, NEWS_METATABLE );
92 LuaNews_t *la = (LuaNews_t *)lua_newuserdata( L,
sizeof( LuaNews_t ) );
94 luaL_getmetatable( L, NEWS_METATABLE );
95 lua_setmetatable( L, -2 );
109 if ( lua_getmetatable( L, ind ) == 0 )
111 lua_getfield( L, LUA_REGISTRYINDEX, NEWS_METATABLE );
114 if ( lua_rawequal( L, -1, -2 ) )
133 NLUA_ERROR( L, _(
"Article is invalid." ) );
167 const char *title, *body, *faction;
168 ntime_t date, date_to_rm;
176 date_to_rm = NEWS_FOREVER;
179 if ( lua_istable( L, 1 ) ) {
183 while ( lua_next( L, -2 ) ) {
185 if ( lua_istable( L, -1 ) ) {
186 faction = title = body = NULL;
189 date_to_rm = NEWS_FOREVER;
191 lua_getfield( L, -1,
"faction" );
192 if ( !lua_isnil( L, -1 ) )
193 faction = luaL_checkstring( L, -1 );
196 lua_getfield( L, -1,
"head" );
197 if ( !lua_isnil( L, -1 ) )
198 title = luaL_checkstring( L, -1 );
201 lua_getfield( L, -1,
"body" );
202 if ( !lua_isnil( L, -1 ) )
203 body = luaL_checkstring( L, -1 );
206 lua_getfield( L, -1,
"date" );
207 if ( !lua_isnil( L, -1 ) ) {
208 if ( lua_isnumber( L, -1 ) )
209 date = lua_tonumber( L, -1 );
215 lua_getfield( L, -1,
"date_to_rm" );
216 if ( !lua_isnil( L, -1 ) ) {
217 if ( lua_isnumber( L, -1 ) )
218 date_to_rm = lua_tonumber( L, -1 );
224 lua_getfield( L, -1,
"priority" );
225 if ( !lua_isnil( L, -1 ) )
226 priority = luaL_checkinteger( L, -1 );
229 if ( title && body && faction )
230 news_add( title, body, faction, NULL, date, date_to_rm,
233 NLUA_WARN( L, _(
"Bad arguments" ) );
249 if ( !( lua_isstring( L, 1 ) && lua_isstring( L, 2 ) &&
250 lua_isstring( L, 3 ) ) ) {
252 L, _(
"\nBad arguments, use "
253 "addArticle(\"Faction\",\"Title\",\"Content\",[date,[date_to_rm]"
258 faction = luaL_checkstring( L, 1 );
259 title = luaL_checkstring( L, 2 );
260 body = luaL_checkstring( L, 3 );
261 priority = luaL_optinteger( L, 6, 5 );
264 if ( !lua_isnoneornil( L, 4 ) ) {
268 date_to_rm = luaL_checklong( L, 4 );
270 if ( !lua_isnoneornil( L, 5 ) ) {
274 date = luaL_checklong( L, 5 );
277 if ( title && body && faction ) {
278 LuaNews_t n_article =
279 news_add( title, body, faction, NULL, date, date_to_rm, priority );
282 return NLUA_ERROR( L, _(
"Bad arguments" ) );
301 if ( lua_istable( L, 1 ) ) {
303 while ( lua_next( L, -2 ) ) {
305 news_rm( *Larticle );
310 news_rm( *Larticle );
346 const char *characteristic = NULL;
350 if ( lua_isnoneornil( L, 1 ) )
352 else if ( lua_isnumber( L, 1 ) )
353 date = (ntime_t)lua_tonumber( L, 1 );
354 else if ( lua_isstring( L, 1 ) )
355 characteristic = lua_tostring( L, 1 );
357 NLUA_INVALID_PARAMETER( L, 1 );
364 if ( ( n->
title == NULL ) || ( n->
desc == NULL ) ||
368 if ( print_all || date == n->
date ||
370 ( ( strcmp( n->
title, characteristic ) == 0 ) ||
371 ( strcmp( n->
desc, characteristic ) == 0 ) ||
372 ( strcmp( n->
faction, characteristic ) == 0 ) ||
374 strcmp( n->
tag, characteristic ) == 0 ) ) ) ) {
376 lua_rawseti( L, -2, narticle++ );
395 const LuaNews_t *a1, *a2;
398 lua_pushboolean( L, *a1 == *a2 );
411 lua_pushstring( L, article_ptr->
title );
424 lua_pushstring( L, article_ptr->
desc );
437 lua_pushstring( L, article_ptr->
faction );
450 lua_pushinteger( L, (lua_Integer)article_ptr->
date );
465 if ( lua_istable( L, 1 ) ) {
466 const char *tag = luaL_checkstring( L, 2 );
471 while ( lua_next( L, -2 ) ) {
474 L, _(
"Bad argument to news.date(), must be article or a table "
479 if ( article_ptr == NULL ) {
480 NLUA_WARN( L, _(
"Article not valid" ) );
483 article_ptr->
tag = strdup( tag );
490 L, _(
"Bad argument to news.date(), must be article or a table of "
495 if ( article_ptr == NULL ) {
496 NLUA_WARN( L, _(
"Article not valid" ) );
500 tag = luaL_checkstring( L, 2 );
501 article_ptr->
tag = strdup( tag );
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
void bar_regen(void)
Regenerates the bar list.
int news_add(const char *title, const char *content, const char *faction, const char *tag, ntime_t date, ntime_t date_to_rm, int priority)
makes a new article and puts it into the list
news_t * news_get(int id)
gets the article with id ID, else NULL
int * generate_news(int faction)
Generates news from newslist from specific faction AND Generic news.
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...
static news_t * luaL_validnews(lua_State *L, int ind)
Makes sure the news is valid or raises a Lua error.
static int newsL_eq(lua_State *L)
Check news articles for equality.
static LuaNews_t * lua_pushnews(lua_State *L, LuaNews_t news)
Pushes a news on the stack.
static int lua_isnews(lua_State *L, int ind)
Checks to see if ind is a news.
static const luaL_Reg news_methods[]
int nlua_loadNews(nlua_env env)
Loads the news library.
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_desc(lua_State *L)
Gets the news article description. Lua function parameter: Article a article to get the desc of Lua r...
LuaNews_t * luaL_checknews(lua_State *L, int ind)
Gets news at index or raises error if there is no news at index.
static int newsL_add(lua_State *L)
Lua bindings to interact with the news.
LuaNews_t * lua_tonews(lua_State *L, int ind)
Gets news at index.
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...
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...
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...
int lua_istime(lua_State *L, int ind)
Checks to see if ind is a time.
ntime_t luaL_validtime(lua_State *L, int ind)
Gets a time directly.
ntime_t ntime_get(void)
Gets the current time.
Represents a news article.