From 36ea7b25b5e0197e63702f97707a9c1ce02f8f51 Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 17 Oct 2019 14:39:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- examples/formats/gzip.own | 21 +++++++++++++++++++++ examples/formats/json.own | 16 ++++++++++++++++ examples/formats/yaml.own | 11 +++++++++-- examples/formats/zip.own | 16 ++++++++++++++++ examples/game/minesweeper.own | 14 +++++++------- 6 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 examples/formats/gzip.own create mode 100644 examples/formats/json.own create mode 100644 examples/formats/zip.own diff --git a/README.md b/README.md index 935f8e0..dfa95af 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ OwnLang - dynamic functional programming language inspired by Scala and Python. | Free | Pro | Desktop | | :--: | :-: | :-----: | -| [![Free](https://developer.android.com/images/brand/en_generic_rgb_wo_45.png)](https://play.google.com/store/apps/details?id=com.annimon.ownlang.free) | [![Pro](https://developer.android.com/images/brand/en_generic_rgb_wo_45.png)](https://play.google.com/store/apps/details?id=com.annimon.ownlang) | [v1.4.0](https://github.com/aNNiMON/Own-Programming-Language-Tutorial/releases/tag/1.4.0) +| [![Free](https://developer.android.com/images/brand/en_generic_rgb_wo_45.png)](https://play.google.com/store/apps/details?id=com.annimon.ownlang.free) | [![Pro](https://developer.android.com/images/brand/en_generic_rgb_wo_45.png)](https://play.google.com/store/apps/details?id=com.annimon.ownlang) | [v1.5.0](https://github.com/aNNiMON/Own-Programming-Language-Tutorial/releases/tag/1.5.0) Also available as AUR package: diff --git a/examples/formats/gzip.own b/examples/formats/gzip.own new file mode 100644 index 0000000..08b6c14 --- /dev/null +++ b/examples/formats/gzip.own @@ -0,0 +1,21 @@ +use ["std", "gzip"] + +// println "Gzip single file" +// gzip("absolute path to file", "example.gz") + +println "Gzip bytes" +text = trim(" +Lorem ipsum dolor sit amet, consectetur adipiscing elit. In leo dui, venenatis eu eleifend ut, volutpat vitae risus. Vivamus sed massa consectetur, fermentum est ac, semper ligula. Donec vel facilisis urna. Cras scelerisque libero a pulvinar mollis. Maecenas elementum, lectus vitae ullamcorper viverra, odio justo interdum lacus, a dictum mauris lacus id neque. Donec ante nibh, ornare ac lacus at, rutrum vulputate lacus. Quisque aliquet sem sit amet nisl semper faucibus. Aenean finibus sodales est, eget efficitur nibh. Donec ut tortor ut ex auctor fringilla id sed neque. Aenean id placerat ipsum. +Etiam enim ligula, vulputate ac velit nec, accumsan blandit velit. Aenean tortor neque, ornare eu quam vel, viverra condimentum erat. In vitae mattis augue. Sed nec auctor est. Aenean in auctor lorem. Etiam non accumsan arcu. Vivamus purus massa, finibus at ultrices feugiat, congue vitae quam. +Vestibulum porttitor finibus nulla, vel mollis elit luctus vel. Phasellus ut erat ante. Praesent consectetur vulputate sem eget bibendum. Etiam porttitor magna et egestas viverra. Praesent urna eros, porttitor vitae lorem sodales, luctus sagittis velit. Donec sed aliquet nulla, ac gravida urna. Mauris at quam eros. Nam dolor lacus, laoreet vel consequat non, semper sed quam. Nunc semper interdum arcu eget iaculis. Vivamus at turpis et urna pellentesque suscipit in nec tellus. Nam sed sem ut ipsum semper imperdiet in et est. Praesent vestibulum augue a dolor consequat feugiat. Nam massa tortor, feugiat quis orci ut, blandit varius tellus. Quisque et blandit erat. +Fusce ultricies, odio scelerisque venenatis pellentesque, nisl mi vehicula mi, eu ultrices dui nisi ac elit. Nullam laoreet et lacus ac fringilla. Morbi pretium, eros non facilisis bibendum, nisl ex ultricies ipsum, sed sodales est felis vel eros. Suspendisse lobortis lectus scelerisque turpis dapibus, et tristique neque faucibus. Donec sed tellus id augue molestie tempus ac in urna. Morbi accumsan velit in erat ultricies, vitae ultricies nulla viverra. Pellentesque non euismod purus. Pellentesque vitae consequat orci. Pellentesque in nulla pulvinar, blandit leo sed, vehicula quam. Cras finibus libero ut diam aliquam efficitur. Vestibulum rutrum tincidunt posuere. Integer ultricies rutrum libero vitae pellentesque. Nulla blandit ipsum sit amet aliquet venenatis. Maecenas cursus massa quis massa posuere eleifend. Morbi vel lorem luctus, efficitur nibh id, sagittis tortor. Maecenas tristique suscipit dui vel congue. +") +bytesOriginal = getBytes(text) +bytesGzipped = gzipBytes(bytesOriginal) + +println "Original bytes count: " + bytesOriginal.length +println "Gzipped bytes count: " + bytesGzipped.length + +println "Ungzip" +ungzippedBytes = ungzipBytes(bytesGzipped) +println stringFromBytes(ungzippedBytes) \ No newline at end of file diff --git a/examples/formats/json.own b/examples/formats/json.own new file mode 100644 index 0000000..49a76e4 --- /dev/null +++ b/examples/formats/json.own @@ -0,0 +1,16 @@ +use "json" + +data = { + "name": "Json Example", + "version": 1, + "arrayData": [ + 1, 2, 3, 4 + ], + "objectData": { + "key": "value", + 10: "1000" + } +} +println "Json encode" +println "Minified: " + jsonencode(data) +println "Pretty-print: " + jsonencode(data, 2) diff --git a/examples/formats/yaml.own b/examples/formats/yaml.own index cd2c08d..0778ad7 100644 --- a/examples/formats/yaml.own +++ b/examples/formats/yaml.own @@ -1,7 +1,6 @@ use "yaml" -println "Yaml encode" -println yamlencode({ +data = { "name": "Yaml Example", "version": 1, "arrayData": [ @@ -11,6 +10,14 @@ println yamlencode({ "key": "value", 10: "1000" } +} +println "Yaml encode" +println yamlencode(data) +println "Yaml encode with options" +println yamlencode(data, { + "indent": 6, + "prettyFlow": true, + "defaultFlowStyle": "BLOCK" }) println "\nYaml decode" diff --git a/examples/formats/zip.own b/examples/formats/zip.own new file mode 100644 index 0000000..b3e3db1 --- /dev/null +++ b/examples/formats/zip.own @@ -0,0 +1,16 @@ +use "zip" + +// println "Zip single file" +// zip("absolute path to file", "example.zip") + +println "Zip files" +zipFiles(["json.own", "yaml.own", "zip.own"], "example1.zip") + +println "Zip files" +zipFiles({ + "json.own": "json.txt", + "yaml.own": "yaml/yaml.own", + "zip.own": "readme.md"}, "example2.zip") + +println "List zip entries" +println listZipEntries("example2.zip").joinToString(", ") diff --git a/examples/game/minesweeper.own b/examples/game/minesweeper.own index 1b99cf1..596701f 100644 --- a/examples/game/minesweeper.own +++ b/examples/game/minesweeper.own @@ -7,11 +7,11 @@ use "canvasfx" CELL_NONE = -100 CELL_MINE = -200 // Colors -BACKGROUND_COLOR = Color.new(#FF283593) -OPENED_CELL_COLOR = Color.new(0xFF9FA8DA) -DEFAULT_CELL_COLOR = Color.new(#FF5C6BC0) -MINE_CELL_COLOR = Color.new(#FF1A237E) -FLAG_COLOR = Color.new(#FF7A231E) +BACKGROUND_COLOR = Color.`new`(#FF283593) +OPENED_CELL_COLOR = Color.`new`(0xFF9FA8DA) +DEFAULT_CELL_COLOR = Color.`new`(#FF5C6BC0) +MINE_CELL_COLOR = Color.`new`(#FF1A237E) +FLAG_COLOR = Color.`new`(#FF7A231E) // Parameters WIDTH = 400 HEIGHT = 400 @@ -73,7 +73,7 @@ def drawGameTable(showBombs = false) { def drawWin() { drawGameTable(true) - g.setFill(Color.new(#60FFFFFF)) + g.setFill(Color.`new`(#60FFFFFF)) g.fillRect(0, 0, WIDTH, HEIGHT) g.setFill(Color.DARKGREEN) g.fillText("YOU WIN", WIDTH / 2, HEIGHT / 2) @@ -81,7 +81,7 @@ def drawWin() { def drawGameOver() { drawGameTable(true) - g.setFill(Color.new(#60000000)) + g.setFill(Color.`new`(#60000000)) g.fillRect(0, 0, WIDTH, HEIGHT) g.setFill(Color.PINK) g.fillText("Game Over", WIDTH / 2, HEIGHT / 2)