Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add script-eval-bool #3755

Merged
merged 1 commit into from Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions code/parse/sexp.cpp
Expand Up @@ -319,6 +319,7 @@ SCP_vector<sexp_oper> Operators = {
{ "string-get-length", OP_STRING_GET_LENGTH, 1, 1, SEXP_INTEGER_OPERATOR, }, // Goober5000

//Other Sub-Category
{ "script-eval-bool", OP_SCRIPT_EVAL_BOOL, 1, 1, SEXP_BOOLEAN_OPERATOR, },
{ "script-eval-num", OP_SCRIPT_EVAL_NUM, 1, 1, SEXP_INTEGER_OPERATOR, },
{ "script-eval-string", OP_SCRIPT_EVAL_STRING, 2, 2, SEXP_ACTION_OPERATOR, },

Expand Down Expand Up @@ -23008,6 +23009,17 @@ int sexp_script_eval(int node, int return_type, bool concat_args = false)

switch(return_type)
{
case OPR_BOOL:
{
auto s = CTEXT(n);
bool r = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While these variable names could be more descriptive, I see they're what's used elsewhere in this function.

bool success = Script_system.EvalStringWithReturn(s, "|b", &r);

if(!success)
Warning(LOCATION, "sexp-script-eval failed to evaluate string \"%s\"; check your syntax", s);

return r ? SEXP_TRUE : SEXP_FALSE;
}
case OPR_NUMBER:
{
auto s = CTEXT(n);
Expand Down Expand Up @@ -25907,6 +25919,10 @@ int eval_sexp(int cur_node, int referenced_node)
sexp_val = SEXP_TRUE;
break;

case OP_SCRIPT_EVAL_BOOL:
sexp_val = sexp_script_eval(node, OPR_BOOL);
break;

case OP_SCRIPT_EVAL_NUM:
sexp_val = sexp_script_eval(node, OPR_NUMBER);
break;
Expand Down Expand Up @@ -26708,6 +26724,7 @@ int query_operator_return_type(int op)
case OP_IS_IN_TURRET_FOV:
case OP_IS_LANGUAGE:
case OP_FUNCTIONAL_WHEN:
case OP_SCRIPT_EVAL_BOOL:
return OPR_BOOL;

case OP_PLUS:
Expand Down Expand Up @@ -29453,6 +29470,7 @@ int query_operator_argument_type(int op, int argnum)
case OP_NEBULA_CHANGE_FOG_COLOR:
return OPF_POSITIVE;

case OP_SCRIPT_EVAL_BOOL:
case OP_SCRIPT_EVAL_NUM:
case OP_SCRIPT_EVAL_BLOCK:
case OP_SCRIPT_EVAL:
Expand Down Expand Up @@ -31368,6 +31386,7 @@ int get_subcategory(int sexp_id)
case OP_STRING_GET_LENGTH:
return STATUS_SUBCATEGORY_VARIABLES;

case OP_SCRIPT_EVAL_BOOL:
case OP_SCRIPT_EVAL_NUM:
return STATUS_SUBCATEGORY_OTHER;

Expand Down Expand Up @@ -35272,6 +35291,12 @@ SCP_vector<sexp_help_struct> Sexp_help = {
"\t3:\tBlue (0 - 255)\r\n"
},

{OP_SCRIPT_EVAL_BOOL, "script-eval-bool\r\n"
"\tEvaluates script to return a boolean"
"Takes 1 argument...\r\n"
"\t1:\tScript\r\n"
},

{OP_SCRIPT_EVAL_NUM, "script-eval-num\r\n"
"\tEvaluates script to return a number"
"Takes 1 argument...\r\n"
Expand Down
1 change: 1 addition & 0 deletions code/parse/sexp.h
Expand Up @@ -402,6 +402,7 @@ class waypoint_list;
#define OP_DISTANCE_BBOX (0x0055 | OP_CATEGORY_STATUS | OP_NONCAMPAIGN_FLAG) // Goober5000
#define OP_DISTANCE_BBOX_SUBSYSTEM (0x0056 | OP_CATEGORY_STATUS | OP_NONCAMPAIGN_FLAG) // Goober5000
#define OP_IS_LANGUAGE (0x0057 | OP_CATEGORY_STATUS) // Goober5000
#define OP_SCRIPT_EVAL_BOOL (0x0058 | OP_CATEGORY_STATUS | OP_NONCAMPAIGN_FLAG) // Goober5000

// conditional sexpressions
#define OP_WHEN (0x0000 | OP_CATEGORY_CONDITIONAL)
Expand Down