23#include "difficulty.h"
31#include "nlua_system.h"
38static int cache_table = LUA_NOREF;
79static int naevL_envs( lua_State *L );
80static int naevL_debugTrails( lua_State *L );
81static int naevL_debugCollisions( lua_State *L );
123 {
"envs", naevL_envs },
124 {
"debugTrails", naevL_debugTrails },
125 {
"debugCollisions", naevL_debugCollisions },
140 if ( cache_table == LUA_NOREF ) {
141 lua_newtable(
naevL );
142 cache_table = luaL_ref(
naevL, LUA_REGISTRYINDEX );
166 if (
player.loaded_version == NULL )
169 lua_pushstring( L,
player.loaded_version );
187 s1 = luaL_checkstring( L, 1 );
188 s2 = luaL_checkstring( L, 2 );
189 if ( semver_parse( s1, &sv1 ) )
190 NLUA_WARN( L, _(
"Failed to parse version string '%s'!" ), s1 );
191 if ( semver_parse( s2, &sv2 ) )
192 NLUA_WARN( L, _(
"Failed to parse version string '%s'!" ), s2 );
195 res = semver_compare( sv1, sv2 );
201 lua_pushinteger( L, res );
227 double d = difftime( time( NULL ),
player.last_played );
228 double g = difftime( time( NULL ), conf.last_played );
229 lua_pushnumber( L,
d / ( 3600. * 24. ) );
230 lua_pushnumber( L, g / ( 3600. * 24. ) );
241 const char *s = luaL_optstring( L, 1,
"%c" );
242 time_t t = luaL_opt( L, (time_t)luaL_checknumber, 2, time( NULL ) );
248 stm = localtime( &t );
251 else if ( strcmp( s,
"*t" ) == 0 ) {
252 lua_createtable( L, 0, 9 );
253#define setfield( L, key, value ) \
255 lua_pushinteger( L, value ); \
256 lua_setfield( L, -2, key ); \
258#define setboolfield( L, key, value ) \
260 if ( value >= 0 ) { \
261 lua_pushinteger( L, value ); \
262 lua_setfield( L, -2, key ); \
265 setfield( L,
"sec", stm->tm_sec );
266 setfield( L,
"min", stm->tm_min );
267 setfield( L,
"hour", stm->tm_hour );
268 setfield( L,
"day", stm->tm_mday );
269 setfield( L,
"month", stm->tm_mon + 1 );
270 setfield( L,
"year", stm->tm_year + 1900 );
271 setfield( L,
"wday", stm->tm_wday + 1 );
272 setfield( L,
"yday", stm->tm_yday + 1 );
273 setboolfield( L,
"isdst", stm->tm_isdst );
281 luaL_buffinit( L, &b );
283 if ( *s !=
'%' || *( s + 1 ) ==
'\0' )
284 luaL_addchar( &b, *s );
289 reslen = strftime( buff,
sizeof( buff ), cc, stm );
290 luaL_addlstring( &b, buff, reslen );
293 luaL_pushresult( &b );
322 lua_pushnumber( L, (
double)SDL_GetPerformanceCounter() /
323 (
double)SDL_GetPerformanceFrequency() );
335 lua_pushnumber( L, (
double)clock() / (
double)CLOCKS_PER_SEC );
363 const char *keyname = luaL_checkstring( L, 1 );
365 lua_pushstring( L, buf );
382 const char *key = luaL_checkstring( L, 1 );
383 int enable = lua_toboolean( L, 2 );
425 const char *str = luaL_checkstring( L, 1 );
428 if ( cli_isOpen() &&
landed )
431 lua_pushboolean( L, !ret );
446 for (
int i = 0; i <
array_size( misns ); i++ ) {
447 misn_pushMissionData( L, &misns[i] );
448 lua_rawseti( L, -2, i + 1 );
465 const char *str = luaL_checkstring( L, 1 );
468 if ( cli_isOpen() &&
landed ) {
473 lua_pushboolean( L, ( ret == 0 ) || ( ret == 3 ) );
474 lua_pushboolean( L, ( ret == 3 ) );
494 lua_pushboolean( L,
mission_test( luaL_checkstring( L, 1 ) ) );
510 const char *str = luaL_checkstring( L, 1 );
511 int ret = event_reload( str );
513 lua_pushboolean( L, !ret );
529 const char *str = luaL_checkstring( L, 1 );
530 int ret = mission_reload( str );
532 lua_pushboolean( L, !ret );
562#define PUSH_STRING( L, name, value ) \
563 lua_pushstring( L, name ); \
564 lua_pushstring( L, value ); \
566#define PUSH_DOUBLE( L, name, value ) \
567 lua_pushstring( L, name ); \
568 lua_pushnumber( L, value ); \
570#define PUSH_INT( L, name, value ) \
571 lua_pushstring( L, name ); \
572 lua_pushinteger( L, value ); \
574#define PUSH_BOOL( L, name, value ) \
575 lua_pushstring( L, name ); \
576 lua_pushboolean( L, value ); \
588 PUSH_STRING( L,
"data", conf.ndata );
589 PUSH_STRING( L,
"language", conf.language );
590 PUSH_STRING( L,
"difficulty", conf.difficulty );
591 PUSH_INT( L,
"fsaa", conf.fsaa );
592 PUSH_BOOL( L,
"vsync", conf.vsync );
593 PUSH_INT( L,
"width", conf.width );
594 PUSH_INT( L,
"height", conf.height );
595 PUSH_DOUBLE( L,
"scalefactor", conf.scalefactor );
596 PUSH_DOUBLE( L,
"nebu_scale", conf.nebu_scale );
597 PUSH_BOOL( L,
"fullscreen", conf.fullscreen );
598 PUSH_BOOL( L,
"modesetting", conf.modesetting );
599 PUSH_BOOL( L,
"notresizable", conf.notresizable );
600 PUSH_BOOL( L,
"borderless", conf.borderless );
601 PUSH_BOOL( L,
"minimize", conf.minimize );
602 PUSH_DOUBLE( L,
"colourblind_sim", conf.colourblind_sim );
603 PUSH_DOUBLE( L,
"colourblind_correct", conf.colourblind_correct );
604 PUSH_INT( L,
"colourblind_type", conf.colourblind_type );
605 PUSH_DOUBLE( L,
"game_speed", conf.game_speed );
606 PUSH_DOUBLE( L,
"bg_brightness", conf.bg_brightness );
607 PUSH_DOUBLE( L,
"nebu_nonuniformity", conf.nebu_nonuniformity );
608 PUSH_DOUBLE( L,
"nebu_saturation", conf.nebu_saturation );
609 PUSH_DOUBLE( L,
"gamma_correction", conf.gamma_correction );
610 PUSH_BOOL( L,
"low_memory", conf.low_memory );
611 PUSH_BOOL( L,
"showfps", conf.fps_show );
612 PUSH_INT( L,
"maxfps", conf.fps_max );
613 PUSH_BOOL( L,
"showpause", conf.pause_show );
614 PUSH_BOOL( L,
"al_efx", conf.al_efx );
615 PUSH_BOOL( L,
"nosound", conf.nosound );
616 PUSH_DOUBLE( L,
"sound", conf.sound );
617 PUSH_DOUBLE( L,
"music", conf.music );
619 PUSH_INT( L,
"mesg_visible", conf.mesg_visible );
620 PUSH_DOUBLE( L,
"map_overlay_opacity", conf.map_overlay_opacity );
621 PUSH_BOOL( L,
"big_icons", conf.big_icons );
622 PUSH_INT( L,
"repeat_delay", conf.repeat_delay );
623 PUSH_INT( L,
"repeat_freq", conf.repeat_freq );
624 PUSH_BOOL( L,
"zoom_manual", conf.zoom_manual );
625 PUSH_DOUBLE( L,
"zoom_far", conf.zoom_far );
626 PUSH_DOUBLE( L,
"zoom_near", conf.zoom_near );
627 PUSH_DOUBLE( L,
"zoom_speed", conf.zoom_speed );
628 PUSH_INT( L,
"font_size_console", conf.font_size_console );
629 PUSH_INT( L,
"font_size_intro", conf.font_size_intro );
630 PUSH_INT( L,
"font_size_def", conf.font_size_def );
631 PUSH_INT( L,
"font_size_small", conf.font_size_small );
632 PUSH_BOOL( L,
"redirect_file", conf.redirect_file );
633 PUSH_INT( L,
"doubletap_sensitivity", conf.doubletap_sens );
634 PUSH_DOUBLE( L,
"mouse_hide", conf.mouse_hide );
635 PUSH_BOOL( L,
"mouse_fly", conf.mouse_fly );
636 PUSH_INT( L,
"mouse_accel", conf.mouse_accel );
637 PUSH_DOUBLE( L,
"mouse_doubleclick", conf.mouse_doubleclick );
638 PUSH_BOOL( L,
"devmode", conf.devmode );
639 PUSH_BOOL( L,
"devautosave", conf.devautosave );
640 PUSH_BOOL( L,
"lua_enet", conf.lua_enet );
641 PUSH_BOOL( L,
"lua_repl", conf.lua_repl );
642 PUSH_BOOL( L,
"conf_nosave", conf.nosave );
643 PUSH_STRING( L,
"last_version", conf.lastversion );
644 PUSH_BOOL( L,
"translation_warning_seen", conf.translation_warning_seen );
645 PUSH_BOOL( L,
"fpu_except", conf.fpu_except );
646 PUSH_STRING( L,
"dev_data_dir", conf.dev_data_dir );
647 PUSH_BOOL( L,
"puzzle_skip", conf.puzzle_skip );
666 return NLUA_ERROR( L, _(
"unimplemented" ) );
680 lua_rawgeti( L, LUA_REGISTRYINDEX, cache_table );
702 const char *hookname = luaL_checkstring( L, 1 );
705 if ( !lua_isnoneornil( L, 2 ) ) {
708 hp[0].
type = HOOK_PARAM_REF;
709 lua_pushvalue( L, 2 );
710 hp[0].
u.
ref = luaL_ref( L, LUA_REGISTRYINDEX );
711 hp[1].
type = HOOK_PARAM_SENTINEL;
713 hp[0].
type = HOOK_PARAM_SENTINEL;
736 int inclusive = lua_toboolean( L, 2 );
739 if ( lua_istable( L, 1 ) ) {
742 while ( lua_next( L, 1 ) != 0 ) {
745 else if ( lua_isstring( L, -1 ) )
751 else if ( lua_isstring( L, 1 ) )
754 NLUA_INVALID_PARAMETER( L, 1 );
777 lua_pushstring( L, plg->x ); \
778 lua_setfield( L, -2, #x )
779#define INTEGER( x ) \
780 lua_pushinteger( L, plg->x ); \
781 lua_setfield( L, -2, #x )
783 lua_pushboolean( L, plg->x ); \
784 lua_setfield( L, -2, #x )
789 STRING( description );
790 STRING( compatibility );
791 STRING( mountpoint );
796 BOOL( total_conversion );
802 lua_rawseti( L, -2, i + 1 );
832 if ( lua_gettop( L ) > 0 )
833 str = luaL_checkstring( L, 1 );
841 if ( strcasecmp( str,
"main" ) == 0 )
843 else if ( strcasecmp( str,
"ship" ) == 0 )
845 else if ( strcasecmp( str,
"weapons" ) == 0 )
847 else if ( strcasecmp( str,
"cargo" ) == 0 )
849 else if ( strcasecmp( str,
"missions" ) == 0 )
851 else if ( strcasecmp( str,
"standings" ) == 0 )
854 return NLUA_ERROR( L, _(
"Invalid window info name '%s'." ), str );
875 menu_small( 0, lua_toboolean( L, 1 ), lua_toboolean( L, 2 ),
876 lua_toboolean( L, 3 ) );
888 lua_pushboolean( L,
paused );
914 return NLUA_ERROR( L, _(
"Unable to unpause the game when landed!" ) );
927 lua_pushboolean( L, SDL_EventState( SDL_TEXTINPUT, SDL_QUERY ) == SDL_TRUE );
943 if ( lua_toboolean( L, 1 ) ) {
945 input_pos.x = luaL_checkinteger( L, 2 );
946 input_pos.y = luaL_checkinteger( L, 3 );
947 input_pos.w = luaL_checkinteger( L, 4 );
948 input_pos.h = luaL_checkinteger( L, 5 );
949 SDL_EventState( SDL_TEXTINPUT, SDL_ENABLE );
950 SDL_StartTextInput();
951 SDL_SetTextInputRect( &input_pos );
954 SDL_EventState( SDL_TEXTINPUT, SDL_DISABLE );
959static const char *unittbl[] = {
960 "time", _UNIT_TIME,
"per_time", _UNIT_PER_TIME,
"distance",
961 _UNIT_DISTANCE,
"speed", _UNIT_SPEED,
"accel", _UNIT_ACCEL,
962 "energy", _UNIT_ENERGY,
"power", _UNIT_POWER,
"angle",
963 _UNIT_ANGLE,
"rotation", _UNIT_ROTATION,
"mass", _UNIT_MASS,
964 "cpu", _UNIT_CPU,
"unit", _UNIT_UNIT,
"percent",
977 if ( lua_isnoneornil( L, 1 ) ) {
979 for (
unsigned int i = 0; i <
sizeof( unittbl ) /
sizeof( unittbl[0] );
981 lua_pushstring( L, _( unittbl[i + 1] ) );
982 lua_setfield( L, -2, unittbl[i] );
986 const char *str = luaL_checkstring( L, 1 );
987 for (
unsigned int i = 0; i <
sizeof( unittbl ) /
sizeof( unittbl[0] );
989 if ( strcmp( unittbl[i], str ) == 0 ) {
990 lua_pushstring( L, _( unittbl[i + 1] ) );
995 NLUA_INVALID_PARAMETER( L, 1 );
1008 int max_elem = luaL_checkinteger( L, 1 );
1009 int depth = luaL_checkinteger( L, 2 );
1027 lua_pushstring( L, dif->
name );
1041static int naevL_envs( lua_State *L )
1043 nlua_pushEnvTable( L );
1056static int naevL_debugTrails( lua_State *L )
1058 int state = ( lua_gettop( L ) > 0 ) ? lua_toboolean( L, 1 ) : 1;
1060 debug_setFlag( DEBUG_MARK_EMITTER );
1062 debug_rmFlag( DEBUG_MARK_EMITTER );
1073static int naevL_debugCollisions( lua_State *L )
1075 int state = ( lua_gettop( L ) > 0 ) ? lua_toboolean( L, 1 ) : 1;
1077 debug_setFlag( DEBUG_MARK_COLLISION );
1079 debug_rmFlag( DEBUG_MARK_COLLISION );
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.
void misn_regen(void)
Regenerates the mission 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_date(lua_State *L)
Equivalent to os.date from standard Lua.
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_difficulty(lua_State *L)
Gets information about the current difficulty setting.
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.
static plugin_t * plugins
const plugin_t * plugin_list(void)
Returns the list of all the plugins.
int ss_statsGetLuaTableList(lua_State *L, const ShipStatList *list, int internal)
Converts ship stats to a Lua table, which is pushed on the Lua stack.
int space_isSimulation(void)
returns whether we're just simulating.
The actual hook parameter.
union HookParam::@114305201244257020071001257133270030317263020235 u