Skip to content

Commit db1fd0e

Browse files
committed
Accept wider range of options for boolean for SetXXXOption
1 parent c7989ba commit db1fd0e

File tree

3 files changed

+50
-10
lines changed

3 files changed

+50
-10
lines changed

ProcessPreviousLine.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,9 +1349,7 @@ POSITION pos;
13491349
if (!trigger_item->strProcedure.IsEmpty ()) // if we have a script routine
13501350
triggerList.AddTail (trigger_item);
13511351

1352-
if (!trigger_item->bKeepEvaluating
1353-
// -- removed in version 3.73 || trigger_item->bMultiLine
1354-
) // exit loop if no more evaluation wanted
1352+
if (!trigger_item->bKeepEvaluating) // exit loop if no more evaluation wanted
13551353
break;
13561354

13571355
} // end of successful evaluation

scripting/lua_methods.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,18 @@ LUALIB_API lua_Number my_optnumber (lua_State *L, int narg, lua_Number def) {
286286
return luaL_opt(L, my_checknumber, narg, def);
287287
}
288288

289+
LUALIB_API const char *get_option_value (lua_State *L, int narg) {
290+
291+
// if boolean convert to 0 or 1
292+
if (lua_isboolean (L, narg))
293+
return (lua_toboolean (L, narg) ? "1" : "0");
294+
295+
const char *s = lua_tolstring(L, narg, NULL);
296+
if (!s)
297+
my_tag_error(L, narg, LUA_TSTRING);
298+
return s;
299+
}
300+
289301
#define my_checkstring(L,n) (my_checklstring(L, (n), NULL))
290302
#define my_optstring(L,n,d) (my_optlstring(L, (n), (d), NULL))
291303

@@ -4705,7 +4717,7 @@ static int L_SetAliasOption (lua_State *L)
47054717
lua_pushnumber (L, pDoc->SetAliasOption (
47064718
my_checkstring (L, 1), // AliasName
47074719
my_checkstring (L, 2), // OptionName
4708-
my_checkstring (L, 3) // Value
4720+
get_option_value (L, 3) // Value
47094721
));
47104722
return 1; // number of result fields
47114723
} // end of L_SetAliasOption
@@ -4927,9 +4939,9 @@ static int L_SetTimerOption (lua_State *L)
49274939
{
49284940
CMUSHclientDoc *pDoc = doc (L);
49294941
lua_pushnumber (L, pDoc->SetTimerOption (
4930-
my_checkstring (L, 1), // AliasName
4942+
my_checkstring (L, 1), // TimerName
49314943
my_checkstring (L, 2), // OptionName
4932-
my_checkstring (L, 3) // Value
4944+
get_option_value (L, 3) // Value
49334945
));
49344946
return 1; // number of result fields
49354947
} // end of L_SetTimerOption
@@ -4942,7 +4954,7 @@ static int L_SetToolBarPosition (lua_State *L)
49424954
CMUSHclientDoc *pDoc = doc (L);
49434955
lua_pushnumber (L, pDoc->SetToolBarPosition (
49444956
my_checknumber (L, 1), // Which
4945-
optboolean (L, 2, 0), // Float
4957+
optboolean (L, 2, 0), // Float
49464958
my_checknumber (L, 3), // Side
49474959
my_checknumber (L, 4), // Top
49484960
my_checknumber (L, 5) // Left
@@ -4957,9 +4969,9 @@ static int L_SetTriggerOption (lua_State *L)
49574969
{
49584970
CMUSHclientDoc *pDoc = doc (L);
49594971
lua_pushnumber (L, pDoc->SetTriggerOption (
4960-
my_checkstring (L, 1), // AliasName
4972+
my_checkstring (L, 1), // TriggerName
49614973
my_checkstring (L, 2), // OptionName
4962-
my_checkstring (L, 3) // Value
4974+
get_option_value (L, 3) // Value
49634975
));
49644976
return 1; // number of result fields
49654977
} // end of L_SetTriggerOption

scripting/methods.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6283,6 +6283,16 @@ bool bChanged;
62836283
{
62846284
// this is a numeric option
62856285

6286+
// for boolean options, accept "y" or "n"
6287+
if (TriggerOptionsTable [iItem].iMinimum == 0 &&
6288+
TriggerOptionsTable [iItem].iMaximum == 0)
6289+
{
6290+
if (strValue == "Y" || strValue == "y")
6291+
Value = "1";
6292+
else if (strValue == "N" || strValue == "n")
6293+
Value = "0";
6294+
}
6295+
62866296
if (!IsNumber (Value, true))
62876297
return eOptionOutOfRange;
62886298

@@ -6550,7 +6560,17 @@ bool bChanged;
65506560
if (iResult == eOK)
65516561
{
65526562
// this is a numeric option
6553-
6563+
6564+
// for boolean options, accept "y" or "n"
6565+
if (AliasOptionsTable [iItem].iMinimum == 0 &&
6566+
AliasOptionsTable [iItem].iMaximum == 0)
6567+
{
6568+
if (strValue == "Y" || strValue == "y")
6569+
Value = "1";
6570+
else if (strValue == "N" || strValue == "n")
6571+
Value = "0";
6572+
}
6573+
65546574
if (!IsNumber (Value, true))
65556575
return eOptionOutOfRange;
65566576

@@ -6849,6 +6869,16 @@ bool bChanged;
68496869
{
68506870
// this is a numeric option
68516871

6872+
// for boolean options, accept "y" or "n"
6873+
if (TimerOptionsTable [iItem].iMinimum == 0 &&
6874+
TimerOptionsTable [iItem].iMaximum == 0)
6875+
{
6876+
if (strValue == "Y" || strValue == "y")
6877+
Value = "1";
6878+
else if (strValue == "N" || strValue == "n")
6879+
Value = "0";
6880+
}
6881+
68526882
long iValue = 0;
68536883
double fValue = 0;
68546884

0 commit comments

Comments
 (0)