AiScript関連
This commit is contained in:
@ -10,7 +10,7 @@ import i18n from '../../i18n';
|
||||
import { faHeart as faHeartS } from '@fortawesome/free-solid-svg-icons';
|
||||
import { faHeart } from '@fortawesome/free-regular-svg-icons';
|
||||
import XBlock from './page.block.vue';
|
||||
import { ASEvaluator } from '../../scripts/aiscript/evaluator';
|
||||
import { ASEvaluator } from '../../scripts/aoiscript/evaluator';
|
||||
import { collectPageVars } from '../../scripts/collect-page-vars';
|
||||
import { url } from '../../config';
|
||||
|
||||
|
@ -59,7 +59,7 @@ import { v4 as uuid } from 'uuid';
|
||||
import i18n from '../../i18n';
|
||||
import XContainer from './page-editor.container.vue';
|
||||
import MkTextarea from '../../components/ui/textarea.vue';
|
||||
import { isLiteralBlock, funcDefs, blockDefs } from '../../scripts/aiscript/index';
|
||||
import { isLiteralBlock, funcDefs, blockDefs } from '../../scripts/aoiscript/index';
|
||||
|
||||
export default Vue.extend({
|
||||
i18n,
|
||||
|
@ -98,8 +98,8 @@ import MkButton from '../../components/ui/button.vue';
|
||||
import MkSelect from '../../components/ui/select.vue';
|
||||
import MkSwitch from '../../components/ui/switch.vue';
|
||||
import MkInput from '../../components/ui/input.vue';
|
||||
import { blockDefs } from '../../scripts/aiscript/index';
|
||||
import { ASTypeChecker } from '../../scripts/aiscript/type-checker';
|
||||
import { blockDefs } from '../../scripts/aoiscript/index';
|
||||
import { ASTypeChecker } from '../../scripts/aoiscript/type-checker';
|
||||
import { url } from '../../config';
|
||||
import { collectPageVars } from '../../scripts/collect-page-vars';
|
||||
import { selectDriveFile } from '../../scripts/select-drive-file';
|
||||
|
@ -31,6 +31,7 @@ import { AiScript, parse, utils, values } from '@syuilo/aiscript';
|
||||
import i18n from '../i18n';
|
||||
import MkContainer from '../components/ui/container.vue';
|
||||
import MkButton from '../components/ui/button.vue';
|
||||
import { createAiScriptEnv } from '../scripts/create-aiscript-env';
|
||||
|
||||
export default Vue.extend({
|
||||
i18n,
|
||||
@ -71,24 +72,7 @@ export default Vue.extend({
|
||||
methods: {
|
||||
async run() {
|
||||
this.logs = [];
|
||||
const aiscript = new AiScript({
|
||||
dialog: values.FN_NATIVE(async ([title, text, type]) => {
|
||||
await this.$root.dialog({
|
||||
type: type ? type.value : 'info',
|
||||
title: title.value,
|
||||
text: text.value,
|
||||
});
|
||||
}),
|
||||
confirm: values.FN_NATIVE(async ([title, text]) => {
|
||||
const confirm = await this.$root.dialog({
|
||||
type: 'warning',
|
||||
showCancelButton: true,
|
||||
title: title.value,
|
||||
text: text.value,
|
||||
});
|
||||
return confirm.canceled ? values.FALSE : values.TRUE
|
||||
}),
|
||||
}, {
|
||||
const aiscript = new AiScript(createAiScriptEnv(this), {
|
||||
in: (q) => {
|
||||
return new Promise(ok => {
|
||||
this.$root.dialog({
|
||||
|
@ -9,7 +9,7 @@ type Fn = {
|
||||
};
|
||||
|
||||
/**
|
||||
* AiScript evaluator
|
||||
* AoiScript evaluator
|
||||
*/
|
||||
export class ASEvaluator {
|
||||
private variables: Variable[];
|
||||
@ -51,7 +51,7 @@ export class ASEvaluator {
|
||||
if (pageVar !== undefined) {
|
||||
pageVar.value = value;
|
||||
} else {
|
||||
throw new AiScriptError(`No such page var '${name}'`);
|
||||
throw new AoiScriptError(`No such page var '${name}'`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,14 +206,14 @@ export class ASEvaluator {
|
||||
const fnName = block.type;
|
||||
const fn = (funcs as any)[fnName];
|
||||
if (fn == null) {
|
||||
throw new AiScriptError(`No such function '${fnName}'`);
|
||||
throw new AoiScriptError(`No such function '${fnName}'`);
|
||||
} else {
|
||||
return fn(...block.args.map(x => this.evaluate(x, scope)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AiScriptError extends Error {
|
||||
class AoiScriptError extends Error {
|
||||
public info?: any;
|
||||
|
||||
constructor(message: string, info?: any) {
|
||||
@ -223,7 +223,7 @@ class AiScriptError extends Error {
|
||||
|
||||
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, AiScriptError);
|
||||
Error.captureStackTrace(this, AoiScriptError);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -256,7 +256,7 @@ class Scope {
|
||||
}
|
||||
}
|
||||
|
||||
throw new AiScriptError(
|
||||
throw new AoiScriptError(
|
||||
`No such variable '${name}' in scope '${this.name}'`, {
|
||||
scope: this.layerdStates
|
||||
});
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* AiScript
|
||||
* AoiScript
|
||||
*/
|
||||
|
||||
import {
|
@ -8,7 +8,7 @@ type TypeError = {
|
||||
};
|
||||
|
||||
/**
|
||||
* AiScript type checker
|
||||
* AoiScript type checker
|
||||
*/
|
||||
export class ASTypeChecker {
|
||||
public variables: Variable[];
|
28
src/client/scripts/create-aiscript-env.ts
Normal file
28
src/client/scripts/create-aiscript-env.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { utils, values } from '@syuilo/aiscript';
|
||||
|
||||
export function createAiScriptEnv(vm) {
|
||||
return {
|
||||
USER_ID: values.STR(vm.$store.state.i.id),
|
||||
USER_USERNAME: values.STR(vm.$store.state.i.username),
|
||||
'Mk:dialog': values.FN_NATIVE(async ([title, text, type]) => {
|
||||
await vm.$root.dialog({
|
||||
type: type ? type.value : 'info',
|
||||
title: title.value,
|
||||
text: text.value,
|
||||
});
|
||||
}),
|
||||
'Mk:confirm': values.FN_NATIVE(async ([title, text]) => {
|
||||
const confirm = await vm.$root.dialog({
|
||||
type: 'warning',
|
||||
showCancelButton: true,
|
||||
title: title.value,
|
||||
text: text.value,
|
||||
});
|
||||
return confirm.canceled ? values.FALSE : values.TRUE
|
||||
}),
|
||||
'Mk:api': values.FN_NATIVE(async ([ep, param, token]) => {
|
||||
const res = await vm.$root.api(ep.value, utils.valToJs(param), token || null);
|
||||
return utils.jsToVal(res);
|
||||
}),
|
||||
};
|
||||
}
|
@ -138,7 +138,7 @@ export default () => new Vuex.Store({
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
// Append a credential
|
||||
if (ctx.getters.isSignedIn) (data as any).i = ctx.state.i.token;
|
||||
if (token) (data as any).i = token;
|
||||
if (token !== undefined) (data as any).i = token;
|
||||
|
||||
// Send request
|
||||
fetch(endpoint.indexOf('://') > -1 ? endpoint : `${apiUrl}/${endpoint}`, {
|
||||
|
@ -7,4 +7,4 @@
|
||||
|
||||
ユーザーからの入力を受け取るには、ページに「ユーザー入力」ブロックを設置し、「変数名」に入力を格納したい変数名を設定します(変数は自動で作成されます)。その変数を使ってユーザー入力に応じた動作を行えます。
|
||||
|
||||
関数を使うと、値の算出処理を再利用可能な形にまとめることができます。関数を作るには、「関数」タイプの変数を作成します。関数にはスロット(引数)を設定することができ、スロットの値は関数内で変数として利用可能です。また、AiScript標準で関数を引数に取る関数(高階関数と呼ばれます)も存在します。関数は予め定義しておくほかに、このような高階関数のスロットに即席でセットすることもできます。
|
||||
関数を使うと、値の算出処理を再利用可能な形にまとめることができます。関数を作るには、「関数」タイプの変数を作成します。関数にはスロット(引数)を設定することができ、スロットの値は関数内で変数として利用可能です。また、関数を引数に取る関数(高階関数と呼ばれます)も存在します。関数は予め定義しておくほかに、このような高階関数のスロットに即席でセットすることもできます。
|
||||
|
Reference in New Issue
Block a user