Skip to content

Commit 7e46151

Browse files
authored
Merge pull request #2 from ellemenno/v0.0.2
v0.0.2
2 parents a76ae30 + 3f80314 commit 7e46151

File tree

7 files changed

+81
-28
lines changed

7 files changed

+81
-28
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/releases
1+
bin/
2+
lib/build/
23
logs/
3-
lib/build
4-
test/bin
4+
releases/
5+
test/bin/
56
TEST-*.xml

LICENSE

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
The MIT License (MIT)
22

33
Copyright (c) pixeldroid
4+
https://github.com/pixeldroid/json-ls
45

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of
7+
this software and associated documentation files (the "Software"), to deal in
8+
the Software without restriction, including without limitation the rights to
9+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10+
the Software, and to permit persons to whom the Software is furnished to do so,
11+
subject to the following conditions:
1112

1213
The above copyright notice and this permission notice shall be included in all
1314
copies or substantial portions of the Software.
1415

1516
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
22-
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ json-ls
33

44
JSON helpers for Loom
55

6+
- `Json` - a utility to simplify json data access
7+
- `JsonPrinter` - a pretty printer for json data
8+
69

710
## installation
811

912
Download the library into its matching sdk folder:
1013

11-
$ curl -L -o ~/.loom/sdks/sprint33/libs/Json.loomlib \
12-
https://github.com/pixeldroid/json-ls/releases/download/v0.0.1/Json-sprint33.loomlib
14+
$ curl -L -o ~/.loom/sdks/sprint34/libs/Json.loomlib \
15+
https://github.com/pixeldroid/json-ls/releases/download/v0.0.2/Json-sprint34.loomlib
1316

1417
To uninstall, simply delete the file:
1518

16-
$ rm ~/.loom/sdks/sprint33/libs/Json.loomlib
19+
$ rm ~/.loom/sdks/sprint34/libs/Json.loomlib
1720

1821

1922
## usage
@@ -43,6 +46,49 @@ var j:Json = Json.fromObject(jsonObject);
4346
trace(JsonPrinter.print(j, JsonPrinterOptions.compact));
4447
```
4548

49+
### Json
50+
51+
Loom provides the [JSON][loom-json] class, which provides strongly typed access to values, requiring separate accessors for every data type, and two families of these accessors for retrieving from Objects or Arrays. There are 18 basic accessors, and 2 methods for determining type.
52+
53+
The `Json` class in this library aims to simplify access to json data, using the `Json` class itself as the single container type, which exposes only 3 basic accessors, and 1 more for type retrieval:
54+
55+
- `keys` - a Dictionary of Json instances, indexed by Strings
56+
- `items` - an Array of Json instances
57+
- `value` - the actual data for the instance
58+
- `type` - any basic System type, or Json
59+
* `Null`, `Boolean`, `Number`, `String`, `Vector`, `Dictionary`, `Json`
60+
61+
For comparison, the code snippets below present two ways to retrieve the second value of the nested array indexed by `r` in the following json data:
62+
63+
```json
64+
{
65+
"key": [
66+
{"a":1.23, "b":45.67},
67+
{"x":8, "y":9},
68+
{"q":[1,2], "r":[3,4], "n":null}
69+
],
70+
}
71+
```
72+
73+
> `json.json`
74+
75+
#### Using `system.JSON`
76+
77+
```ls
78+
var jsonString:String = File.loadTextFile('assets/json.json');
79+
var j:JSON = JSON.parse(jsonString);
80+
trace(j.getArray('key').getArrayObject(2).getArray('r').getArrayNumber(1));
81+
```
82+
83+
#### Using `pixeldroid.json.Json`
84+
85+
```ls
86+
var jsonString:String = File.loadTextFile('assets/json.json');
87+
var j:Json = Json.fromString(jsonString);
88+
trace(j.keys['key'].items[2].keys['r'].items[1]);
89+
```
90+
91+
4692
### JsonPrinter
4793

4894
This library includes a configurable JSON pretty-printer, with three pre-defined configurations for convenience:
@@ -116,5 +162,6 @@ Pull requests are welcome!
116162

117163

118164
[loomtasks]: https://github.com/pixeldroid/loomtasks "loomtasks"
165+
[loom-json]: http://docs.theengine.co/loom/1.1.4813/api/system/JSON.html "Loom JSON class"
119166
[JsonDemo.build]: ./test/src/JsonDemo.build "build file for the demo"
120167
[JsonDemo.ls]: ./test/src/JsonDemo.ls "source file for the demo"

lib/loom.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"sdk_version": "sprint33"
2+
"sdk_version": "sprint34"
33
}

lib/src/pixeldroid/json/Json.ls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package pixeldroid.json
66

77
public class Json
88
{
9-
public static const version:String = '0.0.1';
9+
public static const version:String = '0.0.2';
1010

1111
static public function fromString(value:String):Json
1212
{
@@ -66,7 +66,7 @@ package pixeldroid.json
6666
default :
6767
if (item.hasOwnProperty('toJson'))
6868
{
69-
var method:MethodInfo = item.getType().getMethodInfo('toJson');
69+
var method:MethodInfo = item.getType().getMethodInfoByName('toJson');
7070
if (method) json = method.invokeSingle(item, null) as Json;
7171
}
7272
break;

test/loom.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"sdk_version": "sprint33",
2+
"sdk_version": "sprint34",
33
"executable": "Main.loom",
44
"display": {
55
"width": 480,
@@ -11,4 +11,4 @@
1111
"app_id": "pixeldroid.JsonTest",
1212
"app_name": "JsonTest",
1313
"app_version": "0.0.1"
14-
}
14+
}

test/src/app/JsonTest.ls

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package
33
{
44

5+
import system.Process;
56
import system.application.ConsoleApplication;
67

78
import pixeldroid.bdd.Spec;
@@ -16,23 +17,28 @@ package
1617

1718
public class JsonTest extends ConsoleApplication
1819
{
20+
private var seed:Number = -1;
21+
private const SUCCESS:Number = 0;
22+
private const FAILURE:Number = 1;
23+
1924
override public function run():void
2025
{
2126
JsonSpec.describe();
2227
JsonPrinterSpec.describe();
2328

24-
addReporters();
29+
parseArgs();
2530

26-
Spec.execute();
31+
Process.exit(Spec.execute(seed) ? SUCCESS : FAILURE);
2732
}
2833

29-
private function addReporters():void
34+
private function parseArgs():void
3035
{
3136
var arg:String;
32-
for (var i = 2; i < CommandLine.getArgCount(); i++)
37+
for (var i = 0; i < CommandLine.getArgCount(); i++)
3338
{
3439
arg = CommandLine.getArg(i);
3540
if (arg == '--format') Spec.addReporter(reporterByName(CommandLine.getArg(++i)));
41+
if (arg == '--seed') seed = Number.fromString(CommandLine.getArg(++i));
3642
}
3743

3844
if (Spec.numReporters == 0) Spec.addReporter(new ConsoleReporter());

0 commit comments

Comments
 (0)