From 2d1e08cf9f047beff2d288efeb6a8ea1ed637d79 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sat, 20 Jul 2019 19:37:32 +0900 Subject: [PATCH] Replace (str) with (concat) --- desktop/sources/scripts/library.js | 48 ++++++++++---------------- examples/benchmark.fs.lisp | 14 ++++++++ examples/benchmark.lisp | 2 +- examples/{fs.lisp => random.file.lisp} | 0 4 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 examples/benchmark.fs.lisp rename examples/{fs.lisp => random.file.lisp} (100%) diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index f9cf304..4c9e399 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -13,6 +13,10 @@ function Library (ronin) { return path } + this.open = async (path) => { // Imports a graphic file and resizes the frame. + return ronin.surface.open(path) + } + // Shapes this.pos = (x, y, t = 'pos') => { // Returns a position shape. @@ -62,7 +66,7 @@ function Library (ronin) { // Strings - this.concat = function (...items) { + this.concat = function (...items) { // Concat multiple strings. return items.reduce((acc, item) => { return `${acc}${item}` }, '') } @@ -223,7 +227,7 @@ function Library (ronin) { return item[key] } - this.of = (h, ...keys) => { + this.of = (h, ...keys) => { // Gets object parameters with names. return keys.reduce((acc, key) => { return acc[key] }, h) @@ -240,10 +244,6 @@ function Library (ronin) { return this.pos(rect.w / 2, rect.h / 2) } - this.scale = (rect, w, h) => { - return { x: rect.x, y: rect.y, w: rect.w * w, h: rect.h * h } - } - this.resize = async (w, h, fit = true) => { // Resizes the canvas to target w and h, returns the rect. const rect = { x: 0, y: 0, w, h } const a = document.createElement('img') @@ -264,7 +264,7 @@ function Library (ronin) { return ronin.surface.draw(b, rect) } - this.crop = async (rect) => { + this.crop = async (rect) => { // Crop canvas to rect. return ronin.surface.crop(rect) } @@ -310,43 +310,33 @@ function Library (ronin) { return [pixel.r * q + intercept, pixel.g * q + intercept, pixel.b * q + intercept, pixel.a] } - // Misc - - this.echo = (...args) => { - ronin.log(args) - return args - } - - this.str = (...args) => { - return args.reduce((acc, val) => { return acc + val }, '') - } - - this.open = async (path) => { // Imports a graphic file and resizes the frame. - return ronin.surface.open(path) - } - // File System - this.dir = (path = ronin.source.path) => { // Returns the content of a directory. + this.dir = (path = this.dirpath()) => { // Returns the content of a directory. return fs.existsSync(path) ? fs.readdirSync(path) : [] } - this.file = (path = ronin.source.path) => { // Returns the content of a file - return fs.existsSync(path) ? fs.readFileSync(p, 'utf8') : '' + this.file = (path = this.filepath()) => { // Returns the content of a file. + return fs.existsSync(path) ? fs.readFileSync(path, 'utf8') : '' } - this.dirpath = (path = ronin.source.path) => { // Returns the path of a directory. + this.dirpath = (path = this.filepath()) => { // Returns the path of a directory. return require('path').dirname(path) } - this.filepath = (path = ronin.source.path) => { // Returns the path of a file - return fs.existsSync(path) ? fs.readdirSync(path) : [] + this.filepath = (path = ronin.source.path) => { // Returns the path of a file. + return path } this.exit = (force = false) => { // Exits Ronin. ronin.source.quit(force) } + this.echo = (...args) => { + ronin.log(args) + return args + } + this.time = () => { // Returns timestamp in milliseconds. return Date.now() } @@ -368,7 +358,7 @@ function Library (ronin) { return a === b } - this.benchmark = async (fn) => { // logs time taken to execute a function + this.benchmark = async (fn) => { // logs time taken to execute a function. const start = Date.now() const result = await fn() console.log(`time taken: ${Date.now() - start}ms`) diff --git a/examples/benchmark.fs.lisp b/examples/benchmark.fs.lisp new file mode 100644 index 0000000..cd80cef --- /dev/null +++ b/examples/benchmark.fs.lisp @@ -0,0 +1,14 @@ +; filesystem +( + ; print path + (echo + (filepath)) + ; print folder path + (echo + (dirpath)) + ; print file content + (echo + (file)) + ; print folder content + (echo + (dir))) \ No newline at end of file diff --git a/examples/benchmark.lisp b/examples/benchmark.lisp index 70832bf..1e0d5da 100644 --- a/examples/benchmark.lisp +++ b/examples/benchmark.lisp @@ -53,7 +53,7 @@ ; Generics - (test "str" (str 1 4 "-" (add 3 4) ".jpg") "14-7.jpg") + (test "concat" (concat 1 4 "-" (add 3 4) ".jpg") "14-7.jpg") ; Interop (test "interop" ((of (of (js) "Math") "max") 2 4) 4) diff --git a/examples/fs.lisp b/examples/random.file.lisp similarity index 100% rename from examples/fs.lisp rename to examples/random.file.lisp