diff --git a/doc/function/index.txt b/doc/function/index.txt index b2050f88..345c2e46 100644 --- a/doc/function/index.txt +++ b/doc/function/index.txt @@ -11,6 +11,7 @@ These functions are built into the program, other [[type:function]]s can be defi | [[fun:to_color]] Convert any value to a [[type:color]] | [[fun:to_image]] Convert any value to an [[type:image]] | [[fun:to_date]] Convert any value to a [[type:date]] +| [[fun:type_name]] Get the type of a value ! Numbers <<< | [[fun:abs]] Absolute value diff --git a/doc/function/type_name.txt b/doc/function/type_name.txt new file mode 100644 index 00000000..c42cdda6 --- /dev/null +++ b/doc/function/type_name.txt @@ -0,0 +1,17 @@ +Function: type_name + +DOC_MSE_VERSION: since 2.0.2 + +--Usage-- +> type_name(any_value) + +Return the type of the given value as a string. +Note that type names are localized, so they should not be compared to a fixed string. + +--Parameters-- +! Parameter Type Description +| @input@ ''any type'' Value to determine the type of. + +--Examples-- +> type_name("hello") == "string" +> type_name(1) == "integer number" diff --git a/src/script/functions/basic.cpp b/src/script/functions/basic.cpp index dc0578fd..8310d69f 100644 --- a/src/script/functions/basic.cpp +++ b/src/script/functions/basic.cpp @@ -220,6 +220,11 @@ SCRIPT_FUNCTION(to_code) { SCRIPT_RETURN(input->toCode()); } +SCRIPT_FUNCTION(type_name) { + SCRIPT_PARAM_C(ScriptValueP, input); + SCRIPT_RETURN(input->typeName()); +} + // ----------------------------------------------------------------------------- : Math SCRIPT_FUNCTION(abs) { @@ -718,6 +723,7 @@ void init_script_basic_functions(Context& ctx) { ctx.setVariable(_("to color"), script_to_color); ctx.setVariable(_("to date"), script_to_date); ctx.setVariable(_("to code"), script_to_code); + ctx.setVariable(_("type name"), script_type_name); // math ctx.setVariable(_("abs"), script_abs); ctx.setVariable(_("random real"), script_random_real);