Mercurial > repos > tabletprog
comparison modules/jsonEncoder.tp @ 329:eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 28 Mar 2015 13:26:03 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
328:c1fad3d93861 | 329:eef8a5cea812 |
---|---|
1 #{ | |
2 //this module exists to break a circular dependency between the json module | |
3 //and container types like dictionaries | |
4 encode <- :value { | |
5 if: (object does: value understand?: "jsonEncode") { | |
6 value jsonEncode | |
7 } else: { | |
8 toEncode <- #[] | |
9 if: (object does: value understand?: "serializeFields") { | |
10 toEncode <- value serializeFields | |
11 } else: { | |
12 toEncode <- object propertiesOf: value | |
13 } | |
14 parts <- #[] | |
15 foreach: toEncode :idx field { | |
16 fieldVal <- object sendMessage: field to: value | |
17 parts append: (field jsonEncode) . ":" . (encode: fieldVal) | |
18 } | |
19 "{" . (parts join: ",") . "}" | |
20 } | |
21 } | |
22 } |