Be more strict about type conversion:

* numbers are no longer auto converted to booleans, use to_boolean or != 0
  * booleans are no longer auto converted to numbers, use to_int
  * strings will soon no longer be auto converted to numbers, use to_int

Added version information ("since 0.3.7") to documentation

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1006 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-06-28 13:34:57 +00:00
parent ba2665eb49
commit fe2e3fb9c8
29 changed files with 693 additions and 33 deletions
+4 -2
View File
@@ -1,5 +1,7 @@
Function: assert
DOC_MSE_VERSION: since 0.3.7
--Usage--
> assert(condition)
@@ -12,5 +14,5 @@ Note: @assert@ is a special built-in keyword, so that the error message can incl
| @input@ [[type:boolean]] Condition to check.
--Examples--
> assert(1 + 1 == 2) == nil # nothing happens
> assert(1 * 1 == 2) == nil # An error message is shown
> assert(1 + 1 == 2) # nothing happens
> assert(1 * 1 == 2) # An error message is shown
+7
View File
@@ -2,6 +2,13 @@ Script functions by category
These functions are built into the program, other [[type:function]]s can be defined using the scripting language.
! Type conversion <<<
| [[fun:to_string]] Convert any value to a [[type:string]]
| [[fun:to_int]] Convert any value to a [[type:int]]
| [[fun:to_real]] Convert any value to a [[type:double]]
| [[fun:to_boolean]] Convert any value to a [[type:boolean]]
| [[fun:to_color]] Convert any value to a [[type:color]]
! Text manipulation <<<
| [[fun:to_upper]] Convert a string to upper case, @"aBc" -> "ABC"@.
| [[fun:to_lower]] Convert a string to lower case, @"aBc" -> "abc"@.
+20
View File
@@ -0,0 +1,20 @@
Function: to_boolean
DOC_MSE_VERSION: since 0.3.7
--Usage--
> to_boolean(any value)
Convert any value to a [[type:boolean]] representation.
Normally numbers are not converted to booleans automatically, with the to_boolean function @0@ is converted to @false@ while any other number is converted to @true@.
--Parameters--
! Parameter Type Description
| @input@ ''any type'' Value to convert to a boolean.
--Examples--
> to_boolean(true) == true
> to_boolean("true") == true
> to_boolean(1) == true
> to_boolean(0) == false
+16
View File
@@ -0,0 +1,16 @@
Function: to_color
DOC_MSE_VERSION: since 0.3.7
--Usage--
> to_color(any value)
Convert any value to a [[type:color]].
--Parameters--
! Parameter Type Description
| @input@ ''any type'' Value to convert to a color
--Examples--
> to_color("red") == rgb(255,0,0)
+24
View File
@@ -0,0 +1,24 @@
Function: to_int
DOC_MSE_VERSION: since 0.3.7
--Usage--
> to_int(any value)
Convert any value to a [[type:int]].
* Real numbers are rounded towards zero when converted to integer numbers.
* The boolean value @true@ becomes @1@, while @false@ is converted to @0@.
* For colors the grayscale value between @0@ and @255@ is returned.
--Parameters--
! Parameter Type Description
| @input@ ''any type'' Value to convert to an integer number
--Examples--
> to_int(1.5) == "1"
> to_int("15") == "15"
> to_int(true) == 1
--See also--
| [[fun:to_real]] Convert any value to a [[type:double]]
+20
View File
@@ -0,0 +1,20 @@
Function: to_real
DOC_MSE_VERSION: since 0.3.7
--Usage--
> to_real(any value)
Convert any value to a [[type:double]].
--Parameters--
! Parameter Type Description
| @input@ ''any type'' Value to convert to a real number
--Examples--
> to_real(1) == 1.0
> to_real("1.5") == "1.5"
--See also--
| [[fun:to_int]] Convert any value to a [[type:int]]
+24
View File
@@ -0,0 +1,24 @@
Function: to_string
DOC_MSE_VERSION: since 0.3.7
--Usage--
> to_string(any value)
Convert any value to a [[type:string]] representation.
The @to_string@ function should not be confused with @to_text@,
the former converts things like number to string, while the latter removes tags from a [[type:tagged string]].
--Parameters--
! Parameter Type Description
| @input@ ''any type'' Value to convert to a string
| @format@ ''optional'' Formating to apply.
--Examples--
> to_string(to_color("blue")) == "rgb(0,0,255)"
> to_string(10 + 20) == "30"
> to_string(10 + 20, format: ".3f") == "30.000"
> to_string(10 + 20, format: "x") == "1e" # hexadecimal notation