Commit bf2b2a2d authored by twanvl's avatar twanvl

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

Documented both of them
parent 868a9c95
......@@ -16,3 +16,7 @@ Note: @assert@ is a special built-in keyword, so that the error message can incl
--Examples--
> assert(1 + 1 == 2) # nothing happens
> assert(1 * 1 == 2) # An error message is shown
--See also--
| [[fun:warning]] Output a warning message.
| [[fun:error]] Output an error message.
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.
......@@ -109,3 +109,5 @@ These functions are built into the program, other [[type:function]]s can be defi
! Other functions <<<
| [[fun:trace]] Output a message for debugging purposes.
| [[fun:assert]] Check a condition for debugging purposes.
| [[fun:warning]] Output a warning message.
| [[fun:error]] Output an error message.
......@@ -10,4 +10,8 @@ Output a message for debugging purposes, for example to investigate what is goin
| @input@ [[type:string]] Message
--Examples--
> trace("message") == "message" # the message is reported in a message box
> trace("message") == "message" # the message is shown in the console panel
--See also--
| [[fun:warning]] Output a warning message.
| [[fun:error]] Output an error message.
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.
......@@ -56,6 +56,15 @@ SCRIPT_FUNCTION(warning_if_neq) {
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
/// Format the input variable based on a printf like style specification
......@@ -709,6 +718,8 @@ SCRIPT_FUNCTION(rule) {
void init_script_basic_functions(Context& ctx) {
// debugging
ctx.setVariable(_("trace"), script_trace);
ctx.setVariable(_("warning"), script_warning);
ctx.setVariable(_("error"), script_error);
// conversion
ctx.setVariable(_("to_string"), script_to_string);
ctx.setVariable(_("to_int"), script_to_int);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment