Replace (str) with (concat)
This commit is contained in:
parent
7966b81830
commit
2d1e08cf9f
@ -13,6 +13,10 @@ function Library (ronin) {
|
|||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.open = async (path) => { // Imports a graphic file and resizes the frame.
|
||||||
|
return ronin.surface.open(path)
|
||||||
|
}
|
||||||
|
|
||||||
// Shapes
|
// Shapes
|
||||||
|
|
||||||
this.pos = (x, y, t = 'pos') => { // Returns a position shape.
|
this.pos = (x, y, t = 'pos') => { // Returns a position shape.
|
||||||
@ -62,7 +66,7 @@ function Library (ronin) {
|
|||||||
|
|
||||||
// Strings
|
// Strings
|
||||||
|
|
||||||
this.concat = function (...items) {
|
this.concat = function (...items) { // Concat multiple strings.
|
||||||
return items.reduce((acc, item) => { return `${acc}${item}` }, '')
|
return items.reduce((acc, item) => { return `${acc}${item}` }, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +227,7 @@ function Library (ronin) {
|
|||||||
return item[key]
|
return item[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
this.of = (h, ...keys) => {
|
this.of = (h, ...keys) => { // Gets object parameters with names.
|
||||||
return keys.reduce((acc, key) => {
|
return keys.reduce((acc, key) => {
|
||||||
return acc[key]
|
return acc[key]
|
||||||
}, h)
|
}, h)
|
||||||
@ -240,10 +244,6 @@ function Library (ronin) {
|
|||||||
return this.pos(rect.w / 2, rect.h / 2)
|
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.
|
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 rect = { x: 0, y: 0, w, h }
|
||||||
const a = document.createElement('img')
|
const a = document.createElement('img')
|
||||||
@ -264,7 +264,7 @@ function Library (ronin) {
|
|||||||
return ronin.surface.draw(b, rect)
|
return ronin.surface.draw(b, rect)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.crop = async (rect) => {
|
this.crop = async (rect) => { // Crop canvas to rect.
|
||||||
return ronin.surface.crop(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]
|
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
|
// 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) : []
|
return fs.existsSync(path) ? fs.readdirSync(path) : []
|
||||||
}
|
}
|
||||||
|
|
||||||
this.file = (path = ronin.source.path) => { // Returns the content of a file
|
this.file = (path = this.filepath()) => { // Returns the content of a file.
|
||||||
return fs.existsSync(path) ? fs.readFileSync(p, 'utf8') : ''
|
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)
|
return require('path').dirname(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.filepath = (path = ronin.source.path) => { // Returns the path of a file
|
this.filepath = (path = ronin.source.path) => { // Returns the path of a file.
|
||||||
return fs.existsSync(path) ? fs.readdirSync(path) : []
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
this.exit = (force = false) => { // Exits Ronin.
|
this.exit = (force = false) => { // Exits Ronin.
|
||||||
ronin.source.quit(force)
|
ronin.source.quit(force)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.echo = (...args) => {
|
||||||
|
ronin.log(args)
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
this.time = () => { // Returns timestamp in milliseconds.
|
this.time = () => { // Returns timestamp in milliseconds.
|
||||||
return Date.now()
|
return Date.now()
|
||||||
}
|
}
|
||||||
@ -368,7 +358,7 @@ function Library (ronin) {
|
|||||||
return a === b
|
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 start = Date.now()
|
||||||
const result = await fn()
|
const result = await fn()
|
||||||
console.log(`time taken: ${Date.now() - start}ms`)
|
console.log(`time taken: ${Date.now() - start}ms`)
|
||||||
|
14
examples/benchmark.fs.lisp
Normal file
14
examples/benchmark.fs.lisp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
; filesystem
|
||||||
|
(
|
||||||
|
; print path
|
||||||
|
(echo
|
||||||
|
(filepath))
|
||||||
|
; print folder path
|
||||||
|
(echo
|
||||||
|
(dirpath))
|
||||||
|
; print file content
|
||||||
|
(echo
|
||||||
|
(file))
|
||||||
|
; print folder content
|
||||||
|
(echo
|
||||||
|
(dir)))
|
@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
; Generics
|
; 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
|
; Interop
|
||||||
(test "interop" ((of (of (js) "Math") "max") 2 4) 4)
|
(test "interop" ((of (of (js) "Math") "max") 2 4) 4)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user