Skip to content

Commit 880bfb1

Browse files
Upgrade lua enumeration handling (scp-fs2open#7423)
* upgrade lua enumeration handling * some cleanup * add lua enum descriptions * minor fixes * Update code/scripting/api/objs/enums.cpp Co-authored-by: John Fernandez <jafernandez.tampabay@gmail.com> * include name --------- Co-authored-by: John Fernandez <jafernandez.tampabay@gmail.com>
1 parent f4d84ec commit 880bfb1

27 files changed

Lines changed: 665 additions & 81 deletions

code/scripting/api/libs/async.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ ADE_FUNC(captureGameState,
396396

397397
ADE_FUNC(createLuaState,
398398
l_Async_Context,
399-
"function() => enumeration",
400-
"Creates an execution state by storing the passed function and calling that when the state is required.",
399+
"function() => enumeration /* CONTEXT_* */",
400+
"Creates an execution state by storing the passed function and calling that when the state is required. The function must return a CONTEXT_* enumeration.",
401401
"execution_context",
402402
"The execution context or invalid handle on error")
403403
{

code/scripting/api/libs/audio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ ADE_FUNC(pauseMusic,
341341

342342
ADE_FUNC(openAudioStream,
343343
l_Audio,
344-
"string fileName, enumeration stream_type /* AUDIOSTREAM_* values */",
344+
"string fileName, enumeration stream_type /* AUDIOSTREAM_* */",
345345
"Opens an audio stream of the specified file and type. An audio stream is meant for more long time sounds since "
346346
"they are streamed from the file instead of loaded in its entirety.",
347347
"audio_stream",

code/scripting/api/libs/base.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ ADE_FUNC(savePlayer, l_Base, "player plr", "Saves the specified player.", "boole
396396

397397
ADE_FUNC(setControlMode,
398398
l_Base,
399-
"nil|enumeration mode /* LE_*_CONTROL */",
400-
"Sets the current control mode for the game.",
399+
"nil|enumeration mode /* FLIGHT_CONTROL_* */",
400+
"Sets the current flight control mode for the game.",
401401
"string",
402402
"Current control mode")
403403
{
@@ -437,8 +437,8 @@ ADE_FUNC(setControlMode,
437437

438438
ADE_FUNC(setButtonControlMode,
439439
l_Base,
440-
"nil|enumeration mode /* LE_*_BUTTON_CONTROL */",
441-
"Sets the current control mode for the game.",
440+
"nil|enumeration mode /* BUTTON_CONTROL_* */",
441+
"Sets the current button control mode for the game.",
442442
"string",
443443
"Current control mode")
444444
{

code/scripting/api/libs/controls.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ ADE_FUNC(getMouseY, l_Mouse, nullptr, "Gets Mouse Y pos", "number", "Mouse y pos
7575

7676
ADE_FUNC(isMouseButtonDown,
7777
l_Mouse,
78-
"enumeration buttonCheck1 /* MOUSE_*_BUTTON */, [ enumeration buttonCheck2 /* MOUSE_*_BUTTON */, enumeration "
79-
"buttonCheck3 /* MOUSE_*_BUTTON */ ]",
80-
"Returns whether the specified mouse buttons are up or down",
78+
"enumeration buttonCheck1 /* MOUSE_* */, [enumeration buttonCheck2 /* MOUSE_* */, enumeration buttonCheck3 /* MOUSE_* */]",
79+
"Returns whether the specified MOUSE_* buttons are up or down",
8180
"boolean",
8281
"Whether specified mouse buttons are down, or false if mouse is not initialized yet")
8382
{
@@ -115,8 +114,8 @@ ADE_FUNC(isMouseButtonDown,
115114

116115
ADE_FUNC(mouseButtonDownCount,
117116
l_Mouse,
118-
"enumeration buttonCheck /* any one of MOUSE_LEFT_BUTTON, MOUSE_RIGHT_BUTTON, MOUSE_MIDDLE_BUTTON, MOUSE_X1_BUTTON, MOUSE_X2_BUTTON */, [ boolean reset_count ]",
119-
"Returns the pressed count of the specified button. The count is then reset, unless reset_count (which defaults to true) is false.",
117+
"enumeration buttonCheck /* MOUSE_* */, [boolean reset_count]",
118+
"Returns the pressed count of the specified MOUSE_* button. The count is then reset, unless reset_count (which defaults to true) is false.",
120119
"number",
121120
"The number of frames this button has been pressed, or -1 if the mouse has not been initialized")
122121
{
@@ -315,7 +314,7 @@ ADE_FUNC(AxisInverted, l_Mouse, "number cid, number axis, boolean inverted", "Ge
315314
return ADE_RETURN_FALSE;
316315
}
317316

318-
ADE_VIRTVAR(FlightCursorMode, l_Mouse, "enumeration FlightMode", "Flight Mode; uses LE_FLIGHTMODE_* enumerations.", "enumeration", "enumeration flight mode")
317+
ADE_VIRTVAR(FlightCursorMode, l_Mouse, "enumeration /* FLIGHTMODE_* */", "Flight Mode; uses FLIGHTMODE_* enumerations.", "enumeration", "Current flight cursor mode as a FLIGHTMODE_* enumeration")
319318
{
320319
enum_h flightmode_arg;
321320

code/scripting/api/libs/graphics.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ ADE_VIRTVAR(CurrentRenderTarget, l_Graphics, "texture", "Current rendering targe
278278
}
279279
}
280280

281-
ADE_VIRTVAR(CurrentResizeMode, l_Graphics, "enumeration ResizeMode", "Current resize mode; uses GR_RESIZE_* enumerations. This resize mode will be used by the gr.* drawing methods.", "enumeration", nullptr)
281+
ADE_VIRTVAR(CurrentResizeMode, l_Graphics, "enumeration /* GR_RESIZE_* */", "Current resize mode; uses GR_RESIZE_* enumerations. This resize mode will be used by the gr.* drawing methods.", "enumeration", nullptr)
282282
{
283283
enum_h resize_arg;
284284

@@ -1510,7 +1510,7 @@ ADE_FUNC(drawString, l_Graphics, "string|boolean Message, [number X1, number Y1,
15101510
return drawString_sub(L, false);
15111511
}
15121512

1513-
ADE_FUNC(drawStringResized, l_Graphics, "enumeration ResizeMode, string|boolean Message, [number X1, number Y1, number X2, number Y2]",
1513+
ADE_FUNC(drawStringResized, l_Graphics, "enumeration ResizeMode /* GR_RESIZE_* */, string|boolean Message, [number X1, number Y1, number X2, number Y2]",
15141514
"Draws a string, scaled according to the GR_RESIZE_* parameter. Use x1/y1 to control position, x2/y2 to limit textbox size."
15151515
"Text will automatically move onto new lines, if x2/y2 is specified, however the line spacing will probably not be correct."
15161516
"Additionally, calling drawString with only a string argument will automatically"
@@ -2046,7 +2046,7 @@ ADE_FUNC(loadModel, l_Graphics, "string Filename", "Loads the model - will not s
20462046
return ade_set_args(L, "o", l_Model.Set(model_h(model_num)));
20472047
}
20482048

2049-
ADE_FUNC(hasViewmode, l_Graphics, "enumeration", "Specifies if the current viemode has the specified flag, see VM_* enumeration", "boolean", "true if flag is present, false otherwise")
2049+
ADE_FUNC(hasViewmode, l_Graphics, "enumeration /* VM_* */", "Specifies if the current viewmode has the specified flag.", "boolean", "true if flag is present, false otherwise")
20502050
{
20512051
enum_h *type = NULL;
20522052

@@ -2145,7 +2145,7 @@ ADE_FUNC(hasViewmode, l_Graphics, "enumeration", "Specifies if the current viemo
21452145
return ade_set_args(L, "b", (Viewer_mode & bit) != 0);
21462146
}
21472147

2148-
ADE_FUNC(setClip, l_Graphics, "number x, number y, number width, number height, [enumeration ResizeMode]", "Sets the clipping region to the specified rectangle. Most drawing functions are able to handle the offset.", "boolean", "true if successful, false otherwise")
2148+
ADE_FUNC(setClip, l_Graphics, "number x, number y, number width, number height, [enumeration /* GR_RESIZE_* */]", "Sets the clipping region to the specified rectangle using GR_RESIZE_* enumerations. Most drawing functions are able to handle the offset.", "boolean", "true if successful, false otherwise")
21492149
{
21502150
int x, y, width, height;
21512151
enum_h resize_arg;

code/scripting/api/libs/hud.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ ADE_FUNC(getHUDGaugeHandle, l_HUD, "string Name", "Returns a handle to a specifi
260260
return ade_set_args(L, "o", l_HudGauge.Set(gauge));
261261
}
262262

263-
ADE_FUNC(flashTargetBox, l_HUD, "enumeration section, [number duration_in_milliseconds]", "Flashes a section of the target box with a default duration of " SCP_TOKEN_TO_STR(TBOX_FLASH_DURATION) " milliseconds", nullptr, nullptr)
263+
ADE_FUNC(flashTargetBox, l_HUD, "enumeration section /* TBOX_* */, [number duration_in_milliseconds]", "Flashes a section of the target box with a default duration of " SCP_TOKEN_TO_STR(TBOX_FLASH_DURATION) " milliseconds", nullptr, nullptr)
264264
{
265265
enum_h section;
266266
int num_args, duration;

code/scripting/api/libs/mission.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,9 +1055,9 @@ int sendMessage_sub(lua_State* L, const void* sender, int messageSource, int mes
10551055

10561056
ADE_FUNC(sendMessage,
10571057
l_Mission,
1058-
"string|ship sender, message message, [number delay=0.0, enumeration priority = MESSAGE_PRIORITY_NORMAL, boolean "
1058+
"string|ship sender, message message, [number delay=0.0, enumeration priority = MESSAGE_PRIORITY_NORMAL /* MESSAGE_PRIORITY_* */, boolean "
10591059
"fromCommand = false]",
1060-
"Sends a message from the given source or ship with the given priority, or optionally sends it from the "
1060+
"Sends a message from the given source or ship with the given MESSAGE_PRIORITY_* priority, or optionally sends it from the "
10611061
"mission's command source.<br>"
10621062
"If delay is specified, the message will be delayed by the specified time in seconds.<br>"
10631063
"If sender is <i>nil</i> the message will not have a sender. If sender is a ship object the message will be sent from the ship; "
@@ -1266,10 +1266,10 @@ int getBuiltinMessageType(const enum_h* enumValue)
12661266

12671267
ADE_FUNC(sendBuiltinMessage,
12681268
l_Mission,
1269-
"ship sender, ship subject, enumeration|string type_or_type_name",
1269+
"ship sender, ship subject, enumeration|string type_or_type_name /* BUILTIN_MESSAGE_* */",
12701270
"Sends one of the builtin messages from the given source or ship, taking the message subject into account."
12711271
"The subject can be nil or it can be the target of the message like a response to a destroy order."
1272-
"The type must be one of the BUILTIN_MESSAGE enumerations or a string matching a custom built-in message defined in messages.tbl.",
1272+
"The type must be one of the BUILTIN_MESSAGE_* enumerations or a string matching a custom built-in message defined in messages.tbl.",
12731273
"boolean",
12741274
"true if successful, false otherwise")
12751275
{
@@ -1323,9 +1323,9 @@ ADE_FUNC(sendBuiltinMessage,
13231323

13241324
ADE_FUNC(addMessageToScrollback,
13251325
l_Mission,
1326-
"string message, [team|enumeration source=HUD_SOURCE_COMPUTER]",
1326+
"string message, [team|enumeration source = SCROLLBACK_SOURCE_COMPUTER /* SCROLLBACK_* */]",
13271327
"Adds a string to the message log scrollback without sending it as a message first. Source should be either the team handle "
1328-
"or one of the SCROLLBACK_SOURCE enumerations.",
1328+
"or one of the SCROLLBACK_* enumerations.",
13291329
"boolean",
13301330
"true if successful, false otherwise")
13311331
{
@@ -1894,8 +1894,8 @@ ADE_FUNC(getMissionFilename, l_Mission, NULL, "Gets mission filename", "string",
18941894

18951895
ADE_FUNC(startMission,
18961896
l_Mission,
1897-
"string|enumeration mission /* Filename or MISSION_* enumeration */, [boolean Briefing = true]",
1898-
"Starts the defined mission",
1897+
"string|enumeration mission /* MISSION_* */, [boolean Briefing = true]",
1898+
"Starts the defined mission. Pass a filename string or a MISSION_* enumeration.",
18991899
"boolean",
19001900
"True, or false if the function fails")
19011901
{
@@ -2707,7 +2707,7 @@ ADE_FUNC(hasDebriefing,
27072707
return ade_set_args(L, "b", !(The_mission.flags[Mission::Mission_Flags::Toggle_debriefing]));
27082708
}
27092709
2710-
ADE_FUNC(getMusicScore, l_Mission, "enumeration score", "Returns the music.tbl entry name for the specified mission music score", "string", "The name, or nil if the score is invalid")
2710+
ADE_FUNC(getMusicScore, l_Mission, "enumeration score /* SCORE_* */", "Returns the music.tbl entry name for the specified mission music score", "string", "The name, or nil if the score is invalid")
27112711
{
27122712
enum_h score;
27132713
if (!ade_get_args(L, "o", l_Enum.Get(&score)))
@@ -2728,7 +2728,7 @@ ADE_FUNC(getMusicScore, l_Mission, "enumeration score", "Returns the music.tbl e
27282728
return ade_set_args(L, "s", name);
27292729
}
27302730
2731-
ADE_FUNC(setMusicScore, l_Mission, "enumeration score, string name", "Sets the music.tbl entry for the specified mission music score", nullptr, nullptr)
2731+
ADE_FUNC(setMusicScore, l_Mission, "enumeration score /* SCORE_* */, string name", "Sets the music.tbl entry for the specified mission music score", nullptr, nullptr)
27322732
{
27332733
enum_h score;
27342734
const char *name;

code/scripting/api/libs/testing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ADE_LIB(l_Testing, "Testing", "ts", "Experimental or testing stuff");
3333

3434
ADE_FUNC(openAudioStreamMem,
3535
l_Testing,
36-
"string snddata, enumeration stream_type /* AUDIOSTREAM_* values */",
36+
"string snddata, enumeration stream_type /* AUDIOSTREAM_* */",
3737
"Opens an audio stream of the specified in-memory file contents and type.",
3838
"audio_stream",
3939
"A handle to the opened stream or invalid on error")

code/scripting/api/libs/ui.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ ADE_FUNC(playElementSound,
237237
return ade_set_args(L, "b", scpui::SoundPlugin::instance()->PlayElementSound(el, event, state));
238238
}
239239

240-
ADE_FUNC(maybePlayCutscene, l_UserInterface, "enumeration MovieType, boolean RestartMusic, number ScoreIndex", "Plays a cutscene, if one exists, for the appropriate state transition. If RestartMusic is true, then the music score at ScoreIndex will be started after the cutscene plays.", nullptr, "Returns nothing")
240+
ADE_FUNC(maybePlayCutscene, l_UserInterface, "enumeration MovieType /* MOVIE_* */, boolean RestartMusic, number ScoreIndex", "Plays a cutscene, if one exists, for the appropriate state transition. If RestartMusic is true, then the music score at ScoreIndex will be started after the cutscene plays.", nullptr, "Returns nothing")
241241
{
242242
enum_h movie_type;
243243
bool restart_music = false;
@@ -821,9 +821,9 @@ ADE_FUNC(skipTraining,
821821
ADE_FUNC(commitToMission,
822822
l_UserInterface_Brief,
823823
nullptr,
824-
"Commits to the current mission with current loadout data, and starts the mission. Returns one of the COMMIT_ enums to indicate any errors.",
824+
"Commits to the current mission with current loadout data, and starts the mission.",
825825
"enumeration",
826-
"the error value")
826+
"A COMMIT_* enumeration indicating any errors")
827827
{
828828
commit_pressed_status rc;
829829

@@ -3447,8 +3447,8 @@ ADE_FUNC(setName,
34473447

34483448
ADE_FUNC(setGameType,
34493449
l_UserInterface_MultiStartGame,
3450-
"enumeration type=MULTI_GAME_TYPE_OPEN, [string | number password_or_rank_index]",
3451-
"Sets the game's type and, optionally, the password or rank index.",
3450+
"enumeration type = MULTI_GAME_TYPE_OPEN /* MULTI_GAME_TYPE_* */, [string | number password_or_rank_index]",
3451+
"Sets the game type and optionally the password or rank index.",
34523452
"boolean",
34533453
"True if successful, false otherwise")
34543454
{

0 commit comments

Comments
 (0)