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
6f543cb1
Commit
6f543cb1
authored
Oct 19, 2006
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemented reflection
parent
f1193df0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
10 deletions
+35
-10
src/script/scriptable.cpp
src/script/scriptable.cpp
+4
-7
src/script/scriptable.hpp
src/script/scriptable.hpp
+31
-3
No files found.
src/script/scriptable.cpp
View file @
6f543cb1
...
@@ -24,7 +24,7 @@ void store(const ScriptValueP& val, Defaultable<String>& var) { var.assign(*val)
...
@@ -24,7 +24,7 @@ void store(const ScriptValueP& val, Defaultable<String>& var) { var.assign(*val)
OptionalScript
::~
OptionalScript
()
{}
OptionalScript
::~
OptionalScript
()
{}
ScriptValueP
OptionalScript
::
invoke
(
Context
&
ctx
)
{
ScriptValueP
OptionalScript
::
invoke
(
Context
&
ctx
)
const
{
if
(
script
)
{
if
(
script
)
{
return
ctx
.
eval
(
*
script
);
return
ctx
.
eval
(
*
script
);
}
else
{
}
else
{
...
@@ -44,14 +44,11 @@ template <> void Writer::handle(const OptionalScript& os) {
...
@@ -44,14 +44,11 @@ template <> void Writer::handle(const OptionalScript& os) {
handle
(
os
.
unparsed
);
handle
(
os
.
unparsed
);
}
}
template
<>
void
GetMember
::
handle
(
const
OptionalScript
&
os
)
{
template
<>
void
GetDefaultMember
::
handle
(
const
OptionalScript
&
os
)
{
// no members
}
template
<>
void
GetMember
::
store
(
const
OptionalScript
&
os
)
{
// reflect as the script itself
// reflect as the script itself
if
(
os
.
script
)
{
if
(
os
.
script
)
{
stor
e
(
os
.
script
);
handl
e
(
os
.
script
);
}
else
{
}
else
{
stor
e
(
script_nil
);
handl
e
(
script_nil
);
}
}
}
}
src/script/scriptable.hpp
View file @
6f543cb1
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
#include <util/reflect.hpp>
#include <util/reflect.hpp>
#include <util/defaultable.hpp>
#include <util/defaultable.hpp>
#include <script/script.hpp>
#include <script/script.hpp>
#include <script/parser.hpp>
DECLARE_INTRUSIVE_POINTER_TYPE
(
Script
);
DECLARE_INTRUSIVE_POINTER_TYPE
(
Script
);
class
Context
;
class
Context
;
...
@@ -33,17 +34,17 @@ class OptionalScript {
...
@@ -33,17 +34,17 @@ class OptionalScript {
public:
public:
~
OptionalScript
();
~
OptionalScript
();
/// Is the script set?
/// Is the script set?
inline
operator
bool
()
{
return
!!
script
;
}
inline
operator
bool
()
const
{
return
!!
script
;
}
/// Invoke the script, return the result, or script_nil if there is no script
/// Invoke the script, return the result, or script_nil if there is no script
ScriptValueP
invoke
(
Context
&
ctx
);
ScriptValueP
invoke
(
Context
&
ctx
)
const
;
/// Invoke the script on a value
/// Invoke the script on a value
/** Assigns the result to value if it has changed.
/** Assigns the result to value if it has changed.
* Returns true if the value has changed.
* Returns true if the value has changed.
*/
*/
template
<
typename
T
>
template
<
typename
T
>
bool
invokeOn
(
Context
&
ctx
,
T
&
value
)
{
bool
invokeOn
(
Context
&
ctx
,
T
&
value
)
const
{
if
(
script
)
{
if
(
script
)
{
T
new_value
;
T
new_value
;
store
(
new_value
,
script
->
invoke
(
ctx
));
store
(
new_value
,
script
->
invoke
(
ctx
));
...
@@ -59,6 +60,7 @@ class OptionalScript {
...
@@ -59,6 +60,7 @@ class OptionalScript {
ScriptP
script
;
///< The script, may be null if there is no script
ScriptP
script
;
///< The script, may be null if there is no script
String
unparsed
;
///< Unparsed script, for writing back to a file
String
unparsed
;
///< Unparsed script, for writing back to a file
DECLARE_REFLECTION
();
DECLARE_REFLECTION
();
template
<
typename
T
>
friend
class
Scriptable
;
};
};
// ----------------------------------------------------------------------------- : Scriptable
// ----------------------------------------------------------------------------- : Scriptable
...
@@ -86,5 +88,31 @@ class Scriptable {
...
@@ -86,5 +88,31 @@ class Scriptable {
DECLARE_REFLECTION
();
DECLARE_REFLECTION
();
};
};
// we need some custom io, because the behaviour is different for each of Reader/Writer/GetMember
template
<
typename
T
>
void
Reader
::
handle
(
Scriptable
<
T
>&
s
)
{
handle
(
s
.
script
.
unparsed
);
if
(
starts_with
(
s
.
script
.
unparsed
,
_
(
"script:"
)))
{
s
.
script
.
script
=
parse
(
s
.
script
.
unparsed
);
}
else
{
handle
(
value
);
}
}
template
<
typename
T
>
void
Writer
::
handle
(
const
Scriptable
<
T
>&
s
)
{
if
(
s
.
script
)
{
handle
(
s
.
script
);
}
else
{
handle
(
s
.
value
);
}
}
template
<
typename
T
>
void
GetDefaultMember
::
handle
(
const
Scriptable
<
T
>&
s
)
{
// just handle as the value
handle
(
s
.
value
);
}
// ----------------------------------------------------------------------------- : EOF
// ----------------------------------------------------------------------------- : EOF
#endif
#endif
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