Skip to content

Commit

Permalink
Accept true/false for SetOption, SetChatOption
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Jul 10, 2010
1 parent db1fd0e commit a6f49a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 10 additions & 2 deletions scripting/lua_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4770,7 +4770,7 @@ static int L_SetChatOption (lua_State *L)
lua_pushnumber (L, pDoc->SetChatOption (
my_checknumber (L, 1), // Chat ID
my_checkstring (L, 2), // OptionName
my_checkstring (L, 3) // Value
get_option_value (L, 3) // Value
));
return 1; // number of result fields
} // end of L_SetChatOption
Expand Down Expand Up @@ -4899,9 +4899,17 @@ static int L_SetNotes (lua_State *L)
static int L_SetOption (lua_State *L)
{
CMUSHclientDoc *pDoc = doc (L);
lua_Number option;

// if boolean convert to 0 or 1
if (lua_isboolean (L, 2))
option = lua_toboolean (L, 2) ? 1 : 0;
else
option = my_checknumber (L, 2);

lua_pushnumber (L, pDoc->SetOption (
my_checkstring (L, 1), // OptionName
my_checknumber (L, 2) // Value
option // Value
));
return 1; // number of result fields
} // end of L_SetOption
Expand Down
10 changes: 10 additions & 0 deletions scripting/methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8436,6 +8436,16 @@ bool bChanged;
{
// this is a numeric option

// for boolean options, accept "y" or "n"
if (ChatOptionsTable [iItem].iMinimum == 0 &&
ChatOptionsTable [iItem].iMaximum == 0)
{
if (strValue == "Y" || strValue == "y")
Value = "1";
else if (strValue == "N" || strValue == "n")
Value = "0";
}

if (!IsNumber (Value, true))
return eOptionOutOfRange;

Expand Down

0 comments on commit a6f49a1

Please sign in to comment.