27#include "nlua_system.h"
35static int cache_table = LUA_NOREF;
69static int naevL_envs( lua_State *L );
103 {
"envs", naevL_envs },
119 if (cache_table == LUA_NOREF) {
120 lua_newtable( naevL );
121 cache_table = luaL_ref(naevL, LUA_REGISTRYINDEX);
166 s1 = luaL_checkstring(L,1);
167 s2 = luaL_checkstring(L,2);
168 if (semver_parse( s1, &sv1 ))
169 WARN( _(
"Failed to parse version string '%s'!"), s1 );
170 if (semver_parse( s2, &sv2 ))
171 WARN( _(
"Failed to parse version string '%s'!"), s2 );
174 res = semver_compare( sv1, sv2 );
180 lua_pushinteger(L,res);
206 double g = difftime( time(NULL), conf.
last_played );
207 lua_pushnumber(L,
d/(3600.*24.));
208 lua_pushnumber(L, g/(3600.*24.));
236 lua_pushnumber(L, (
double)SDL_GetTicks() / 1000.);
248 lua_pushnumber(L, (
double)clock() / (
double)CLOCKS_PER_SEC );
263 const char *keyname = luaL_checkstring( L, 1 );
266 lua_pushstring( L, buf );
283 const char *key = luaL_checkstring(L,1);
284 int enable = lua_toboolean(L,2);
326 const char *str = luaL_checkstring(L, 1);
329 if (cli_isOpen() &&
landed)
332 lua_pushboolean( L, !ret );
347 const char *str = luaL_checkstring(L, 1);
350 if (cli_isOpen() &&
landed)
353 lua_pushboolean( L, (ret==0) || (ret==3) );
354 lua_pushboolean( L, (ret==3) );
369 const char *str = luaL_checkstring(L, 1);
370 int ret = event_reload( str );
372 lua_pushboolean( L, !ret );
387 const char *str = luaL_checkstring(L, 1);
388 int ret = mission_reload( str );
390 lua_pushboolean( L, !ret );
419#define PUSH_STRING( L, name, value ) \
420lua_pushstring( L, name ); \
421lua_pushstring( L, value ); \
423#define PUSH_DOUBLE( L, name, value ) \
424lua_pushstring( L, name ); \
425lua_pushnumber( L, value ); \
427#define PUSH_INT( L, name, value ) \
428lua_pushstring( L, name ); \
429lua_pushinteger( L, value ); \
431#define PUSH_BOOL( L, name, value ) \
432lua_pushstring( L, name ); \
433lua_pushboolean( L, value ); \
444 PUSH_STRING( L,
"data", conf.
ndata );
445 PUSH_STRING( L,
"language", conf.
language );
446 PUSH_STRING( L,
"difficulty", conf.
difficulty );
447 PUSH_INT( L,
"fsaa", conf.
fsaa );
448 PUSH_BOOL( L,
"vsync", conf.
vsync );
449 PUSH_INT( L,
"width", conf.
width );
450 PUSH_INT( L,
"height", conf.
height );
452 PUSH_DOUBLE( L,
"nebu_scale", conf.
nebu_scale );
453 PUSH_BOOL( L,
"fullscreen", conf.
fullscreen );
456 PUSH_BOOL( L,
"borderless", conf.
borderless );
457 PUSH_BOOL( L,
"minimize", conf.
minimize );
458 PUSH_BOOL( L,
"colorblind", conf.
colorblind );
462 PUSH_BOOL( L,
"showfps", conf.
fps_show );
463 PUSH_INT( L,
"maxfps", conf.
fps_max );
465 PUSH_BOOL( L,
"al_efx", conf.
al_efx );
466 PUSH_BOOL( L,
"nosound", conf.
nosound );
467 PUSH_DOUBLE( L,
"sound", conf.
sound );
468 PUSH_DOUBLE( L,
"music", conf.
music );
472 PUSH_BOOL( L,
"big_icons", conf.
big_icons );
476 PUSH_DOUBLE( L,
"zoom_far", conf.
zoom_far );
477 PUSH_DOUBLE( L,
"zoom_near", conf.
zoom_near );
478 PUSH_DOUBLE( L,
"zoom_speed", conf.
zoom_speed );
479 PUSH_DOUBLE( L,
"zoom_stars", conf.
zoom_stars );
489 PUSH_BOOL( L,
"mouse_fly", conf.
mouse_fly );
494 PUSH_BOOL( L,
"devmode", conf.
devmode );
496 PUSH_BOOL( L,
"lua_enet", conf.
lua_enet );
497 PUSH_BOOL( L,
"lua_repl", conf.
lua_repl );
498 PUSH_BOOL( L,
"conf_nosave", conf.
nosave );
499 PUSH_STRING( L,
"last_version", conf.
lastversion );
501 PUSH_BOOL( L,
"fpu_except", conf.
fpu_except );
523 NLUA_ERROR(L, _(
"unimplemented"));
538 lua_rawgeti( L, LUA_REGISTRYINDEX, cache_table );
557 const char *hookname = luaL_checkstring(L,1);
560 if (lua_isnoneornil(L,2)) {
563 hp[0].
type = HOOK_PARAM_REF;
565 hp[0].
u.
ref = luaL_ref( L, LUA_REGISTRYINDEX );
566 hp[1].
type = HOOK_PARAM_SENTINEL;
569 hp[0].
type = HOOK_PARAM_SENTINEL;
588 int inclusive = lua_toboolean(L,2);
591 if (lua_istable(L,1)) {
594 while (lua_next(L, 1) != 0) {
597 else if (lua_isstring(L,-1))
604 else if (lua_isstring(L, 1))
607 NLUA_INVALID_PARAMETER(L);
630 lua_pushstring(L,plg->x); \
631 lua_setfield(L,-2,#x)
633 lua_pushinteger(L,plg->x); \
634 lua_setfield(L,-2,#x)
636 lua_pushboolean(L,plg->x); \
637 lua_setfield(L,-2,#x)
643 STRING(compatibility);
649 BOOL(total_conversion);
655 lua_rawseti(L,-2,i+1);
685 if (lua_gettop(L) > 0)
686 str = luaL_checkstring(L,1);
694 if (strcasecmp( str,
"main" )==0)
696 else if (strcasecmp( str,
"ship" )==0)
698 else if (strcasecmp( str,
"weapons" )==0)
700 else if (strcasecmp( str,
"cargo" )==0)
702 else if (strcasecmp( str,
"missions" )==0)
704 else if (strcasecmp( str,
"standings" )==0)
707 NLUA_ERROR(L,_(
"Invalid window info name '%s'."), str);
729 menu_small( 0, lua_toboolean(L,1), lua_toboolean(L,2), lua_toboolean(L,3) );
741 lua_pushboolean( L,
paused );
767 NLUA_ERROR(L, _(
"Unable to unpause the game when landed!"));
780 lua_pushboolean( L, SDL_EventState( SDL_TEXTINPUT, SDL_QUERY ) == SDL_TRUE );
796 if (lua_toboolean(L,1)) {
798 input_pos.x = luaL_checkinteger(L,2);
799 input_pos.y = luaL_checkinteger(L,3);
800 input_pos.w = luaL_checkinteger(L,4);
801 input_pos.h = luaL_checkinteger(L,5);
802 SDL_EventState( SDL_TEXTINPUT, SDL_ENABLE );
803 SDL_StartTextInput();
804 SDL_SetTextInputRect( &input_pos );
808 SDL_EventState( SDL_TEXTINPUT, SDL_DISABLE );
822static int naevL_envs( lua_State *L )
824 nlua_pushEnvTable( L );
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
int claim_test(const Claim_t *claim)
Tests to see if a system claim would have collisions.
void claim_destroy(Claim_t *claim)
Destroys a system claim.
int claim_addStr(Claim_t *claim, const char *str)
Adds a string claim to a claim.
int claim_addSys(Claim_t *claim, int ss_id)
Adds a claim to a system claim.
Claim_t * claim_create(int exclusive)
Creates a system claim.
int event_start(const char *name, unsigned int *id)
Starts an event.
const char * gettext_getLanguage(void)
Gets the active (primary) translation language. Even in case of a complex locale, this will be the na...
int hooks_runParamDeferred(const char *stack, const HookParam *param)
Runs all the hooks of stack in the next frame. Does not trigger right away.
void menu_info(int window)
Opens the information menu.
void bar_regen(void)
Regenerates the bar list.
int mission_start(const char *name, unsigned int *id)
Starts a mission.
Header file with generic functions and naev-specifics.
const char * naev_version(int long_version)
Returns the version in a human readable string.
static int naevL_isSimulation(lua_State *L)
Gets whether or not the universe is being simulated or not.
static int naevL_menuInfo(lua_State *L)
Opens the info menu window.
static int naevL_conf(lua_State *L)
Gets the configuration information.
static int naevL_eventReload(lua_State *L)
Reloads an event's script, providing a convenient way to test and hopefully not corrupt the game's st...
static int naevL_shadersReload(lua_State *L)
Reloads all the Naev shaders excluding those created by the shader library.
static int naevL_lastplayed(lua_State *L)
Gets how many days it has been since the player last played Naev.
static int naevL_confSet(lua_State *L)
Sets configuration variables. Note that not all are supported.
static int naevL_claimTest(lua_State *L)
Tests a claim of a system or strings.
static int naevL_missionStart(lua_State *L)
Starts a mission, does no check start conditions.
static int naevL_keyDisableAll(lua_State *L)
Disables all inputs.
int nlua_loadNaev(nlua_env env)
Loads the Naev Lua library.
static int naevL_keyGet(lua_State *L)
Gets a human-readable name for the key bound to a function.
static int naevL_pause(lua_State *L)
Pauses the game.
static int naevL_clock(lua_State *L)
Gets the approximate CPU processing time.
static int naevL_plugins(lua_State *L)
Gets the list of available plugins.
static int naevL_setTextInput(lua_State *L)
Enables or disables text inputting.
static int naevL_menuSmall(lua_State *L)
Opens the small menu window.
static int naevL_hasTextInput(lua_State *L)
Checks to see if text inputting is enabled.
static int naevL_cache(lua_State *L)
Gets the global Lua runtime cache. This is shared among all environments and is cleared when the game...
static int naevL_version(lua_State *L)
Naev generic Lua bindings.
static int naevL_keyEnableAll(lua_State *L)
Enables all inputs.
static int naevL_missionReload(lua_State *L)
Reloads a mission's script, providing a convenient way to test and hopefully not corrupt the game's s...
static int naevL_keyEnable(lua_State *L)
Disables or enables a specific keybinding.
static int naevL_language(lua_State *L)
Gets the current language locale.
static int naevL_ticks(lua_State *L)
Gets the seconds since the program started running.
static int naevL_trigger(lua_State *L)
Triggers manually a hook stack. This is run deferred (next frame). Meant mainly to be used with hook....
static int naevL_isPaused(lua_State *L)
Checks to see if the game is paused.
static int naevL_eventStart(lua_State *L)
Starts an event, does not start check conditions.
static int naevL_versionTest(lua_State *L)
Tests two semver version strings.
static int naevL_unpause(lua_State *L)
Unpauses the game.
static int naevL_ticksGame(lua_State *L)
Gets the game seconds since the program started running.
static const luaL_Reg naev_methods[]
LuaSystem lua_tosystem(lua_State *L, int ind)
Lua system module.
int lua_issystem(lua_State *L, int ind)
Checks to see if ind is a system.
void pause_game(void)
Pauses the game.
void unpause_game(void)
Unpauses the game.
const plugin_t * plugin_list(void)
Returns the list of all the plugins.
int space_isSimulation(void)
returns whether we're just simulating.
The actual hook parameter.
double autonav_reset_shield
double compression_velocity
double autonav_reset_dist
unsigned int repeat_delay
unsigned int doubletap_sens
double map_overlay_opacity
int translation_warning_seen