AiScript関連

This commit is contained in:
syuilo
2020-04-12 19:38:19 +09:00
parent c62aff76af
commit f07047d1e8
12 changed files with 58 additions and 133 deletions

View File

@ -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
});

View File

@ -1,5 +1,5 @@
/**
* AiScript
* AoiScript
*/
import {

View File

@ -8,7 +8,7 @@ type TypeError = {
};
/**
* AiScript type checker
* AoiScript type checker
*/
export class ASTypeChecker {
public variables: Variable[];

View 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);
}),
};
}