naev 0.12.6
nlua_time.c File Reference

Time manipulation Lua bindings. More...

#include "nlua_time.h"
#include "nluadef.h"
#include "ntime.h"
Include dependency graph for nlua_time.c:

Go to the source code of this file.

Functions

static int timeL_new (lua_State *L)
 Creates a time. This can be absolute or relative.
static int timeL_add (lua_State *L)
 Adds two time metatables.
static int timeL_add__ (lua_State *L)
static int timeL_sub (lua_State *L)
 Subtracts two time metatables.
static int timeL_sub__ (lua_State *L)
static int timeL_eq (lua_State *L)
 Checks to see if two time are equal.
static int timeL_lt (lua_State *L)
 Checks to see if a time is strictly larger than another.
static int timeL_le (lua_State *L)
 Checks to see if a time is larger or equal to another.
static int timeL_get (lua_State *L)
 Gets the current time in internal representation time.
static int timeL_str (lua_State *L)
 Converts the time to a pretty human readable format.
static int timeL_inc (lua_State *L)
 Increases or decreases the in-game time.
static int timeL_tonumber (lua_State *L)
 Gets a number representing this time.
static int timeL_fromnumber (lua_State *L)
 Creates a time from a number representing it.
int nlua_loadTime (nlua_env env)
 Loads the Time Lua library.
ntime_t * lua_totime (lua_State *L, int ind)
 Bindings for interacting with the time.
ntime_t * luaL_checktime (lua_State *L, int ind)
 Gets time at index raising an error if isn't a time.
ntime_t luaL_validtime (lua_State *L, int ind)
 Gets a time directly.
ntime_t * lua_pushtime (lua_State *L, ntime_t time)
 Pushes a time on the stack.
int lua_istime (lua_State *L, int ind)
 Checks to see if ind is a time.

Variables

static const luaL_Reg time_methods []

Detailed Description

Time manipulation Lua bindings.

Definition in file nlua_time.c.

Function Documentation

◆ lua_istime()

int lua_istime ( lua_State * L,
int ind )

Checks to see if ind is a time.

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

Definition at line 138 of file nlua_time.c.

◆ lua_pushtime()

ntime_t * lua_pushtime ( lua_State * L,
ntime_t time )

Pushes a time on the stack.

Parameters
LLua state to push time into.
timeTime to push.
Returns
Newly pushed time.

Definition at line 123 of file nlua_time.c.

◆ lua_totime()

ntime_t * lua_totime ( lua_State * L,
int ind )

Bindings for interacting with the time.

Usage is generally something as follows:

time_limit = time.get() + time.new( 0, 5, 0 )
player.msg( string.format("You only have %s left!", time.str(time.get() -
time_limit)) )
-- Do stuff here
if time.get() > time_limit then
-- Limit is up
end
Player_t player
Definition player.c:77

Lua module: time

Gets time at index.

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

Definition at line 87 of file nlua_time.c.

◆ luaL_checktime()

ntime_t * luaL_checktime ( lua_State * L,
int ind )

Gets time at index raising an error if isn't a time.

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

Definition at line 98 of file nlua_time.c.

◆ luaL_validtime()

ntime_t luaL_validtime ( lua_State * L,
int ind )

Gets a time directly.

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

Definition at line 112 of file nlua_time.c.

◆ nlua_loadTime()

int nlua_loadTime ( nlua_env env)

Loads the Time Lua library.

Parameters
envLua environment.
Returns
0 on success.

Definition at line 56 of file nlua_time.c.

◆ timeL_add()

int timeL_add ( lua_State * L)
static

Adds two time metatables.

Overrides the addition operator.

Lua usage parameter: new_time = time.get() + time.new( 0, 5, 0 ) – Adds 5 periods to the current date Lua usage parameter: t:add( time.new( 0, 3, 0 ) ) – Directly modifies t

Lua function parameter: Time t1 Time metatable to add to. Lua function parameter: Time t2 Time metatable added.

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

Lua function: add

Definition at line 192 of file nlua_time.c.

◆ timeL_add__()

int timeL_add__ ( lua_State * L)
static

Definition at line 208 of file nlua_time.c.

◆ timeL_eq()

int timeL_eq ( lua_State * L)
static

Checks to see if two time are equal.

It is recommended to check with < and <= instead of ==.

Lua usage parameter: if time.new( 630, 5, 78) == time.get() then – do something if they match

Lua function parameter: Time t1 Time to compare for equality. Lua function parameter: Time t2 Time to compare for equality. Lua return parameter: boolean true if they're equal.

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

Lua function: __eq

Definition at line 278 of file nlua_time.c.

◆ timeL_fromnumber()

int timeL_fromnumber ( lua_State * L)
static

Creates a time from a number representing it.

The best usage for this currently is mission variables.

Lua usage parameter: t = time.fromnumber( t:tonumber() ) – Should get the time t again

Lua function parameter: number num Number to get time from. Lua return parameter: Time Time representing number.

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

Lua function: fromnumber

Definition at line 417 of file nlua_time.c.

◆ timeL_get()

int timeL_get ( lua_State * L)
static

Gets the current time in internal representation time.

Lua usage parameter: t = time.get()

Lua return parameter: Time Time in internal representation time.

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

Lua function: get

Definition at line 332 of file nlua_time.c.

◆ timeL_inc()

int timeL_inc ( lua_State * L)
static

Increases or decreases the in-game time.

Note that this can trigger hooks and fail missions and the likes.

Lua usage parameter: time.inc( time.new(0,0,100) ) – Increments the time by 100 seconds.

Lua function parameter: Time t Amount to increment or decrement the time by.

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

Lua function: inc

Definition at line 382 of file nlua_time.c.

◆ timeL_le()

int timeL_le ( lua_State * L)
static

Checks to see if a time is larger or equal to another.

Lua usage parameter: if time.new( 630, 5, 78) <= time.get() then – do something if time is past UST 630:0005.78

Lua function parameter: Time t1 Time to see if is is smaller or equal to than t2. Lua function parameter: Time t2 Time see if is larger or equal to than t1. Lua return parameter: boolean true if t1 <= t2

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

Lua function: __le

Definition at line 316 of file nlua_time.c.

◆ timeL_lt()

int timeL_lt ( lua_State * L)
static

Checks to see if a time is strictly larger than another.

Lua usage parameter: if time.new( 630, 5, 78) < time.get() then – do something if time is past UST 630:0005.78

Lua function parameter: Time t1 Time to see if is is smaller than t2. Lua function parameter: Time t2 Time see if is larger than t1. Lua return parameter: boolean true if t1 < t2

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

Lua function: __lt

Definition at line 297 of file nlua_time.c.

◆ timeL_new()

int timeL_new ( lua_State * L)
static

Creates a time. This can be absolute or relative.

Lua usage parameter: t = time.new( 591, 3271, 12801 ) – Gets a time near when the incident happened.

Lua function parameter: number cycles Cycles for the new time. Lua function parameter: number periods Periods for the new time. Lua function parameter: number seconds Seconds for the new time. Lua return parameter: Time A newly created time metatable.

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

Lua function: new

Definition at line 166 of file nlua_time.c.

◆ timeL_str()

int timeL_str ( lua_State * L)
static

Converts the time to a pretty human readable format.

Lua usage parameter: strt = time.str() – Gets current time Lua usage parameter: strt = time.str( nil, 5 ) – Gets current time with full decimals Lua usage parameter: strt = time.str( time.get() + time.new(0,5,0) ) – Gets time in 5 periods Lua usage parameter: strt = t:str() – Gets the string of t

Lua function parameter: Time t Time to convert to pretty format. If omitted, current time is used. Lua function parameter:[opt=2] number d Decimals to use for displaying seconds (should be between 0 and 5). Lua return parameter: string The time in human readable format.

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

Lua function: str

Definition at line 353 of file nlua_time.c.

◆ timeL_sub()

int timeL_sub ( lua_State * L)
static

Subtracts two time metatables.

Overrides the subtraction operator.

Lua usage parameter: new_time = time.get() - time.new( 0, 3, 0 ) – Subtracts 3 periods from the current date Lua usage parameter: t:sub( time.new( 0, 3, 0 ) ) – Directly modifies t

Lua function parameter: Time t1 Time metatable to subtract from. Lua function parameter: Time t2 Time metatable subtracted.

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

Lua function: sub

Definition at line 235 of file nlua_time.c.

◆ timeL_sub__()

int timeL_sub__ ( lua_State * L)
static

Definition at line 251 of file nlua_time.c.

◆ timeL_tonumber()

int timeL_tonumber ( lua_State * L)
static

Gets a number representing this time.

The best usage for this currently is mission variables.

Lua usage parameter: num = t:tonumber() – Getting the number from a time t

Lua function parameter: Time t Time to get number of. Lua return parameter: number Number representing time.

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

Lua function: tonumber

Definition at line 399 of file nlua_time.c.

Variable Documentation

◆ time_methods

const luaL_Reg time_methods[]
static
Initial value:
= { { "new", timeL_new },
{ "add", timeL_add__ },
{ "__add", timeL_add },
{ "sub", timeL_sub__ },
{ "__sub", timeL_sub },
{ "__eq", timeL_eq },
{ "__lt", timeL_lt },
{ "__le", timeL_le },
{ "get", timeL_get },
{ "str", timeL_str },
{ "__tostring", timeL_str },
{ "inc", timeL_inc },
{ "tonumber", timeL_tonumber },
{ "fromnumber", timeL_fromnumber },
{ 0, 0 } }
static int timeL_sub(lua_State *L)
Subtracts two time metatables.
Definition nlua_time.c:235
static int timeL_lt(lua_State *L)
Checks to see if a time is strictly larger than another.
Definition nlua_time.c:297
static int timeL_le(lua_State *L)
Checks to see if a time is larger or equal to another.
Definition nlua_time.c:316
static int timeL_tonumber(lua_State *L)
Gets a number representing this time.
Definition nlua_time.c:399
static int timeL_add(lua_State *L)
Adds two time metatables.
Definition nlua_time.c:192
static int timeL_fromnumber(lua_State *L)
Creates a time from a number representing it.
Definition nlua_time.c:417
static int timeL_new(lua_State *L)
Creates a time. This can be absolute or relative.
Definition nlua_time.c:166
static int timeL_inc(lua_State *L)
Increases or decreases the in-game time.
Definition nlua_time.c:382
static int timeL_eq(lua_State *L)
Checks to see if two time are equal.
Definition nlua_time.c:278
static int timeL_str(lua_State *L)
Converts the time to a pretty human readable format.
Definition nlua_time.c:353
static int timeL_get(lua_State *L)
Gets the current time in internal representation time.
Definition nlua_time.c:332

Time Lua methods.

Definition at line 34 of file nlua_time.c.