Fixed issue with prelude path in builds

This commit is contained in:
Devine Lu Linvega 2019-07-21 07:37:11 +09:00
parent a559269b2d
commit 0e7af66c16
5 changed files with 37 additions and 34 deletions

View File

@ -18,10 +18,10 @@
<body> <body>
<script type="text/javascript"> <script type="text/javascript">
const {dialog,app} = require('electron').remote; const {dialog,app} = require('electron').remote;
const fs = require('fs'); const fs = require('fs')
const app_path = app.getAppPath(); const ronin = new Ronin()
const ronin = new Ronin();
ronin.controller = new Controller(); ronin.controller = new Controller()
ronin.controller.add("default","*","About",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Dotgrid'); },"CmdOrCtrl+,"); ronin.controller.add("default","*","About",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Dotgrid'); },"CmdOrCtrl+,");
ronin.controller.add("default","*","Fullscreen",() => { app.toggleFullscreen() },"CmdOrCtrl+Enter"); ronin.controller.add("default","*","Fullscreen",() => { app.toggleFullscreen() },"CmdOrCtrl+Enter");
ronin.controller.add("default","*","Hide",() => { app.toggleVisible() },"CmdOrCtrl+H"); ronin.controller.add("default","*","Hide",() => { app.toggleVisible() },"CmdOrCtrl+H");
@ -53,9 +53,10 @@
ronin.controller.add("default","Theme","Reset Theme",() => { ronin.theme.reset() },"CmdOrCtrl+Shift+Backspace") ronin.controller.add("default","Theme","Reset Theme",() => { ronin.theme.reset() },"CmdOrCtrl+Shift+Backspace")
ronin.controller.addSpacer('default', 'Theme', 'Download') ronin.controller.addSpacer('default', 'Theme', 'Download')
ronin.controller.add("default","Theme","Download Themes..",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Themes') }) ronin.controller.add("default","Theme","Download Themes..",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Themes') })
ronin.controller.commit(); ronin.controller.commit()
ronin.install(document.body);
window.addEventListener('load', () => { ronin.start(); }) ronin.install(document.body)
window.addEventListener('load', () => { ronin.start() })
</script> </script>
</body> </body>
</html> </html>

View File

@ -33,8 +33,7 @@ function Commander (ronin) {
this.run = (txt = this._input.value) => { this.run = (txt = this._input.value) => {
if (txt.indexOf('$') > -1) { ronin.log('Present: $'); return } if (txt.indexOf('$') > -1) { ronin.log('Present: $'); return }
const inter = new Lisp(txt, ronin.library) const inter = new Lisp(txt, ronin.library, ronin.includes).run()
inter.toPixels()
ronin.always === true && requestAnimationFrame(() => this.run(txt)) ronin.always === true && requestAnimationFrame(() => this.run(txt))
} }

View File

@ -1,6 +1,6 @@
'use strict' 'use strict'
function Lisp (input, lib) { function Lisp (input, lib, includes) {
const path = require('path') const path = require('path')
const fs = require('fs') const fs = require('fs')
@ -20,7 +20,7 @@ function Lisp (input, lib) {
const special = { const special = {
include: (input, context) => { include: (input, context) => {
if (!input[1].value || !fs.existsSync(input[1].value)) { console.warn('Source', input[1].value); return [] } if (!input[1].value || !fs.existsSync(input[1].value)) { console.warn('Lisp', 'No file: ' + input[1].value); return [] }
const file = fs.readFileSync(input[1].value, { encoding: 'utf-8' }) const file = fs.readFileSync(input[1].value, { encoding: 'utf-8' })
return interpret(this.parse(`(${file})`), context) return interpret(this.parse(`(${file})`), context)
}, },
@ -69,7 +69,7 @@ function Lisp (input, lib) {
__fn: function (input, context) { __fn: function (input, context) {
return async function () { return async function () {
const lambdaArguments = arguments const lambdaArguments = arguments
const keys = [...new Set(input.slice(2).flat(100).filter(i => const keys = [...new Set(input.slice(2).flat(100).filter(i =>
i.type === TYPES.identifier && i.type === TYPES.identifier &&
i.value[0] === '%' i.value[0] === '%'
).map(x => x.value).sort())] ).map(x => x.value).sort())]
@ -82,8 +82,8 @@ function Lisp (input, lib) {
}, },
__obj: async function (input, context) { __obj: async function (input, context) {
const obj = {} const obj = {}
for (let i = 1 ; i<input.length ; i+=2) { for (let i = 1; i < input.length; i += 2) {
obj[await interpret(input[i] ,context)] = await interpret(input[i+1], context) obj[await interpret(input[i], context)] = await interpret(input[i + 1], context)
} }
return obj return obj
} }
@ -101,7 +101,7 @@ function Lisp (input, lib) {
} }
const interpret = async function (input, context) { const interpret = async function (input, context) {
if (!input) { console.warn('error', context.scope); return null } if (!input) { console.warn('Lisp', 'error', context.scope); return null }
if (context === undefined) { if (context === undefined) {
return interpret(input, new Context(lib)) return interpret(input, new Context(lib))
@ -153,26 +153,34 @@ function Lisp (input, lib) {
const tokenize = function (input) { const tokenize = function (input) {
const i = input.replace(/^\;.*\n?/gm, '').split('"') const i = input.replace(/^\;.*\n?/gm, '').split('"')
return i.map(function (x, i) { return i.map(function (x, i) {
return i % 2 === 0 ? return i % 2 === 0
x.replace(/\(/g, ' ( ') ? x.replace(/\(/g, ' ( ')
.replace(/\)/g, ' ) ') .replace(/\)/g, ' ) ')
.replace(/' \( /g, ' \'( ') // '() .replace(/' \( /g, ' \'( ') // '()
.replace(/\{/g, ' { ') // {} .replace(/\{/g, ' { ') // {}
.replace(/\}/g, ' } ') // {} .replace(/\}/g, ' } ') // {}
: x.replace(/ /g, '!whitespace!') : x.replace(/ /g, '!whitespace!')
}) })
.join('"').trim().split(/\s+/) .join('"').trim().split(/\s+/)
.map(function (x) { return x.replace(/!whitespace!/g, ' ') }) .map(function (x) { return x.replace(/!whitespace!/g, ' ') })
}
this.inc = function () {
return includes.reduce((acc, item) => {
const p = path.join(__dirname, `lisp/${item}.lisp`)
if (!fs.existsSync(p)) { console.warn('Lisp', `Missing include: ${p}`); return acc }
return `${acc}(include "${p}") `
}, '')
} }
this.parse = function (input) { this.parse = function (input) {
return parenthesize(tokenize(input)) return parenthesize(tokenize(input))
} }
this.toPixels = async function () { this.run = async function () {
return interpret(this.parse(`( return interpret(this.parse(`(
(include "./sources/lisp/prelude.lisp") ${this.inc()}
${input})`)) ${input})`))
} }
} }

View File

@ -23,6 +23,7 @@ function Ronin () {
// Parameters // Parameters
this.always = false this.always = false
this.includes = ['prelude']
this.install = function (host = document.body) { this.install = function (host = document.body) {
this._wrapper = document.createElement('div') this._wrapper = document.createElement('div')

View File

@ -126,12 +126,6 @@ function Source (ronin) {
return `${str}` return `${str}`
} }
this.locate = function (name) {
if (!this.path) { return }
const loc = path.join(this.folder(), name)
return fs.existsSync(loc) ? loc : null
}
// Etc // Etc
this.name = function () { this.name = function () {