Skip to content

Commit dd32cd1

Browse files
committed
Fix prototype assignment
1 parent 5b777c1 commit dd32cd1

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

examples/01-objects.frank

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ a.field2 = {} # 2
1313
b = a.field1
1414
c = a["field1"]
1515

16+
# FrankenScipt uses reference counting. Values are deallocated when the reference
17+
# count hits 0. This can be used to remove unused elements from the diagram.
18+
a = None
19+
b = None
20+
c = None
21+
1622
# FrankenScript also provides stings, created by double quotes:
1723
d = "This is a string"
1824

25+
# All objects in FrankenScript are dictionaries. The language uses prototypes
26+
# to share functionality across objects and to identify the type of object.
27+
# The diagram currently shows the prototype for frame objects (called `[Frame]),
28+
# and the prototype for strings (called `[String]`).
29+
#
30+
# Prototypes can be accessed via the `__proto__` field.
31+
e = d.__proto__
32+
33+
# The prototype can also be written to. This creates an object `g` with the
34+
# prototype `f`
35+
f = {}
36+
f.field = {}
37+
g = {}
38+
g.__proto__ = f
39+
40+
# If a field is not found on an object the prototype will be checked for the
41+
# field. In this example, a reference to `f.field` is returned since `g` doesn't
42+
# have a field called `field` but the prototype has one.
43+
h = g.field

src/rt/objects/dyn_object.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ namespace rt::objects
271271
[[nodiscard]] virtual DynObject* set(std::string name, DynObject* value)
272272
{
273273
assert_modifiable();
274+
275+
if (name == PrototypeField)
276+
{
277+
return set_prototype(value);
278+
}
279+
274280
DynObject* old = fields[name];
275281
fields[name] = value;
276282
return old;

0 commit comments

Comments
 (0)