Add cached builtin and unignore ScriptTest cached
This commit is contained in:
1 parent
f9c29e742a
commit
2e9e0921bf
2 files changed
+30
-22
No files matched your search
@@ -346,6 +346,23 @@ class Script(
|
||||
addFn("run") {
|
||||
requireOnlyArg<Statement>().execute(this)
|
||||
}
|
||||
addFn("cached") {
|
||||
val builder = requireOnlyArg<Statement>()
|
||||
val capturedScope = this
|
||||
var calculated = false
|
||||
var cachedValue: Obj = ObjVoid
|
||||
val thunk = object : Statement() {
|
||||
override val pos: Pos = Pos.builtIn
|
||||
override suspend fun execute(scope: Scope): Obj {
|
||||
if (!calculated) {
|
||||
cachedValue = builder.execute(capturedScope)
|
||||
calculated = true
|
||||
}
|
||||
return cachedValue
|
||||
}
|
||||
}
|
||||
thunk
|
||||
}
|
||||
|
||||
addVoidFn("delay") {
|
||||
val a = args.firstAndOnly()
|
||||
|
||||
Reference in new issue
Block a user