-
-
Save mdboom/213e71d37a4b26c01f80e8db41b68dfe to your computer and use it in GitHub Desktop.
Iodide with PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const PHP_MODULE = 'https://oraoto.github.io/pib/php.js' | |
const loadResource = url => new Promise((resolve) => { | |
const head = document.getElementsByTagName('head')[0] | |
const theScript = document.createElement('script') | |
console.log("window.PHP " + window.PHP) | |
theScript.src = url; | |
theScript.onload = () => { | |
resolve() | |
}; | |
head.appendChild(theScript) | |
}) | |
loadResource(PHP_MODULE) | |
.then(() => { | |
window.php = {} | |
window.php.evaluate = code => { | |
code = code.replace(/^\s*<\?php/, '') | |
code = code + '\necho PHP_EOL;' | |
let ret = module.ccall('pib_eval', 'number', ['string'], [code]) | |
} | |
window.php.export = (...arguments) => { | |
if (arguments.length > 1) { | |
text = Array.prototype.slice.call(arguments).join(' ') | |
} else { | |
text = arguments | |
} | |
const elem = window.iodide.output.element('div') | |
elem.innerHTML = text | |
} | |
const options = { | |
print: window.php.export, | |
printErr: window.php.export, | |
locateFile: (path) => 'https://oraoto.github.io/pib/' + path | |
} | |
const module = PHP(options) | |
window.iodide.exportPHP = (variableName, variable) => { | |
const out = variable | |
window[variableName] = out; | |
} | |
window.iodide.addOutputHandler({ | |
shouldHandle: val => true, | |
render: (val) => { | |
return val.toString() | |
}, | |
}); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% plugin | |
{ | |
"languageId": "php", | |
"displayName": "PHP", | |
"codeMirrorMode": "php", | |
"keybinding": "php", | |
"url": "https://gist.githubusercontent.com/mdboom/213e71d37a4b26c01f80e8db41b68dfe/raw/8d348f670d670b9bdcd8e486f192cffda65ff0c6/evaluate-php.js", | |
"module": "php", | |
"evaluator": "evaluate", | |
"pluginType": "language" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment