Expose the 'warning' function, and added a similar 'error' function.

Add documentation.
This commit is contained in:
Twan van Laarhoven
2020-04-23 20:22:43 +02:00
parent e9456eea86
commit 8f8e2cea65
4 changed files with 55 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
Function: error
DOC_MSE_VERSION: since 2.0.1
--Usage--
> error(some_string)
Output an error message.
--Parameters--
! Parameter Type Description
| @input@ [[type:string]] Message
| @condition@ [[type:boolean]] (optional) Only show the message if this condition holds.
--Examples--
> error("message") # the message is shown in the console panel
> error("message", condition: false) # shows no message
--See also--
| [[fun:assert]] Check that the condition is @true@. Shows a warning message if it is not.
| [[fun:warning]] Output a warning message.
+2
View File
@@ -110,3 +110,5 @@ These functions are built into the program, other [[type:function]]s can be defi
! Other functions <<< ! Other functions <<<
| [[fun:trace]] Output a message for debugging purposes. | [[fun:trace]] Output a message for debugging purposes.
| [[fun:assert]] Check a condition for debugging purposes. | [[fun:assert]] Check a condition for debugging purposes.
| [[fun:warning]] Output a warning message.
| [[fun:error]] Output an error message.
+21
View File
@@ -0,0 +1,21 @@
Function: warning
DOC_MSE_VERSION: since 2.0.1
--Usage--
> warning(some_string)
Output a warning message.
--Parameters--
! Parameter Type Description
| @input@ [[type:string]] Message
| @condition@ [[type:boolean]] (optional) Only show the message if this condition holds.
--Examples--
> warning("message")" # the message is shown in the console panel
> warning("message", condition: false) # shows no message
--See also--
| [[fun:assert]] Check that the condition is @true@. Shows a warning message if it is not.
| [[fun:error]] Output an error message.
+11
View File
@@ -56,6 +56,15 @@ SCRIPT_FUNCTION(warning_if_neq) {
return script_nil; return script_nil;
} }
SCRIPT_FUNCTION(error) {
SCRIPT_PARAM_C(String, input);
SCRIPT_PARAM_DEFAULT_C(bool, condition, true);
if (condition) {
queue_message(MESSAGE_ERROR, input);
}
return script_nil;
}
// ----------------------------------------------------------------------------- : Conversion // ----------------------------------------------------------------------------- : Conversion
/// Format the input variable based on a printf like style specification /// Format the input variable based on a printf like style specification
@@ -714,6 +723,8 @@ SCRIPT_FUNCTION(rule) {
void init_script_basic_functions(Context& ctx) { void init_script_basic_functions(Context& ctx) {
// debugging // debugging
ctx.setVariable(_("trace"), script_trace); ctx.setVariable(_("trace"), script_trace);
ctx.setVariable(_("warning"), script_warning);
ctx.setVariable(_("error"), script_error);
// conversion // conversion
ctx.setVariable(_("to_string"), script_to_string); ctx.setVariable(_("to_string"), script_to_string);
ctx.setVariable(_("to_int"), script_to_int); ctx.setVariable(_("to_int"), script_to_int);