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
4017a911
Commit
4017a911
authored
Mar 24, 2011
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use toXXX() instead of operator XXX in ScriptValue.
This means that we are more explicit about type conversions.
parent
a754df74
Changes
19
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
165 additions
and
173 deletions
+165
-173
src/data/keyword.cpp
src/data/keyword.cpp
+8
-8
src/data/keyword.hpp
src/data/keyword.hpp
+5
-5
src/data/pack.cpp
src/data/pack.cpp
+1
-1
src/data/set.cpp
src/data/set.cpp
+3
-3
src/gui/control/card_list.cpp
src/gui/control/card_list.cpp
+1
-1
src/gui/html_export_window.cpp
src/gui/html_export_window.cpp
+1
-1
src/gui/set/console_panel.cpp
src/gui/set/console_panel.cpp
+1
-1
src/gui/value/choice.cpp
src/gui/value/choice.cpp
+1
-1
src/gui/value/color.cpp
src/gui/value/color.cpp
+1
-1
src/script/context.cpp
src/script/context.cpp
+40
-40
src/script/dependency.cpp
src/script/dependency.cpp
+5
-5
src/script/functions/basic.cpp
src/script/functions/basic.cpp
+19
-19
src/script/functions/construction.cpp
src/script/functions/construction.cpp
+1
-1
src/script/functions/regex.cpp
src/script/functions/regex.cpp
+1
-1
src/script/functions/spelling.cpp
src/script/functions/spelling.cpp
+2
-2
src/script/scriptable.cpp
src/script/scriptable.cpp
+9
-8
src/script/to_value.hpp
src/script/to_value.hpp
+18
-18
src/script/value.cpp
src/script/value.cpp
+40
-40
src/script/value.hpp
src/script/value.hpp
+8
-17
No files found.
src/data/keyword.cpp
View file @
4017a911
...
...
@@ -680,7 +680,7 @@ bool KeywordDatabase::tryExpand(const Keyword& kw,
ctx
.
setVariable
(
_
(
"used_placeholders"
),
to_script
(
used_placeholders
));
// Final check whether the keyword matches
if
(
match_condition
&&
(
bool
)
*
match_condition
->
eval
(
ctx
)
==
false
)
{
if
(
match_condition
&&
match_condition
->
eval
(
ctx
)
->
toBool
(
)
==
false
)
{
return
false
;
}
...
...
@@ -688,7 +688,7 @@ bool KeywordDatabase::tryExpand(const Keyword& kw,
bool
expand
=
expand_type
==
_
(
'1'
);
if
(
!
expand
&&
expand_type
!=
_
(
'0'
))
{
// default expand, determined by script
expand
=
expand_default
?
(
bool
)
*
expand_default
->
eval
(
ctx
)
:
true
;
expand
=
expand_default
?
expand_default
->
eval
(
ctx
)
->
toBool
(
)
:
true
;
expand_type
=
expand
?
_
(
'A'
)
:
_
(
'a'
);
}
...
...
@@ -726,7 +726,7 @@ bool KeywordDatabase::tryExpand(const Keyword& kw,
ScriptType
KeywordParamValue
::
type
()
const
{
return
SCRIPT_STRING
;
}
String
KeywordParamValue
::
typeName
()
const
{
return
_
(
"keyword parameter"
);
}
KeywordParamValue
::
operator
String
()
const
{
String
KeywordParamValue
::
to
String
()
const
{
String
safe_type
=
replace_all
(
replace_all
(
replace_all
(
type_name
,
_
(
"("
),
_
(
"-"
)),
_
(
")"
),
_
(
"-"
)),
...
...
@@ -734,10 +734,10 @@ KeywordParamValue::operator String() const {
return
_
(
"<param-"
)
+
safe_type
+
_
(
">"
)
+
value
+
_
(
"</param-"
)
+
safe_type
+
_
(
">"
);
}
KeywordParamValue
::
operator
int
()
const
{
return
*
to_script
(
value
);
}
// a bit of a hack
KeywordParamValue
::
operator
double
()
const
{
return
*
to_script
(
value
);
}
KeywordParamValue
::
operator
bool
()
const
{
return
*
to_script
(
value
);
}
KeywordParamValue
::
operator
AColor
()
const
{
return
*
to_script
(
value
);
}
int
KeywordParamValue
::
toInt
()
const
{
return
to_script
(
value
)
->
toInt
(
);
}
// a bit of a hack
double
KeywordParamValue
::
toDouble
()
const
{
return
to_script
(
value
)
->
toDouble
(
);
}
bool
KeywordParamValue
::
toBool
()
const
{
return
to_script
(
value
)
->
toBool
(
);
}
AColor
KeywordParamValue
::
toColor
()
const
{
return
to_script
(
value
)
->
toColor
(
);
}
int
KeywordParamValue
::
itemCount
()
const
{
return
to_script
(
value
)
->
itemCount
();
}
ScriptValueP
KeywordParamValue
::
getMember
(
const
String
&
name
)
const
{
...
...
src/data/keyword.hpp
View file @
4017a911
...
...
@@ -193,11 +193,11 @@ class KeywordParamValue : public ScriptValue {
virtual
ScriptType
type
()
const
;
virtual
String
typeName
()
const
;
virtual
operator
String
()
const
;
virtual
operator
i
nt
()
const
;
virtual
operator
b
ool
()
const
;
virtual
operator
d
ouble
()
const
;
virtual
operator
AColor
()
const
;
virtual
String
to
String
()
const
;
virtual
int
toI
nt
()
const
;
virtual
bool
toB
ool
()
const
;
virtual
double
toD
ouble
()
const
;
virtual
AColor
toColor
()
const
;
virtual
int
itemCount
()
const
;
virtual
ScriptValueP
getMember
(
const
String
&
name
)
const
;
};
...
...
src/data/pack.cpp
View file @
4017a911
...
...
@@ -116,7 +116,7 @@ PackInstance::PackInstance(const PackType& pack_type, PackGenerator& parent)
if
(
pack_type
.
filter
)
{
FOR_EACH
(
card
,
parent
.
set
->
cards
)
{
Context
&
ctx
=
parent
.
set
->
getContext
(
card
);
bool
keep
=
*
pack_type
.
filter
.
invoke
(
ctx
);
bool
keep
=
pack_type
.
filter
.
invoke
(
ctx
)
->
toBool
(
);
if
(
keep
)
{
cards
.
push_back
(
card
);
}
...
...
src/data/set.cpp
View file @
4017a911
...
...
@@ -270,9 +270,9 @@ int Set::positionOfCard(const CardP& card, const ScriptValueP& order_by, const S
vector
<
int
>
keep
;
if
(
filter
)
keep
.
reserve
(
cards
.
size
());
FOR_EACH_CONST
(
c
,
cards
)
{
Context
&
ctx
=
getContext
(
c
);
values
.
push_back
(
*
order_by
->
eval
(
ctx
));
values
.
push_back
(
order_by
->
eval
(
ctx
)
->
toString
(
));
if
(
filter
)
{
keep
.
push_back
(
(
bool
)
*
filter
->
eval
(
ctx
));
keep
.
push_back
(
filter
->
eval
(
ctx
)
->
toBool
(
));
}
}
#if USE_SCRIPT_PROFILING
...
...
@@ -292,7 +292,7 @@ int Set::numberOfCards(const ScriptValueP& filter) {
}
else
{
int
n
=
0
;
FOR_EACH_CONST
(
c
,
cards
)
{
if
(
*
filter
->
eval
(
getContext
(
c
)
))
++
n
;
if
(
filter
->
eval
(
getContext
(
c
))
->
toBool
(
))
++
n
;
}
filter_cache
.
insert
(
make_pair
(
filter
,
n
));
return
n
;
...
...
src/gui/control/card_list.cpp
View file @
4017a911
...
...
@@ -324,7 +324,7 @@ int CardListBase::OnGetItemImage(long pos) const {
wxListItemAttr
*
CardListBase
::
OnGetItemAttr
(
long
pos
)
const
{
if
(
!
set
->
game
->
card_list_color_script
)
return
nullptr
;
Context
&
ctx
=
set
->
getContext
(
getCard
(
pos
));
item_attr
.
SetTextColour
(
*
set
->
game
->
card_list_color_script
.
invoke
(
ctx
));
item_attr
.
SetTextColour
(
set
->
game
->
card_list_color_script
.
invoke
(
ctx
)
->
toColor
(
));
return
&
item_attr
;
}
...
...
src/gui/html_export_window.cpp
View file @
4017a911
...
...
@@ -83,7 +83,7 @@ ScriptValueP export_set(SetP const& set, vector<CardP> const& cards, ExportTempl
// write as string
wxFileOutputStream
file
(
outname
);
wxTextOutputStream
stream
(
file
);
stream
.
WriteString
(
*
result
);
stream
.
WriteString
(
result
->
toString
()
);
}
return
result
;
}
...
...
src/gui/set/console_panel.cpp
View file @
4017a911
...
...
@@ -412,7 +412,7 @@ void ConsolePanel::exec(String const& command) {
message
->
bitmap
=
wxBitmap
(
image
);
}
else
if
(
type
==
SCRIPT_COLOR
)
{
message
->
text
=
result
->
toCode
();
AColor
color
=
(
AColor
)
*
result
;
AColor
color
=
result
->
toColor
()
;
wxImage
image
(
30
,
20
);
fill_image
(
image
,
color
);
set_alpha
(
image
,
color
.
alpha
/
255.0
);
...
...
src/gui/value/choice.cpp
View file @
4017a911
...
...
@@ -255,7 +255,7 @@ size_t DropDownChoiceList::selection() const {
return
0
;
}
else
{
// run default script to find out what the default choice would be
String
default_choice
=
*
field
().
default_script
.
invoke
(
cve
.
viewer
.
getContext
()
);
String
default_choice
=
field
().
default_script
.
invoke
(
cve
.
viewer
.
getContext
()
)
->
toString
(
);
default_id
=
group
->
choiceId
(
default_choice
);
}
}
...
...
src/gui/value/color.cpp
View file @
4017a911
...
...
@@ -109,7 +109,7 @@ size_t DropDownColorList::selection() const {
return
0
;
}
else
if
(
hasDefault
())
{
// evaluate script to find default color
default_color
=
*
field
().
default_script
.
invoke
(
cve
.
viewer
.
getContext
()
);
default_color
=
field
().
default_script
.
invoke
(
cve
.
viewer
.
getContext
())
->
toColor
(
);
}
return
selection
;
}
...
...
src/script/context.cpp
View file @
4017a911
...
...
@@ -67,7 +67,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
}
// Conditional jump
case
I_JUMP_IF_NOT
:
{
bool
condition
=
*
stack
.
back
();
bool
condition
=
stack
.
back
()
->
toBool
();
stack
.
pop_back
();
if
(
!
condition
)
{
instr
=
&
script
.
instructions
[
0
]
+
i
.
data
;
...
...
@@ -76,7 +76,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
}
// Short-circuiting and/or = conditional jump without pop
case
I_JUMP_SC_AND
:
{
bool
condition
=
*
stack
.
back
();
bool
condition
=
stack
.
back
()
->
toBool
();
if
(
!
condition
)
{
instr
=
&
script
.
instructions
[
0
]
+
i
.
data
;
}
else
{
...
...
@@ -85,7 +85,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
break
;
}
case
I_JUMP_SC_OR
:
{
bool
condition
=
*
stack
.
back
();
bool
condition
=
stack
.
back
()
->
toBool
();
if
(
condition
)
{
instr
=
&
script
.
instructions
[
0
]
+
i
.
data
;
}
else
{
...
...
@@ -109,7 +109,7 @@ ScriptValueP Context::eval(const Script& script, bool useScope) {
// Get an object member
case
I_MEMBER_C
:
{
stack
.
back
()
=
stack
.
back
()
->
getMember
(
*
script
.
constants
[
i
.
data
]
);
stack
.
back
()
=
stack
.
back
()
->
getMember
(
script
.
constants
[
i
.
data
]
->
toString
()
);
break
;
}
// Loop over a container, push next value or jump
...
...
@@ -367,13 +367,13 @@ void instrUnary (UnaryInstructionType i, ScriptValueP& a) {
case
I_NEGATE
:
{
ScriptType
at
=
a
->
type
();
if
(
at
==
SCRIPT_DOUBLE
)
{
a
=
to_script
(
-
(
double
)
*
a
);
a
=
to_script
(
-
a
->
toDouble
()
);
}
else
{
a
=
to_script
(
-
(
int
)
*
a
);
a
=
to_script
(
-
a
->
toInt
()
);
}
break
;
}
case
I_NOT
:
a
=
to_script
(
!
(
bool
)
*
a
);
a
=
to_script
(
!
a
->
toBool
()
);
break
;
}
}
...
...
@@ -425,29 +425,29 @@ class ScriptCompose : public ScriptValue {
// operator on ints
#define OPERATOR_I(OP) \
a
=
to_script
(
(
int
)
*
a
OP
(
int
)
*
b
);
\
a
=
to_script
(
a
->
toInt
()
OP
b
->
toInt
());
\
break
// operator on bools
#define OPERATOR_B(OP) \
a
=
to_script
(
(
bool
)
*
a
OP
(
bool
)
*
b
);
\
a
=
to_script
(
a
->
toBool
()
OP
b
->
toBool
());
\
break
// operator on doubles or ints
#define OPERATOR_DI(OP) \
if
(
at
==
SCRIPT_DOUBLE
||
bt
==
SCRIPT_DOUBLE
)
{
\
a
=
to_script
(
(
double
)
*
a
OP
(
double
)
*
b
);
\
a
=
to_script
(
a
->
toDouble
()
OP
b
->
toDouble
());
\
}
else
{
\
a
=
to_script
(
(
int
)
*
a
OP
(
int
)
*
b
);
\
a
=
to_script
(
a
->
toInt
()
OP
b
->
toInt
());
\
}
\
break
// operator on doubles or ints, defined as a function
#define OPERATOR_FUN_DI(OP) \
if
(
at
==
SCRIPT_DOUBLE
||
bt
==
SCRIPT_DOUBLE
)
{
\
a
=
to_script
(
OP
(
(
double
)
*
a
,
(
double
)
*
b
));
\
a
=
to_script
(
OP
(
a
->
toDouble
(),
b
->
toDouble
()));
\
}
else
{
\
a
=
to_script
(
OP
(
(
int
)
*
a
,
(
int
)
*
b
));
\
a
=
to_script
(
OP
(
a
->
toInt
(),
b
->
toInt
()));
\
}
\
break
...
...
@@ -455,10 +455,10 @@ class ScriptCompose : public ScriptValue {
void
instrBinary
(
BinaryInstructionType
i
,
ScriptValueP
&
a
,
const
ScriptValueP
&
b
)
{
switch
(
i
)
{
case
I_MEMBER
:
a
=
a
->
getMember
(
*
b
);
a
=
a
->
getMember
(
b
->
toString
()
);
break
;
case
I_ITERATOR_R
:
a
=
rangeIterator
(
*
a
,
*
b
);
a
=
rangeIterator
(
a
->
toInt
(),
b
->
toInt
()
);
break
;
default:
ScriptType
at
=
a
->
type
(),
bt
=
b
->
type
();
...
...
@@ -473,10 +473,10 @@ void instrBinary (BinaryInstructionType i, ScriptValueP& a, const ScriptValueP&
}
else
if
(
at
==
SCRIPT_COLLECTION
&&
bt
==
SCRIPT_COLLECTION
)
{
a
=
intrusive
(
new
ScriptConcatCollection
(
a
,
b
));
}
else
if
(
at
==
SCRIPT_INT
&&
bt
==
SCRIPT_INT
)
{
a
=
to_script
(
(
int
)
*
a
+
(
int
)
*
b
);
a
=
to_script
(
a
->
toInt
()
+
b
->
toInt
()
);
}
else
if
((
at
==
SCRIPT_INT
||
at
==
SCRIPT_DOUBLE
)
&&
(
bt
==
SCRIPT_INT
||
bt
==
SCRIPT_DOUBLE
))
{
a
=
to_script
(
(
double
)
*
a
+
(
double
)
*
b
);
a
=
to_script
(
a
->
toDouble
()
+
b
->
toDouble
()
);
}
else
{
a
=
to_script
(
a
->
toString
()
+
b
->
toString
());
}
...
...
@@ -484,34 +484,34 @@ void instrBinary (BinaryInstructionType i, ScriptValueP& a, const ScriptValueP&
case
I_SUB
:
OPERATOR_DI
(
-
);
case
I_MUL
:
OPERATOR_DI
(
*
);
case
I_FDIV
:
a
=
to_script
(
(
double
)
*
a
/
(
double
)
*
b
);
a
=
to_script
(
a
->
toDouble
()
/
b
->
toDouble
()
);
break
;
case
I_DIV
:
if
(
at
==
SCRIPT_DOUBLE
||
bt
==
SCRIPT_DOUBLE
)
{
a
=
to_script
((
int
)(
(
double
)
*
a
/
(
double
)
*
b
));
a
=
to_script
((
int
)(
a
->
toDouble
()
/
b
->
toDouble
()
));
}
else
{
a
=
to_script
(
(
int
)
*
a
/
(
int
)
*
b
);
a
=
to_script
(
a
->
toInt
()
/
b
->
toInt
()
);
}
break
;
case
I_MOD
:
if
(
at
==
SCRIPT_DOUBLE
||
bt
==
SCRIPT_DOUBLE
)
{
a
=
to_script
(
fmod
(
(
double
)
*
a
,
(
double
)
*
b
));
a
=
to_script
(
fmod
(
a
->
toDouble
(),
b
->
toDouble
()
));
}
else
{
a
=
to_script
(
(
int
)
*
a
%
(
int
)
*
b
);
a
=
to_script
(
a
->
toInt
()
%
b
->
toInt
()
);
}
break
;
case
I_POW
:
if
(
bt
==
SCRIPT_INT
)
{
int
bi
=
*
b
;
int
bi
=
b
->
toInt
()
;
if
(
at
==
SCRIPT_DOUBLE
)
{
double
aa
=
*
a
;
double
aa
=
a
->
toDouble
()
;
if
(
bi
==
0
)
a
=
to_script
(
1
);
else
if
(
bi
==
1
)
a
=
to_script
(
aa
);
else
if
(
bi
==
2
)
a
=
to_script
(
aa
*
aa
);
else
if
(
bi
==
3
)
a
=
to_script
(
aa
*
aa
*
aa
);
else
a
=
to_script
(
pow
(
aa
,
bi
));
}
else
{
int
aa
=
*
a
;
int
aa
=
a
->
toInt
()
;
if
(
bi
==
0
)
a
=
to_script
(
1
);
else
if
(
bi
==
1
)
a
=
to_script
(
aa
);
else
if
(
bi
==
2
)
a
=
to_script
(
aa
*
aa
);
...
...
@@ -519,7 +519,7 @@ void instrBinary (BinaryInstructionType i, ScriptValueP& a, const ScriptValueP&
else
a
=
to_script
(
pow
((
double
)
aa
,
bi
));
}
}
else
{
a
=
to_script
(
pow
(
(
double
)
*
a
,
(
double
)
*
b
));
a
=
to_script
(
pow
(
a
->
toDouble
(),
b
->
toDouble
()
));
}
break
;
case
I_AND
:
OPERATOR_B
(
&&
);
...
...
@@ -546,7 +546,7 @@ void instrBinary (BinaryInstructionType i, ScriptValueP& a, const ScriptValueP&
void
instrTernary
(
TernaryInstructionType
i
,
ScriptValueP
&
a
,
const
ScriptValueP
&
b
,
const
ScriptValueP
&
c
)
{
switch
(
i
)
{
case
I_RGB
:
a
=
to_script
(
Color
(
(
int
)
*
a
,
(
int
)
*
b
,
(
int
)
*
c
));
a
=
to_script
(
Color
(
a
->
toInt
(),
b
->
toInt
(),
c
->
toInt
()
));
break
;
}
}
...
...
@@ -556,7 +556,7 @@ void instrTernary(TernaryInstructionType i, ScriptValueP& a, const ScriptValueP&
void
instrQuaternary
(
QuaternaryInstructionType
i
,
ScriptValueP
&
a
,
const
ScriptValueP
&
b
,
const
ScriptValueP
&
c
,
const
ScriptValueP
&
d
)
{
switch
(
i
)
{
case
I_RGBA
:
a
=
to_script
(
AColor
(
(
int
)
*
a
,
(
int
)
*
b
,
(
int
)
*
c
,
(
int
)
*
d
));
a
=
to_script
(
AColor
(
a
->
toInt
(),
b
->
toInt
(),
c
->
toInt
(),
d
->
toInt
()
));
break
;
}
}
...
...
src/script/dependency.cpp
View file @
4017a911
...
...
@@ -83,10 +83,10 @@ class ScriptMissingVariable : public ScriptValue {
ScriptMissingVariable
(
const
String
&
name
)
:
name
(
name
)
{}
virtual
ScriptType
type
()
const
{
return
SCRIPT_NIL
;
}
virtual
String
typeName
()
const
{
return
_
(
"missing variable '"
)
+
name
+
_
(
"'"
);
}
virtual
operator
String
()
const
{
return
wxEmptyString
;
}
virtual
operator
d
ouble
()
const
{
return
0.0
;
}
virtual
operator
i
nt
()
const
{
return
0
;
}
virtual
operator
b
ool
()
const
{
return
false
;
}
virtual
String
to
String
()
const
{
return
wxEmptyString
;
}
virtual
double
toD
ouble
()
const
{
return
0.0
;
}
virtual
int
toI
nt
()
const
{
return
0
;
}
virtual
bool
toB
ool
()
const
{
return
false
;
}
virtual
ScriptValueP
eval
(
Context
&
)
const
{
return
script_nil
;
}
// nil() == nil
private:
String
name
;
///< Name of the variable
...
...
@@ -227,7 +227,7 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script)
// Get an object member (almost as normal)
case
I_MEMBER_C
:
{
String
name
=
*
script
.
constants
[
i
.
data
]
;
String
name
=
script
.
constants
[
i
.
data
]
->
toString
()
;
stack
.
back
()
=
stack
.
back
()
->
dependencyMember
(
name
,
dep
);
// dependency on member
break
;
}
...
...
src/script/functions/basic.cpp
View file @
4017a911
...
...
@@ -68,9 +68,9 @@ String format_input(const String& format, const ScriptValue& input) {
// determine type expected by format string
String
fmt
=
_
(
"%"
)
+
replace_all
(
format
,
_
(
"%"
),
_
(
""
));
if
(
format
.
find_first_of
(
_
(
"DdIiOoXx"
))
!=
String
::
npos
)
{
return
String
::
Format
(
fmt
,
(
int
)
input
);
return
String
::
Format
(
fmt
,
input
.
toInt
()
);
}
else
if
(
format
.
find_first_of
(
_
(
"EeFfGg"
))
!=
String
::
npos
)
{
return
String
::
Format
(
fmt
,
(
double
)
input
);
return
String
::
Format
(
fmt
,
input
.
toDouble
()
);
}
else
if
(
format
.
find_first_of
(
_
(
"Ss"
))
!=
String
::
npos
)
{
return
format_string
(
fmt
,
input
.
toString
());
}
else
{
...
...
@@ -85,7 +85,7 @@ SCRIPT_FUNCTION(to_string) {
try
{
if
(
format
&&
format
->
type
()
==
SCRIPT_STRING
)
{
// format specifier. Be careful, the built in function 'format' has the same name
SCRIPT_RETURN
(
format_input
(
*
format
,
*
input
));
SCRIPT_RETURN
(
format_input
(
format
->
toString
()
,
*
input
));
}
else
{
// simple conversion
SCRIPT_RETURN
(
input
->
toString
());
...
...
@@ -101,9 +101,9 @@ SCRIPT_FUNCTION(to_int) {
try
{
int
result
;
if
(
t
==
SCRIPT_BOOL
)
{
result
=
(
bool
)
*
input
?
1
:
0
;
result
=
input
->
toBool
()
?
1
:
0
;
}
else
if
(
t
==
SCRIPT_COLOR
)
{
AColor
c
=
(
AColor
)
*
input
;
AColor
c
=
input
->
toColor
()
;
result
=
(
c
.
Red
()
+
c
.
Blue
()
+
c
.
Green
())
/
3
;
}
else
if
(
t
==
SCRIPT_STRING
)
{
long
l
;
...
...
@@ -116,7 +116,7 @@ SCRIPT_FUNCTION(to_int) {
return
delay_error
(
ScriptErrorConversion
(
str
,
input
->
typeName
(),
_TYPE_
(
"integer"
)));
}
}
else
{
result
=
(
int
)
*
input
;
result
=
input
->
toInt
()
;
}
SCRIPT_RETURN
(
result
);
}
catch
(
const
ScriptError
&
e
)
{
...
...
@@ -130,9 +130,9 @@ SCRIPT_FUNCTION(to_real) {
try
{
double
result
;
if
(
t
==
SCRIPT_BOOL
)
{
result
=
(
bool
)
*
input
?
1.0
:
0.0
;
result
=
input
->
toBool
()
?
1.0
:
0.0
;
}
else
if
(
t
==
SCRIPT_COLOR
)
{
AColor
c
=
(
AColor
)
*
input
;
AColor
c
=
input
->
toColor
()
;
result
=
(
c
.
Red
()
+
c
.
Blue
()
+
c
.
Green
())
/
3.0
;
}
else
if
(
t
==
SCRIPT_STRING
)
{
String
str
=
input
->
toString
();
...
...
@@ -142,7 +142,7 @@ SCRIPT_FUNCTION(to_real) {
return
delay_error
(
ScriptErrorConversion
(
str
,
input
->
typeName
(),
_TYPE_
(
"double"
)));
}
}
else
{
result
=
(
double
)
*
input
;
result
=
input
->
toDouble
()
;
}
SCRIPT_RETURN
(
result
);
}
catch
(
const
ScriptError
&
e
)
{
...
...
@@ -155,12 +155,12 @@ SCRIPT_FUNCTION(to_number) {
ScriptType
t
=
input
->
type
();
try
{
if
(
t
==
SCRIPT_BOOL
)
{
SCRIPT_RETURN
(
(
bool
)
*
input
?
1
:
0
);
SCRIPT_RETURN
(
input
->
toBool
()
?
1
:
0
);
}
else
if
(
t
==
SCRIPT_COLOR
)
{
AColor
c
=
(
AColor
)
*
input
;
AColor
c
=
input
->
toColor
()
;
SCRIPT_RETURN
(
(
c
.
Red
()
+
c
.
Blue
()
+
c
.
Green
())
/
3
);
}
else
if
(
t
==
SCRIPT_DOUBLE
)
{
SCRIPT_RETURN
((
double
)
*
input
)
;
}
else
if
(
t
==
SCRIPT_DOUBLE
||
t
==
SCRIPT_INT
)
{
return
input
;
}
else
if
(
t
==
SCRIPT_NIL
)
{
SCRIPT_RETURN
(
0
);
}
else
{
...
...
@@ -187,9 +187,9 @@ SCRIPT_FUNCTION(to_boolean) {
ScriptType
t
=
input
->
type
();
bool
result
;
if
(
t
==
SCRIPT_INT
)
{
result
=
(
int
)
*
input
!=
0
;
result
=
input
->
toInt
()
!=
0
;
}
else
{
result
=
(
bool
)
*
input
;
result
=
input
->
toBool
()
;
}
SCRIPT_RETURN
(
result
);
}
catch
(
const
ScriptError
&
e
)
{
...
...
@@ -226,9 +226,9 @@ SCRIPT_FUNCTION(abs) {
ScriptValueP
input
=
ctx
.
getVariable
(
SCRIPT_VAR_input
);
ScriptType
t
=
input
->
type
();
if
(
t
==
SCRIPT_DOUBLE
)
{
SCRIPT_RETURN
(
fabs
(
(
double
)
*
input
));
SCRIPT_RETURN
(
fabs
(
input
->
toDouble
()
));
}
else
{
SCRIPT_RETURN
(
abs
(
(
int
)
*
input
));
SCRIPT_RETURN
(
abs
(
input
->
toInt
()
));
}
}
...
...
@@ -566,7 +566,7 @@ SCRIPT_FUNCTION(filter_list) {
ScriptValueP
it
=
input
->
makeIterator
(
input
);
while
(
ScriptValueP
v
=
it
->
next
())
{
ctx
.
setVariable
(
SCRIPT_VAR_input
,
v
);
if
(
*
filter
->
eval
(
ctx
))
{
if
(
filter
->
eval
(
ctx
)
->
toBool
(
))
{
ret
->
value
.
push_back
(
v
);
}
}
...
...
@@ -609,7 +609,7 @@ SCRIPT_FUNCTION(random_select_many) {
SCRIPT_PARAM_C
(
ScriptValueP
,
input
);
SCRIPT_PARAM
(
int
,
count
)
;
SCRIPT_OPTIONAL_PARAM_C_
(
ScriptValueP
,
replace
);
bool
with_replace
=
replace
&&
replace
->
type
()
!=
SCRIPT_FUNCTION
&&
(
bool
)
*
replace
;
bool
with_replace
=
replace
&&
replace
->
type
()
!=
SCRIPT_FUNCTION
&&
replace
->
toBool
()
;
// pick many
ScriptCustomCollectionP
ret
(
new
ScriptCustomCollection
);
int
itemCount
=
input
->
itemCount
();
...
...
src/script/functions/construction.cpp
View file @
4017a911
...
...
@@ -44,7 +44,7 @@ SCRIPT_FUNCTION(new_card) {
}
else
if
(
PackageChoiceValue
*
pvalue
=
dynamic_cast
<
PackageChoiceValue
*>
(
value
))
{
pvalue
->
package_name
=
v
->
toString
();
}
else
if
(
ColorValue
*
cvalue
=
dynamic_cast
<
ColorValue
*>
(
value
))
{
cvalue
->
value
=
(
AColor
)
*
v
;
cvalue
->
value
=
v
->
toColor
()
;
}
else
{
throw
ScriptError
(
format_string
(
_
(
"Can not set value '%s', it is not of the right type"
),
name
));
}
...
...
src/script/functions/regex.cpp
View file @
4017a911
...
...
@@ -53,7 +53,7 @@ ScriptRegexP regex_from_script(const ScriptValueP& value) {
ScriptRegexP
regex
=
dynamic_pointer_cast
<
ScriptRegex
>
(
value
);
if
(
!
regex
)
{
// TODO: introduce some kind of caching?
regex
=
intrusive
(
new
ScriptRegex
(
*
value
));
regex
=
intrusive
(
new
ScriptRegex
(
value
->
toString
()
));
}
return
regex
;
}
...
...
src/script/functions/spelling.cpp
View file @
4017a911
...
...
@@ -37,12 +37,12 @@ inline size_t spelled_correctly(const String& input, size_t start, size_t end, S
if
(
extra_test
)
{
// try on untagged
ctx
.
setVariable
(
SCRIPT_VAR_input
,
to_script
(
word
));
if
(
*
extra_test
->
eval
(
ctx
))
{
if
(
extra_test
->
eval
(
ctx
)
->
toBool
(
))
{
return
true
;
}
// try on tagged
ctx
.
setVariable
(
SCRIPT_VAR_input
,
to_script
(
input
.
substr
(
start
,
end
-
start
)));
if
(
*
extra_test
->
eval
(
ctx
))
{
if
(
extra_test
->
eval
(
ctx
)
->
toBool
(
))
{
return
true
;
}
}
...
...
src/script/scriptable.cpp
View file @
4017a911
...
...
@@ -21,15 +21,16 @@ DECLARE_TYPEOF_COLLECTION(ScriptParseError);
// ----------------------------------------------------------------------------- : Store
// TODO: reduce duplication, see from_script
void
store
(
const
ScriptValueP
&
val
,
String
&
var
)
{
var
=
val
->
toString
();
}
void
store
(
const
ScriptValueP
&
val
,
int
&
var
)
{
var
=
*
val
;
}
void
store
(
const
ScriptValueP
&
val
,
double
&
var
)
{
var
=
*
val
;
}
void
store
(
const
ScriptValueP
&
val
,
bool
&
var
)
{
var
=
*
val
;
}
void
store
(
const
ScriptValueP
&
val
,
Color
&
var
)
{
var
=
(
AColor
)
*
val
;
}
void
store
(
const
ScriptValueP
&
val
,
AColor
&
var
)
{
var
=
*
val
;
}
void
store
(
const
ScriptValueP
&
val
,
Defaultable
<
String
>&
var
)
{
var
.
assign
(
*
val
);
}
void
store
(
const
ScriptValueP
&
val
,
Defaultable
<
Color
>&
var
)
{
var
.
assign
(
(
AColor
)
*
val
);
}
void
store
(
const
ScriptValueP
&
val
,
Defaultable
<
AColor
>&
var
)
{
var
.
assign
(
*
val
);
}
void
store
(
const
ScriptValueP
&
val
,
int
&
var
)
{
var
=
val
->
toInt
()
;
}
void
store
(
const
ScriptValueP
&
val
,
double
&
var
)
{
var
=
val
->
toDouble
()
;
}
void
store
(
const
ScriptValueP
&
val
,
bool
&
var
)
{
var
=
val
->
toBool
()
;
}
void
store
(
const
ScriptValueP
&
val
,
Color
&
var
)
{
var
=
val
->
toColor
()
;
}
void
store
(
const
ScriptValueP
&
val
,
AColor
&
var
)
{
var
=
val
->
toColor
()
;
}
void
store
(
const
ScriptValueP
&
val
,
Defaultable
<
String
>&
var
)
{
var
.
assign
(
val
->
toString
()
);
}
void
store
(
const
ScriptValueP
&
val
,
Defaultable
<
Color
>&
var
)
{
var
.
assign
(
val
->
toColor
()
);
}
void
store
(
const
ScriptValueP
&
val
,
Defaultable
<
AColor
>&
var
)
{
var
.
assign
(
val
->
toColor
()
);
}
void
store
(
const
ScriptValueP
&
val
,
Alignment
&
var
)
{
var
=
from_string
(
val
->
toString
());
}
void
store
(
const
ScriptValueP
&
val
,
Direction
&
var
)
{
parse_enum
(
val
->
toString
(),
var
);
}
...
...
src/script/to_value.hpp
View file @
4017a911
...
...
@@ -74,11 +74,11 @@ class ScriptDelayedError : public ScriptValue {
// all of these throw
virtual
String
typeName
()
const
;
virtual
operator
String
()
const
;
virtual
operator
d
ouble
()
const
;
virtual
operator
i
nt
()
const
;
virtual
operator
b
ool
()
const
;
virtual
operator
AColor
()
const
;
virtual
String
to
String
()
const
;
virtual
double
toD
ouble
()
const
;
virtual
int
toI
nt
()
const
;
virtual
bool
toB
ool
()
const
;
virtual
AColor
toColor
()
const
;
virtual
int
itemCount
()
const
;
virtual
CompareWhat
compareAs
(
String
&
,
void
const
*&
)
const
;
// these can propagate the error
...
...
@@ -273,11 +273,11 @@ class ScriptObject : public ScriptValue {
inline
ScriptObject
(
const
T
&
v
)
:
value
(
v
)
{}
virtual
ScriptType
type
()
const
{
ScriptValueP
d
=
getDefault
();
return
d
?
d
->
type
()
:
SCRIPT_OBJECT
;
}
virtual
String
typeName
()
const
{
return
type_name
(
*
value
);
}
virtual
operator
String
()
const
{
ScriptValueP
d
=
getDefault
();
return
d
?
*
d
:
ScriptValue
::
operator
String
();
}
virtual
operator
double
()
const
{
ScriptValueP
d
=
getDefault
();
return
d
?
*
d
:
ScriptValue
::
operator
double
();
}
virtual
operator
int
()
const
{
ScriptValueP
d
=
getDefault
();
return
d
?
*
d
:
ScriptValue
::
operator
int
();
}
virtual
operator
bool
()
const
{
ScriptValueP
d
=
getDefault
();
return
d
?
*
d
:
ScriptValue
::
operator
b
ool
();
}
virtual
operator
AColor
()
const
{
ScriptValueP
d
=
getDefault
();
return
d
?
*
d
:
ScriptValue
::
operator
A
Color
();
}
virtual
String
toString
()
const
{
ScriptValueP
d
=
getDefault
();
return
d
?
d
->
toString
()
:
ScriptValue
::
to
String
();
}
virtual
int
toInt
()
const
{
ScriptValueP
d
=
getDefault
();
return
d
?
d
->
toInt
()
:
ScriptValue
::
toInt
();
}
virtual
double
toDouble
()
const
{
ScriptValueP
d
=
getDefault
();
return
d
?
d
->
toDouble
()
:
ScriptValue
::
toDouble
();
}
virtual
bool
toBool
()
const
{
ScriptValueP
d
=
getDefault
();
return
d
?
d
->
toBool
()
:
ScriptValue
::
toB
ool
();
}
virtual
AColor
toColor
()
const
{
ScriptValueP
d
=
getDefault
();
return
d
?
d
->
toColor
()
:
ScriptValue
::
to
Color
();
}
virtual
String
toCode
()
const
{
ScriptValueP
d
=
getDefault
();
return
d
?
d
->
toCode
()
:
to_code
(
*
value
);
}
virtual
GeneratedImageP
toImage
(
const
ScriptValueP
&
thisP
)
const
{
ScriptValueP
d
=
getDefault
();
return
d
?
d
->
toImage
(
d
)
:
ScriptValue
::
toImage
(
thisP
);
...
...
@@ -422,13 +422,13 @@ template <typename T> inline T from_script (const ScriptValueP& va
return
o
->
getValue
();
}
template
<>
inline
ScriptValueP
from_script
<
ScriptValueP
>
(
const
ScriptValueP
&
value
)
{
return
value
;
}
template
<>
inline
String
from_script
<
String
>
(
const
ScriptValueP
&
value
)
{
return
*
value
;
}
template
<>
inline
int
from_script
<
int
>
(
const
ScriptValueP
&
value
)
{
return
*
value
;
}
template
<>
inline
double
from_script
<
double
>
(
const
ScriptValueP
&
value
)
{
return
*
value
;
}
template
<>
inline
bool
from_script
<
bool
>
(
const
ScriptValueP
&
value
)
{
return
*
value
;
}
template
<>
inline
Color
from_script
<
Color
>
(
const
ScriptValueP
&
value
)
{
return
(
AColor
)
*
value
;
}
template
<>
inline
AColor
from_script
<
AColor
>
(
const
ScriptValueP
&
value
)
{
return
*
value
;
}
template
<>
inline
wxDateTime
from_script
<
wxDateTime
>
(
const
ScriptValueP
&
value
)
{
return
*
value
;
}
template
<>
inline
String
from_script
<
String
>
(
const
ScriptValueP
&
value
)
{
return
value
->
toString
()
;
}
template
<>
inline
int
from_script
<
int
>
(
const
ScriptValueP
&
value
)
{
return
value
->
toInt
()
;
}
template
<>
inline
double
from_script
<
double
>
(
const
ScriptValueP
&
value
)
{
return
value
->
toDouble
()
;
}
template
<>
inline
bool
from_script
<
bool
>
(
const
ScriptValueP
&
value
)
{
return
value
->
toBool
()
;
}
template
<>
inline
Color
from_script
<
Color
>
(
const
ScriptValueP
&
value
)
{
return
value
->
toColor
()
;
}
template
<>
inline
AColor
from_script
<
AColor
>
(
const
ScriptValueP
&
value
)
{
return
value
->
toColor
()
;
}
template
<>
inline
wxDateTime
from_script
<
wxDateTime
>
(
const
ScriptValueP
&
value
)
{
return
value
->
toDateTime
()
;
}
// ----------------------------------------------------------------------------- : EOF
#endif
src/script/value.cpp
View file @
4017a911
...
...
@@ -19,18 +19,18 @@ DECLARE_TYPEOF_COLLECTION(pair<Variable COMMA ScriptValueP>);
// ----------------------------------------------------------------------------- : ScriptValue
// Base cases
ScriptValue
::
operator
String
()
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"string"
));
}
ScriptValue
::
operator
int
()
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"integer"
));
}
ScriptValue
::
operator
bool
()
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"boolean"
));
}
ScriptValue
::
operator
double
()
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"double"
));
}
ScriptValue
::
operator
AColor
()
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"color"
));
}
ScriptValue
::
operator
wxDateTime
()
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"date"
));
}
String
ScriptValue
::
toString
()
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"string"
));
}
int
ScriptValue
::
toInt
()
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"integer"
));
}
bool
ScriptValue
::
toBool
()
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"boolean"
));
}
double
ScriptValue
::
toDouble
()
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"double"
));
}
AColor
ScriptValue
::
toColor
()
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"color"
));
}
wxDateTime
ScriptValue
::
toDateTime
()
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"date"
));
}
GeneratedImageP
ScriptValue
::
toImage
(
const
ScriptValueP
&
)
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"image"
));
}
String
ScriptValue
::
toCode
()
const
{
return
toString
();
}
ScriptValueP
ScriptValue
::
do_eval
(
Context
&
,
bool
)
const
{
return
delay_error
(
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"function"
)));
}
ScriptValueP
ScriptValue
::
next
(
ScriptValueP
*
key_out
)
{
throw
InternalError
(
_
(
"Can't convert from "
)
+
typeName
()
+
_
(
" to iterator"
));
}
ScriptValueP
ScriptValue
::
makeIterator
(
const
ScriptValueP
&
)
const
{
return
delay_error
(
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"collection"
)));
}
int
ScriptValue
::
itemCount
()
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"collection"
));
}
GeneratedImageP
ScriptValue
::
toImage
(
const
ScriptValueP
&
)
const
{
throw
ScriptErrorConversion
(
typeName
(),
_TYPE_
(
"image"
));
}
String
ScriptValue
::
toCode
()
const
{
return
*
this
;
}
CompareWhat
ScriptValue
::
compareAs
(
String
&
compare_str
,
void
const
*&
compare_ptr
)
const
{
compare_str
=
toCode
();
return
COMPARE_AS_STRING
;
...
...
@@ -66,12 +66,12 @@ bool equal(const ScriptValueP& a, const ScriptValueP& b) {
if
(
a
==
b
)
return
true
;
ScriptType
at
=
a
->
type
(),
bt
=
b
->
type
();
if
(
at
==
bt
&&
at
==
SCRIPT_INT
)
{
return
(
int
)
*
a
==
(
int
)
*
b
;
return
a
->
toInt
()
==
b
->
toInt
()
;
}
else
if
(
at
==
bt
&&
at
==
SCRIPT_BOOL
)
{
return
(
bool
)
*
a
==
(
bool
)
*
b
;
return
a
->
toBool
()
==
b
->
toBool
()
;
}
else
if
((
at
==
SCRIPT_INT
||
at
==
SCRIPT_DOUBLE
)
&&
(
bt
==
SCRIPT_INT
||
bt
==
SCRIPT_DOUBLE
))
{
return
approx_equal
(
(
double
)
*
a
,
(
double
)
*
b
);
return
approx_equal
(
a
->
toDouble
(),
b
->
toDouble
()
);
}
else
if
(
at
==
SCRIPT_COLLECTION
&&
bt
==
SCRIPT_COLLECTION
)
{
// compare each element
if
(
a
->
itemCount
()
!=
b
->
itemCount
())
return
false
;
...
...
@@ -104,11 +104,11 @@ bool equal(const ScriptValueP& a, const ScriptValueP& b) {
ScriptType
ScriptDelayedError
::
type
()
const
{
return
SCRIPT_ERROR
;
}
String
ScriptDelayedError
::
typeName
()
const
{
throw
error
;
}
S
criptDelayedError
::
operator
String
()
const
{
throw
error
;
}
ScriptDelayedError
::
operator
double
()
const
{
throw
error
;
}
ScriptDelayedError
::
operator
int
()
const
{
throw
error
;
}
ScriptDelayedError
::
operator
bool
()
const
{
throw
error
;
}
ScriptDelayedError
::
operator
AColor
()
const
{
throw
error
;
}
S
tring
ScriptDelayedError
::
toString
()
const
{
throw
error
;
}
double
ScriptDelayedError
::
toDouble
()
const
{
throw
error
;
}
int
ScriptDelayedError
::
toInt
()
const
{
throw
error
;
}
bool
ScriptDelayedError
::
toBool
()
const
{
throw
error
;
}
AColor
ScriptDelayedError
::
toColor
()
const
{
throw
error
;
}
int
ScriptDelayedError
::
itemCount
()
const
{
throw
error
;
}
CompareWhat
ScriptDelayedError
::
compareAs
(
String
&
,
void
const
*&
)
const
{
throw
error
;
}
ScriptValueP
ScriptDelayedError
::
getMember
(
const
String
&
)
const
{
return
intrusive
(
new
ScriptDelayedError
(
error
));
}
...
...
@@ -157,9 +157,9 @@ class ScriptInt : public ScriptValue {
ScriptInt
(
int
v
)
:
value
(
v
)
{}
virtual
ScriptType
type
()
const
{
return
SCRIPT_INT
;
}
virtual
String
typeName
()
const
{
return
_TYPE_
(
"integer"
);
}
virtual
operator
String
()
const
{
return
String
()
<<
value
;
}
virtual
operator
d
ouble
()
const
{
return
value
;
}
virtual
operator
i
nt
()
const
{
return
value
;
}
virtual
String
to
String
()
const
{
return
String
()
<<
value
;
}
virtual
double
toD
ouble
()
const
{
return
value
;
}
virtual
int
toI
nt
()
const
{
return
value
;
}
protected:
#ifdef USE_POOL_ALLOCATOR
virtual
void
destroy
()
{
...
...
@@ -202,9 +202,9 @@ class ScriptBool : public ScriptValue {
ScriptBool
(
bool
v
)
:
value
(
v
)
{}
virtual
ScriptType
type
()
const
{
return
SCRIPT_BOOL
;
}
virtual
String
typeName
()
const
{
return
_TYPE_
(
"boolean"
);
}
virtual
operator
String
()
const
{
return
value
?
_
(
"true"
)
:
_
(
"false"
);
}
virtual
String
to
String
()
const
{
return
value
?
_
(
"true"
)
:
_
(
"false"
);
}
// bools don't autoconvert to int
virtual
operator
b
ool
()
const
{
return
value
;
}
virtual
bool
toB
ool
()
const
{
return
value
;
}
private:
bool
value
;
};
...
...
@@ -225,9 +225,9 @@ class ScriptDouble : public ScriptValue {
ScriptDouble
(
double
v
)
:
value
(
v
)
{}
virtual
ScriptType
type
()
const
{
return
SCRIPT_DOUBLE
;
}
virtual
String
typeName
()
const
{
return
_TYPE_
(
"double"
);
}
virtual
operator
String
()
const
{
return
String
()
<<
value
;
}
virtual
operator
d
ouble
()
const
{
return
value
;
}
virtual
operator
int
()
const
{
return
(
int
)
value
;
}
virtual
String
to
String
()
const
{
return
String
()
<<
value
;
}
virtual
double
toD
ouble
()
const
{
return
value
;
}
virtual
int
toInt
()
const
{
return
(
int
)
value
;
}
// TODO: do we want this automatic conversion?
private:
double
value
;
};
...
...
@@ -244,8 +244,8 @@ class ScriptString : public ScriptValue {
ScriptString
(
const
String
&
v
)
:
value
(
v
)
{}
virtual
ScriptType
type
()
const
{
return
SCRIPT_STRING
;
}
virtual
String
typeName
()
const
{
return
_TYPE_
(
"string"
)
+
_
(
" (
\"
"
)
+
(
value
.
size
()
<
30
?
value
:
value
.
substr
(
0
,
30
)
+
_
(
"..."
))
+
_
(
"
\"
)"
);
}
virtual
operator
String
()
const
{
return
value
;
}
virtual
operator
d
ouble
()
const
{
virtual
String
to
String
()
const
{
return
value
;
}
virtual
double
toD
ouble
()
const
{
double
d
;
if
(
value
.
ToDouble
(
&
d
))
{
return
d
;
...
...
@@ -253,7 +253,7 @@ class ScriptString : public ScriptValue {
throw
ScriptErrorConversion
(
value
,
typeName
(),
_TYPE_
(
"double"
));
}
}
virtual
operator
int
()
const
{
virtual
int
toInt
()
const
{
long
l
;
if
(
value
.
ToLong
(
&
l
))
{
return
l
;
...
...
@@ -261,7 +261,7 @@ class ScriptString : public ScriptValue {
throw
ScriptErrorConversion
(
value
,
typeName
(),
_TYPE_
(
"integer"
));
}
}
virtual
operator
bool
()
const
{
virtual
bool
toBool
()
const
{
if
(
value
==
_
(
"yes"
)
||
value
==
_
(
"true"
))
{
return
true
;
}
else
if
(
value
==
_
(
"no"
)
||
value
==
_
(
"false"
)
||
value
.
empty
())
{
...
...
@@ -270,14 +270,14 @@ class ScriptString : public ScriptValue {
throw
ScriptErrorConversion
(
value
,
typeName
(),
_TYPE_
(
"boolean"
));
}
}
virtual
operator
A
Color
()
const
{
virtual
AColor
to
Color
()
const
{
AColor
c
=
parse_acolor
(
value
);
if
(
!
c
.
Ok
())
{
throw
ScriptErrorConversion
(
value
,
typeName
(),
_TYPE_
(
"color"
));
}
return
c
;
}
virtual
operator
wx
DateTime
()
const
{
virtual
wxDateTime
to
DateTime
()
const
{
wxDateTime
date
;
if
(
!
date
.
ParseDateTime
(
value
.
c_str
()))
{
throw
ScriptErrorConversion
(
value
,
typeName
(),
_TYPE_
(
"date"
));
...
...
@@ -318,9 +318,9 @@ class ScriptAColor : public ScriptValue {
ScriptAColor
(
const
AColor
&
v
)
:
value
(
v
)
{}
virtual
ScriptType
type
()
const
{
return
SCRIPT_COLOR
;
}
virtual
String
typeName
()
const
{
return
_TYPE_
(
"color"
);
}
virtual
operator
A
Color
()
const
{
return
value
;
}
virtual
AColor
to
Color
()
const
{
return
value
;
}
// colors don't auto convert to int, use to_int to force
virtual
operator
String
()
const
{
virtual
String
to
String
()
const
{
return
format_acolor
(
value
);
}
private:
...
...
@@ -343,8 +343,8 @@ class ScriptDateTime : public ScriptValue {
ScriptDateTime
(
const
wxDateTime
&
v
)
:
value
(
v
)
{}
virtual
ScriptType
type
()
const
{
return
SCRIPT_DATETIME
;
}
virtual
String
typeName
()
const
{
return
_TYPE_
(
"date"
);
}
virtual
operator
wx
DateTime
()
const
{
return
value
;
}
virtual
operator
String
()
const
{
virtual
wxDateTime
to
DateTime
()
const
{
return
value
;
}
virtual
String
to
String
()
const
{
return
value
.
Format
(
_
(
"%Y-%m-%d %H:%M:%S"
));
}
private:
...
...
@@ -363,10 +363,10 @@ class ScriptNil : public ScriptValue {
public:
virtual
ScriptType
type
()
const
{
return
SCRIPT_NIL
;
}
virtual
String
typeName
()
const
{
return
_TYPE_
(
"nil"
);
}
virtual
operator
String
()
const
{
return
wxEmptyString
;
}
virtual
operator
d
ouble
()
const
{
return
0.0
;
}
virtual
operator
i
nt
()
const
{
return
0
;
}
virtual
operator
b
ool
()
const
{
return
false
;
}
virtual
String
to
String
()
const
{
return
wxEmptyString
;
}
virtual
double
toD
ouble
()
const
{
return
0.0
;
}
virtual
int
toI
nt
()
const
{
return
0
;
}
virtual
bool
toB
ool
()
const
{
return
false
;
}
virtual
GeneratedImageP
toImage
(
const
ScriptValueP
&
)
const
{
return
intrusive
(
new
BlankImage
());
}
...
...
src/script/value.hpp
View file @
4017a911
...
...
@@ -59,28 +59,19 @@ class ScriptValue : public IntrusivePtrBaseWithDelete {
virtual
CompareWhat
compareAs
(
String
&
compare_str
,
void
const
*&
compare_ptr
)
const
;
/// Convert this value to a string
virtual
operator
String
()
const
;
virtual
String
toString
()
const
;
/// Script code to generate this value
virtual
String
toCode
()
const
;
/// Convert this value to a double
virtual
operator
d
ouble
()
const
;
virtual
double
toD
ouble
()
const
;
/// Convert this value to an integer
virtual
operator
int
()
const
;
virtual
int
toInt
()
const
;
/// Convert this value to a boolean
virtual
operator
bool
()
const
;
virtual
bool
toBool
()
const
;
/// Convert this value to a color
virtual
operator
A
Color
()
const
;
virtual
AColor
to
Color
()
const
;
/// Convert this value to a wxDateTime
virtual
operator
wxDateTime
()
const
;
/// Script code to generate this value
virtual
String
toCode
()
const
;
/// Explicit overload to convert to a string
/** This is sometimes necessary, because wxString has an int constructor,
* which confuses gcc. */
inline
String
toString
()
const
{
return
*
this
;
}
/// Explicit overload to convert to a wxDateTime
/** Overload resolution is sometimes confused by other conversions */
inline
wxDateTime
toDateTime
()
const
{
return
*
this
;
}
virtual
wxDateTime
toDateTime
()
const
;
/// Convert this value to an image
virtual
GeneratedImageP
toImage
(
const
ScriptValueP
&
thisP
)
const
;
...
...
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