27#include "nlua_system.h"
35static int cache_table = LUA_NOREF;
74static int naevL_envs( lua_State *L );
113 {
"envs", naevL_envs },
129 if (cache_table == LUA_NOREF) {
130 lua_newtable( naevL );
131 cache_table = luaL_ref(naevL, LUA_REGISTRYINDEX);
176 s1 = luaL_checkstring(L,1);
177 s2 = luaL_checkstring(L,2);
178 if (semver_parse( s1, &sv1 ))
179 WARN( _(
"Failed to parse version string '%s'!"), s1 );
180 if (semver_parse( s2, &sv2 ))
181 WARN( _(
"Failed to parse version string '%s'!"), s2 );
184 res = semver_compare( sv1, sv2 );
190 lua_pushinteger(L,res);
216 double g = difftime( time(NULL), conf.
last_played );
217 lua_pushnumber(L,
d/(3600.*24.));
218 lua_pushnumber(L, g/(3600.*24.));
246 lua_pushnumber(L, (
double)SDL_GetTicks64() / 1000.);
258 lua_pushnumber(L, (
double)clock() / (
double)CLOCKS_PER_SEC );
285 const char *keyname = luaL_checkstring( L, 1 );
288 lua_pushstring( L, buf );
305 const char *key = luaL_checkstring(L,1);
306 int enable = lua_toboolean(L,2);
348 const char *str = luaL_checkstring(L, 1);
351 if (cli_isOpen() &&
landed)
354 lua_pushboolean( L, !ret );
369 misn_pushMissionData( L, &misns[i] );
370 lua_rawseti(L,-2,i+1);
386 const char *str = luaL_checkstring(L, 1);
389 if (cli_isOpen() &&
landed)
392 lua_pushboolean( L, (ret==0) || (ret==3) );
393 lua_pushboolean( L, (ret==3) );
409 lua_pushboolean( L,
mission_test( luaL_checkstring(L, 1) ) );
424 const char *str = luaL_checkstring(L, 1);
425 int ret = event_reload( str );
427 lua_pushboolean( L, !ret );
442 const char *str = luaL_checkstring(L, 1);
443 int ret = mission_reload( str );
445 lua_pushboolean( L, !ret );
474#define PUSH_STRING( L, name, value ) \
475lua_pushstring( L, name ); \
476lua_pushstring( L, value ); \
478#define PUSH_DOUBLE( L, name, value ) \
479lua_pushstring( L, name ); \
480lua_pushnumber( L, value ); \
482#define PUSH_INT( L, name, value ) \
483lua_pushstring( L, name ); \
484lua_pushinteger( L, value ); \
486#define PUSH_BOOL( L, name, value ) \
487lua_pushstring( L, name ); \
488lua_pushboolean( L, value ); \
499 PUSH_STRING( L,
"data", conf.
ndata );
500 PUSH_STRING( L,
"language", conf.
language );
501 PUSH_STRING( L,
"difficulty", conf.
difficulty );
502 PUSH_INT( L,
"fsaa", conf.
fsaa );
503 PUSH_BOOL( L,
"vsync", conf.
vsync );
504 PUSH_INT( L,
"width", conf.
width );
505 PUSH_INT( L,
"height", conf.
height );
507 PUSH_DOUBLE( L,
"nebu_scale", conf.
nebu_scale );
508 PUSH_BOOL( L,
"fullscreen", conf.
fullscreen );
511 PUSH_BOOL( L,
"borderless", conf.
borderless );
512 PUSH_BOOL( L,
"minimize", conf.
minimize );
518 PUSH_BOOL( L,
"showfps", conf.
fps_show );
519 PUSH_INT( L,
"maxfps", conf.
fps_max );
521 PUSH_BOOL( L,
"al_efx", conf.
al_efx );
522 PUSH_BOOL( L,
"nosound", conf.
nosound );
523 PUSH_DOUBLE( L,
"sound", conf.
sound );
524 PUSH_DOUBLE( L,
"music", conf.
music );
528 PUSH_BOOL( L,
"big_icons", conf.
big_icons );
532 PUSH_DOUBLE( L,
"zoom_far", conf.
zoom_far );
533 PUSH_DOUBLE( L,
"zoom_near", conf.
zoom_near );
534 PUSH_DOUBLE( L,
"zoom_speed", conf.
zoom_speed );
542 PUSH_DOUBLE( L,
"mouse_hide", conf.
mouse_hide );
543 PUSH_BOOL( L,
"mouse_fly", conf.
mouse_fly );
546 PUSH_BOOL( L,
"devmode", conf.
devmode );
548 PUSH_BOOL( L,
"lua_enet", conf.
lua_enet );
549 PUSH_BOOL( L,
"lua_repl", conf.
lua_repl );
550 PUSH_BOOL( L,
"conf_nosave", conf.
nosave );
551 PUSH_STRING( L,
"last_version", conf.
lastversion );
553 PUSH_BOOL( L,
"fpu_except", conf.
fpu_except );
580 return NLUA_ERROR(L, _(
"unimplemented"));
594 lua_rawgeti( L, LUA_REGISTRYINDEX, cache_table );
613 const char *hookname = luaL_checkstring(L,1);
616 if (!lua_isnoneornil(L,2)) {
619 hp[0].
type = HOOK_PARAM_REF;
621 hp[0].
u.
ref = luaL_ref( L, LUA_REGISTRYINDEX );
622 hp[1].
type = HOOK_PARAM_SENTINEL;
625 hp[0].
type = HOOK_PARAM_SENTINEL;
644 int inclusive = lua_toboolean(L,2);
647 if (lua_istable(L,1)) {
650 while (lua_next(L, 1) != 0) {
653 else if (lua_isstring(L,-1))
660 else if (lua_isstring(L, 1))
663 NLUA_INVALID_PARAMETER(L,1);
686 lua_pushstring(L,plg->x); \
687 lua_setfield(L,-2,#x)
689 lua_pushinteger(L,plg->x); \
690 lua_setfield(L,-2,#x)
692 lua_pushboolean(L,plg->x); \
693 lua_setfield(L,-2,#x)
699 STRING(compatibility);
705 BOOL(total_conversion);
711 lua_rawseti(L,-2,i+1);
740 if (lua_gettop(L) > 0)
741 str = luaL_checkstring(L,1);
749 if (strcasecmp( str,
"main" )==0)
751 else if (strcasecmp( str,
"ship" )==0)
753 else if (strcasecmp( str,
"weapons" )==0)
755 else if (strcasecmp( str,
"cargo" )==0)
757 else if (strcasecmp( str,
"missions" )==0)
759 else if (strcasecmp( str,
"standings" )==0)
762 return NLUA_ERROR(L,_(
"Invalid window info name '%s'."), str);
782 menu_small( 0, lua_toboolean(L,1), lua_toboolean(L,2), lua_toboolean(L,3) );
794 lua_pushboolean( L,
paused );
820 return NLUA_ERROR(L, _(
"Unable to unpause the game when landed!"));
833 lua_pushboolean( L, SDL_EventState( SDL_TEXTINPUT, SDL_QUERY ) == SDL_TRUE );
849 if (lua_toboolean(L,1)) {
851 input_pos.x = luaL_checkinteger(L,2);
852 input_pos.y = luaL_checkinteger(L,3);
853 input_pos.w = luaL_checkinteger(L,4);
854 input_pos.h = luaL_checkinteger(L,5);
855 SDL_EventState( SDL_TEXTINPUT, SDL_ENABLE );
856 SDL_StartTextInput();
857 SDL_SetTextInputRect( &input_pos );
861 SDL_EventState( SDL_TEXTINPUT, SDL_DISABLE );
866static const char *unittbl[] = {
868 "per_time", _UNIT_PER_TIME,
869 "distance", _UNIT_DISTANCE,
870 "speed", _UNIT_SPEED,
871 "accel", _UNIT_ACCEL,
872 "energy", _UNIT_ENERGY,
873 "power", _UNIT_POWER,
874 "angle", _UNIT_ANGLE,
875 "rotation", _UNIT_ROTATION,
879 "percent", _UNIT_PERCENT,
889 if (lua_isnoneornil(L,1)) {
891 for (
unsigned int i=0; i<
sizeof(unittbl)/
sizeof(unittbl[0]); i+=2) {
892 lua_pushstring( L, _(unittbl[i+1]) );
893 lua_setfield( L, -2, unittbl[i] );
898 const char *str = luaL_checkstring(L,1);
899 for (
unsigned int i=0; i<
sizeof(unittbl)/
sizeof(unittbl[0]); i+=2) {
900 if (strcmp(unittbl[i],str)==0) {
901 lua_pushstring( L, _(unittbl[i+1]) );
906 NLUA_INVALID_PARAMETER(L,1);
918 int max_elem = luaL_checkinteger( L, 1 );
919 int depth = luaL_checkinteger( L, 2 );
933static int naevL_envs( lua_State *L )
935 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 bar_regen(void)
Regenerates the bar list.
int mission_start(const char *name, unsigned int *id)
Starts a mission.
const MissionData * mission_list(void)
Returns all the missions.
int mission_test(const char *name)
Tests the conditionals of a mission.
double fps_current(void)
Gets the current FPS.
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_unit(lua_State *L)
Gets the translated string corresponding to an in-game unit. Lua function parameter:[opt=nil] string ...
static int naevL_conf(lua_State *L)
Gets the configuration information.
static int naevL_fps(lua_State *L)
Gets the current game FPS as displayed to the player.
static int naevL_missionTest(lua_State *L)
Tests a missions conditionals to see if it can be started by the player.
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_quadtreeParams(lua_State *L)
Modifies the Naev internal quadtree lookup parameters.
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_missionList(lua_State *L)
Lists all the missions in the game.
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.
void pilot_quadtreeParams(int max_elem, int depth)
Sets the quad tree parameters. Can have significant impact on performance.
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
double nebu_nonuniformity
int translation_warning_seen