Files
fs2open.github.com/code/scripting/api/objs/fictionviewer.cpp
T
wookieejedi 650ae9a074 Some extra safety checks for fiction viewer scripts (#4598)
Protects `Fiction_viewer_active_stage` if it reads a stage of -1 (it would have thrown a vector access error because the index is out of range). Also, given a lot of other scripting functions have additional built in error checks, I just added those to the fiction viewer functions.
2022-08-28 09:11:57 -04:00

64 lines
1.6 KiB
C++

#include "fictionviewer.h"
namespace scripting {
namespace api {
//**********HANDLE: cmd_briefing
ADE_OBJ(l_FictionViewerStage, fiction_viewer_stage, "fiction_viewer_stage", "Fiction Viewer stage handle");
ADE_VIRTVAR(TextFile, l_FictionViewerStage, nullptr, "The text file of the stage", "fiction_viewer_stage", "The text filename")
{
fiction_viewer_stage* stage = nullptr;
if (!ade_get_args(L, "o", l_FictionViewerStage.GetPtr(&stage))) {
return ADE_RETURN_NIL;
}
if (stage == nullptr) {
return ADE_RETURN_NIL;
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "s", stage->story_filename);
}
ADE_VIRTVAR(FontFile, l_FictionViewerStage, nullptr, "The font file of the stage", "fiction_viewer_stage", "The font filename")
{
fiction_viewer_stage* stage = nullptr;
if (!ade_get_args(L, "o", l_FictionViewerStage.GetPtr(&stage))) {
return ADE_RETURN_NIL;
}
if (stage == nullptr) {
return ADE_RETURN_NIL;
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "s", stage->font_filename);
}
ADE_VIRTVAR(VoiceFile, l_FictionViewerStage, nullptr, "The voice file of the stage", "fiction_viewer_stage", "The voice filename")
{
fiction_viewer_stage* stage = nullptr;
if (!ade_get_args(L, "o", l_FictionViewerStage.GetPtr(&stage))) {
return ADE_RETURN_NIL;
}
if (stage == nullptr) {
return ADE_RETURN_NIL;
}
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "s", stage->voice_filename);
}
} // namespace api
} // namespace scripting