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
+4
View File
@@ -1,5 +1,7 @@
Default arguments
DOC_MSE_VERSION: since 0.3.7
It is possible to declare default arguments for functions using the @@@@ operator.
> function := { "argument was: " + arg }@(arg:"default")
If this function is called without the @arg@ argument, then the default value @"default"@ is used instead.
@@ -19,6 +21,8 @@ Defaults are evaluated at the time the @@@@ operator is evaluated, they will not
--Rule functions--
DOC_MSE_VERSION: until 0.3.6
In earlier versions of MSE some functions were available in a special ''rule form''.
A call to for example @replace_rule(match:"abc",replace:"xyz")@ is equivalent to @replace@@(match:"abc",replace:"xyz")@ .
For backwards compatability these functions are still available, but they should not be used for new templates.
+1
View File
@@ -16,6 +16,7 @@ See also:
* [[fun:index|Built in functions]]
--Syntax index--
| @#comment@ Comments ignored by the parser
| @123@ [[type:int|A literal number]]
| @"stuff"@ [[type:string|A literal string]]
| @[a,b,c]@ [[type:list|A literal list]]
+2
View File
@@ -22,3 +22,5 @@ The operators @or@, @and@ and @xor@ combine two booleans:
| @true@ @false@ @true@ @false@ @true@
| @true@ @true@ @true@ @true@ @false@
--See also--
| [[fun:to_boolean]] Convert a value to a boolean
+3
View File
@@ -27,3 +27,6 @@ For example:
| @rgba(0,0,0,0)@ transparent <div style="border:1px solid black; width:30px;height:15px;text-align:center;">over</div>
| @rgba(255,0,0,128)@ transparent red <div style="border:1px solid black; background:rgb(255,128,128);color:rgb(128,0,0);width:30px;height:15px;text-align:center;">over</div>
| @rgba(0,0,255,192)@ transparent blue <div style="border:1px solid black; background:rgb(64,64,255);color:rgb(0,0,192);width:30px;height:15px;text-align:center;">over</div>
--See also--
| [[fun:to_color]] Convert any value to a color
+2 -1
View File
@@ -12,4 +12,5 @@ Conversion from integer to real numbers happens automatically in scripting.
> 123.1 + 456 * -1
--See also--
* [[type:int]]
| [[type:int]] Integer numbers
| [[fun:to_real]] Convert a value to a real number
+2 -1
View File
@@ -10,4 +10,5 @@ In many cases negative numbers don't make sense, but the program never complains
> 123 + 456 * -1
--See also--
* [[type:double]]
| [[type:double]] Number type that can contain fractional values.
| [[fun:to_int]] Convert a value to an integer number
+9 -2
View File
@@ -25,10 +25,17 @@ Sections between curly braces are interpreted as script code, that is concatenta
> "ab{1 + 1}c" == "ab2c"
This can be nested arbitrarily.
The @+@ operator concatenates strings. Numbers and most other values are automatically converted to strings when needed.
The @+@ operator concatenates strings. Numbers and most other values are automatically converted to strings when needed. This conversion can be forced with the [[fun:to_string]] function.
Using the @[]@ or @.@ operator characters in a string can be selected. 0 is the first character:
> "xyz"[0] == "x"
> "xyz".0 == "x" # same thing
> "xyz".1 == "y"
> "xyz".2 == "z"
It is an error to select characters outside the string
> "xyz".10 # error
> "xyz".10 # error
--See also--
| [[type:tagged string]] A string containg tags.
| [[fun:to_string]] Convert any value to a [[type:string]]