Skip to content

Commit

Permalink
ScriptedInfo|Default Style: Use a 'self' variable consistently
Browse files Browse the repository at this point in the history
Embedded scripts in a ScriptedInfo document would use the special
'__this__' variable to refer to the current object. This was changed
to 'self' to be consistent with the new class mechanism.
  • Loading branch information
skyjake committed Jun 20, 2014
1 parent 2fd2241 commit 77015d2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
7 changes: 4 additions & 3 deletions doomsday/client/data/defaultstyle.pack/fonts.dei
Expand Up @@ -89,7 +89,7 @@ group {
}

font title inherits default {
size $: gui.scale(__this__.size, 1.75)
size $: gui.scale(self.size, 1.75)
weight: light
}

Expand All @@ -98,7 +98,7 @@ font heading inherits title {
}

font small inherits default {
size $: gui.scale(__this__.size, 0.75)
size $: gui.scale(self.size, 0.75)
}

group editor {
Expand All @@ -111,11 +111,12 @@ group editor {

group separator {
font empty inherits default {
size $: gui.scale(__this__.size, 0.5)
size $: gui.scale(self.size, 0.5)
}
font label inherits small {
weight: bold
}
font annotation inherits small {}
}

group choice {
Expand Down
22 changes: 11 additions & 11 deletions doomsday/libcore/src/scriptsys/scriptedinfo.cpp
Expand Up @@ -98,9 +98,9 @@ DENG2_PIMPL(ScriptedInfo)
{
Record &ns = process.globals();

// The global "__this__" will point to the block where the script
// is running.
bool needRemoveThis = false;
// The global "self" variable will point to the block where the script
// is running (analogous to "self" in class member calling).
bool needRemoveSelf = false;
if(context)
{
String varName = variableName(*context);
Expand All @@ -111,17 +111,17 @@ DENG2_PIMPL(ScriptedInfo)
// If it doesn't exist yet, make sure it does.
ns.addRecord(varName);
}
ns.add("__this__") = new RecordValue(ns.subrecord(varName));
needRemoveThis = true;
ns.add("self") = new RecordValue(ns.subrecord(varName));
needRemoveSelf = true;
}
}

// Execute the current script.
process.execute();

if(needRemoveThis)
if(needRemoveSelf)
{
delete &ns["__this__"];
delete &ns["self"];
}
}

Expand Down Expand Up @@ -339,10 +339,10 @@ DENG2_PIMPL(ScriptedInfo)
}

/**
* Constructs a Value from the value of an element. If the element value
* has been marked with the semantic hint for scripting, it will be
* evaluated as a script. The global __this__ will be pointed to the
* Record representing the @a context block.
* Constructs a Value from the value of an element. If the element value has been
* marked with the semantic hint for scripting, it will be evaluated as a script. A
* global "self" variable will be pointed to the Record representing the @a context
* block.
*
* @param rawValue Value of an element.
* @param context Containing block element.
Expand Down
10 changes: 5 additions & 5 deletions doomsday/tests/test_info/test_info.dei
Expand Up @@ -33,7 +33,7 @@ thing A {

thing B inherits A {
member2: value from B
script { print "Contents of B:"; print __this__ }
script { print "Contents of B:"; print self }
}

group {
Expand All @@ -42,12 +42,12 @@ group {

thing C {
member2: value from C
script { print "Contents of C:"; print __this__ }
script { print "Contents of C:"; print self }
}
thing D inherits B {
# Inherits A from group, then B.
member3: value from D
script { print "Contents of D:"; print __this__ }
script { print "Contents of D:"; print self }
}
}

Expand All @@ -67,15 +67,15 @@ group font {

script {
print "Default font:"
print __this__
print self
}
}

# Identifiers retain case in script namespaces (and are case
# sensitive), however group types are forced lower case (FoNt==font).
FoNt "Title" inherits font.Default {
SIZE: 24pt
weight $: if __this__.weight == "normal": "bold"; else: "normal"
weight $: if self.weight == "normal": "bold"; else: "normal"
}
}

Expand Down

0 comments on commit 77015d2

Please sign in to comment.