Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
9354ddf9
Commit
9354ddf9
authored
Jul 09, 2008
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow "or else" construct to be used for error recovery
parent
5aae5075
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
22 deletions
+65
-22
doc/function/to_int.txt
doc/function/to_int.txt
+4
-0
doc/function/to_number.txt
doc/function/to_number.txt
+4
-0
doc/function/to_real.txt
doc/function/to_real.txt
+4
-0
src/script/functions/basic.cpp
src/script/functions/basic.cpp
+45
-21
tools/website/drupal/mse-drupal-modules/highlight.inc
tools/website/drupal/mse-drupal-modules/highlight.inc
+8
-1
No files found.
doc/function/to_int.txt
View file @
9354ddf9
...
@@ -21,6 +21,10 @@ Convert any value to a [[type:int]].
...
@@ -21,6 +21,10 @@ Convert any value to a [[type:int]].
> to_int(true) == 1
> to_int(true) == 1
> to_int(rgb(255,255,255)) == 255
> to_int(rgb(255,255,255)) == 255
Use @or else@ to recover from errors:
> to_number("not a number") or else 0 == 0
> to_number("123") or else 0 == 123
--See also--
--See also--
| [[fun:to_real]] Convert any value to a [[type:double]]
| [[fun:to_real]] Convert any value to a [[type:double]]
| [[fun:to_number]] Convert any value to a number
| [[fun:to_number]] Convert any value to a number
doc/function/to_number.txt
View file @
9354ddf9
...
@@ -20,6 +20,10 @@ Otherwise it is converted to a [[type:double]].
...
@@ -20,6 +20,10 @@ Otherwise it is converted to a [[type:double]].
> to_number("1") == 1
> to_number("1") == 1
> to_number("1.5") == 1.5
> to_number("1.5") == 1.5
Use @or else@ to recover from errors:
> to_number("not a number") or else 0 == 0
> to_number("123") or else 0 == 123
--See also--
--See also--
| [[fun:to_int]] Convert any value to a [[type:int]]
| [[fun:to_int]] Convert any value to a [[type:int]]
| [[fun:to_real]] Convert any value to a [[type:double]]
| [[fun:to_real]] Convert any value to a [[type:double]]
doc/function/to_real.txt
View file @
9354ddf9
...
@@ -16,6 +16,10 @@ Convert any value to a [[type:double]].
...
@@ -16,6 +16,10 @@ Convert any value to a [[type:double]].
> to_real(1) == 1.0
> to_real(1) == 1.0
> to_real("1.5") == 1.5
> to_real("1.5") == 1.5
Use @or else@ to recover from errors:
> to_number("not a number") or else 0.0 == 0.0
> to_number("123") or else 0.0 == 123.0
--See also--
--See also--
| [[fun:to_int]] Convert any value to a [[type:int]]
| [[fun:to_int]] Convert any value to a [[type:int]]
| [[fun:to_number]] Convert any value to a number
| [[fun:to_number]] Convert any value to a number
src/script/functions/basic.cpp
View file @
9354ddf9
...
@@ -72,21 +72,29 @@ SCRIPT_FUNCTION(to_string) {
...
@@ -72,21 +72,29 @@ SCRIPT_FUNCTION(to_string) {
SCRIPT_FUNCTION
(
to_int
)
{
SCRIPT_FUNCTION
(
to_int
)
{
ScriptValueP
input
=
ctx
.
getVariable
(
SCRIPT_VAR_input
);
ScriptValueP
input
=
ctx
.
getVariable
(
SCRIPT_VAR_input
);
ScriptType
t
=
input
->
type
();
ScriptType
t
=
input
->
type
();
int
result
;
try
{
if
(
t
==
SCRIPT_BOOL
)
{
int
result
;
result
=
(
bool
)
*
input
?
1
:
0
;
if
(
t
==
SCRIPT_BOOL
)
{
}
else
if
(
t
==
SCRIPT_COLOR
)
{
result
=
(
bool
)
*
input
?
1
:
0
;
AColor
c
=
(
AColor
)
*
input
;
}
else
if
(
t
==
SCRIPT_COLOR
)
{
result
=
(
c
.
Red
()
+
c
.
Blue
()
+
c
.
Green
())
/
3
;
AColor
c
=
(
AColor
)
*
input
;
}
else
{
result
=
(
c
.
Red
()
+
c
.
Blue
()
+
c
.
Green
())
/
3
;
result
=
(
int
)
*
input
;
}
else
{
result
=
(
int
)
*
input
;
}
SCRIPT_RETURN
(
result
);
}
catch
(
const
ScriptError
&
e
)
{
return
new_intrusive1
<
ScriptDelayedError
>
(
e
);
}
}
SCRIPT_RETURN
(
result
);
}
}
SCRIPT_FUNCTION
(
to_real
)
{
SCRIPT_FUNCTION
(
to_real
)
{
SCRIPT_PARAM_C
(
double
,
input
);
try
{
SCRIPT_RETURN
(
input
);
SCRIPT_PARAM_C
(
double
,
input
);
SCRIPT_RETURN
(
input
);
}
catch
(
const
ScriptError
&
e
)
{
return
new_intrusive1
<
ScriptDelayedError
>
(
e
);
}
}
}
SCRIPT_FUNCTION
(
to_number
)
{
SCRIPT_FUNCTION
(
to_number
)
{
...
@@ -100,25 +108,41 @@ SCRIPT_FUNCTION(to_number) {
...
@@ -100,25 +108,41 @@ SCRIPT_FUNCTION(to_number) {
}
else
if
(
t
==
SCRIPT_DOUBLE
)
{
}
else
if
(
t
==
SCRIPT_DOUBLE
)
{
SCRIPT_RETURN
((
double
)
*
input
);
SCRIPT_RETURN
((
double
)
*
input
);
}
else
{
}
else
{
SCRIPT_RETURN
((
int
)
*
input
);
String
s
=
input
->
toString
();
long
l
;
double
d
;
if
(
s
.
ToLong
(
&
l
))
{
SCRIPT_RETURN
((
int
)
l
);
}
else
if
(
s
.
ToDouble
(
&
d
))
{
SCRIPT_RETURN
((
double
)
d
);
}
else
{
return
delayError
(
_ERROR_2_
(
"can't convert"
,
input
->
typeName
(),
_TYPE_
(
"double"
)));
}
}
}
}
}
SCRIPT_FUNCTION
(
to_boolean
)
{
SCRIPT_FUNCTION
(
to_boolean
)
{
ScriptValueP
input
=
ctx
.
getVariable
(
SCRIPT_VAR_input
);
ScriptValueP
input
=
ctx
.
getVariable
(
SCRIPT_VAR_input
);
ScriptType
t
=
input
->
type
();
try
{
bool
result
;
ScriptType
t
=
input
->
type
();
if
(
t
==
SCRIPT_INT
)
{
bool
result
;
result
=
(
int
)
*
input
!=
0
;
if
(
t
==
SCRIPT_INT
)
{
}
else
{
result
=
(
int
)
*
input
!=
0
;
result
=
(
bool
)
*
input
;
}
else
{
result
=
(
bool
)
*
input
;
}
SCRIPT_RETURN
(
result
);
}
catch
(
const
ScriptError
&
e
)
{
return
new_intrusive1
<
ScriptDelayedError
>
(
e
);
}
}
SCRIPT_RETURN
(
result
);
}
}
SCRIPT_FUNCTION
(
to_color
)
{
SCRIPT_FUNCTION
(
to_color
)
{
SCRIPT_PARAM_C
(
AColor
,
input
);
try
{
SCRIPT_RETURN
(
input
);
SCRIPT_PARAM_C
(
AColor
,
input
);
SCRIPT_RETURN
(
input
);
}
catch
(
const
ScriptError
&
e
)
{
return
new_intrusive1
<
ScriptDelayedError
>
(
e
);
}
}
}
// ----------------------------------------------------------------------------- : Math
// ----------------------------------------------------------------------------- : Math
...
...
tools/website/drupal/mse-drupal-modules/highlight.inc
View file @
9354ddf9
...
@@ -8,8 +8,13 @@ $built_in_functions = array(
...
@@ -8,8 +8,13 @@ $built_in_functions = array(
'to_string'
=>
''
,
'to_string'
=>
''
,
'to_int'
=>
''
,
'to_int'
=>
''
,
'to_real'
=>
''
,
'to_real'
=>
''
,
'to_number'
=>
''
,
'to_boolean'
=>
''
,
'to_boolean'
=>
''
,
'to_color'
=>
''
,
'to_color'
=>
''
,
// numbers
'abs'
=>
''
,
'random_int'
=>
''
,
'random_real'
=>
''
,
// text
// text
'to_upper'
=>
''
,
'to_upper'
=>
''
,
'to_lower'
=>
''
,
'to_lower'
=>
''
,
...
@@ -36,6 +41,8 @@ $built_in_functions = array(
...
@@ -36,6 +41,8 @@ $built_in_functions = array(
'number_of_items'
=>
''
,
'number_of_items'
=>
''
,
'sort_list'
=>
''
,
'sort_list'
=>
''
,
'filter_list'
=>
''
,
'filter_list'
=>
''
,
'random_shuffle'
=>
''
,
'random_select'
=>
''
,
// keywords
// keywords
'expand_keywords'
=>
''
,
'expand_keywords_rule'
=>
'expand_keywords'
,
'expand_keywords'
=>
''
,
'expand_keywords_rule'
=>
'expand_keywords'
,
'keyword_usage'
=>
''
,
'keyword_usage'
=>
''
,
...
@@ -159,7 +166,7 @@ function highlight_script($code) {
...
@@ -159,7 +166,7 @@ function highlight_script($code) {
if
(
$matches
[
2
]
==
'{'
)
$string
.=
's'
;
if
(
$matches
[
2
]
==
'{'
)
$string
.=
's'
;
}
else
if
(
preg_match
(
"@^
\\
#.*@"
,
$code
,
$matches
))
{
}
else
if
(
preg_match
(
"@^
\\
#.*@"
,
$code
,
$matches
))
{
$ret
.=
"<span class='hl-comment'>"
.
$matches
[
0
]
.
"</span>"
;
$ret
.=
"<span class='hl-comment'>"
.
$matches
[
0
]
.
"</span>"
;
}
else
if
(
preg_match
(
"@^([-+*/=!.\@]|<|>)+|^:=@"
,
$code
,
$matches
))
{
}
else
if
(
preg_match
(
"@^([-+*/=!.\@
^
]|<|>)+|^:=@"
,
$code
,
$matches
))
{
$ret
.=
"<span class='hl-op'>"
.
$matches
[
0
]
.
"</span>"
;
$ret
.=
"<span class='hl-op'>"
.
$matches
[
0
]
.
"</span>"
;
}
else
if
(
preg_match
(
"@^([}]|[
\\
(
\\
)
\\
[
\\
]{,]+)@"
,
$code
,
$matches
))
{
}
else
if
(
preg_match
(
"@^([}]|[
\\
(
\\
)
\\
[
\\
]{,]+)@"
,
$code
,
$matches
))
{
$ret
.=
"<span class='hl-paren'>"
.
$matches
[
0
]
.
"</span>"
;
$ret
.=
"<span class='hl-paren'>"
.
$matches
[
0
]
.
"</span>"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment