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