Files
ms/packages/molang/src/parser/expressions/name.ts
MiaoWoo 6816e51239 feat: add molang package
1. upgrade bukkit chat
2. fix config update error

Signed-off-by: MiaoWoo <admin@yumc.pw>
2022-02-12 16:29:40 +08:00

48 lines
885 B
TypeScript

import { ExecutionEnvironment } from '../../env/env'
import { Expression } from '../expression'
export class NameExpression extends Expression {
type = 'NameExpression'
constructor(
public executionEnv: ExecutionEnvironment,
protected name: string,
protected isFunctionCall = false
) {
super()
}
get allExpressions() {
return []
}
setExpressionAt() {}
isStatic() {
return false
}
setPointer(value: unknown) {
this.executionEnv.setAt(this.name, value)
}
setFunctionCall(value = true) {
this.isFunctionCall = value
}
setName(name: string) {
this.name = name
}
setExecutionEnv(executionEnv: ExecutionEnvironment) {
this.executionEnv = executionEnv
}
eval() {
const value = this.executionEnv.getFrom(this.name)
if (!this.isFunctionCall && typeof value === 'function') return value()
return value
}
toString() {
return this.name
}
}