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

View File

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

View File

@ -1,6 +1,6 @@
'use strict'
function Lisp (input, lib) {
function Lisp (input, lib, includes) {
const path = require('path')
const fs = require('fs')
@ -20,7 +20,7 @@ function Lisp (input, lib) {
const special = {
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' })
return interpret(this.parse(`(${file})`), context)
},
@ -101,7 +101,7 @@ function Lisp (input, lib) {
}
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) {
return interpret(input, new Context(lib))
@ -154,8 +154,8 @@ function Lisp (input, lib) {
const tokenize = function (input) {
const i = input.replace(/^\;.*\n?/gm, '').split('"')
return i.map(function (x, i) {
return i % 2 === 0 ?
x.replace(/\(/g, ' ( ')
return i % 2 === 0
? x.replace(/\(/g, ' ( ')
.replace(/\)/g, ' ) ')
.replace(/' \( /g, ' \'( ') // '()
.replace(/\{/g, ' { ') // {}
@ -166,13 +166,21 @@ function Lisp (input, lib) {
.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) {
return parenthesize(tokenize(input))
}
this.toPixels = async function () {
this.run = async function () {
return interpret(this.parse(`(
(include "./sources/lisp/prelude.lisp")
${this.inc()}
${input})`))
}
}

View File

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

View File

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