Skip to content
Snippets Groups Projects
Commit e7da10ae authored by syuilo's avatar syuilo
Browse files

Resolve #6242

parent f07047d1
No related branches found
No related tags found
No related merge requests found
......@@ -72,7 +72,9 @@ export default Vue.extend({
methods: {
async run() {
this.logs = [];
const aiscript = new AiScript(createAiScriptEnv(this), {
const aiscript = new AiScript(createAiScriptEnv(this, {
storageKey: 'scratchpad'
}), {
in: (q) => {
return new Promise(ok => {
this.$root.dialog({
......
import { utils, values } from '@syuilo/aiscript';
export function createAiScriptEnv(vm) {
export function createAiScriptEnv(vm, opts) {
return {
USER_ID: values.STR(vm.$store.state.i.id),
USER_USERNAME: values.STR(vm.$store.state.i.username),
......@@ -24,5 +24,14 @@ export function createAiScriptEnv(vm) {
const res = await vm.$root.api(ep.value, utils.valToJs(param), token || null);
return utils.jsToVal(res);
}),
'Mk:save': values.FN_NATIVE(([key, value]) => {
utils.assertString(key);
localStorage.setItem('aiscript:' + opts.storageKey + ':' + key.value, JSON.stringify(utils.valToJs(value)));
return values.NULL;
}),
'Mk:load': values.FN_NATIVE(([key]) => {
utils.assertString(key);
return utils.jsToVal(JSON.parse(localStorage.getItem('aiscript:' + opts.storageKey + ':' + key.value)));
}),
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment