Skip to content

Commit

Permalink
Fix coroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
Seggan committed Dec 21, 2023
1 parent 02dcfb2 commit ca8f0a4
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ class Coroutine(state: State, chunk: Chunk.Instance, args: List<Value>) : Value
* The global metatable for coroutines.
*/
val metatable = buildTable { table ->
table["__str__"] = oneArgFunction { _ ->
table["__str__"] = oneArgFunction(true) { _ ->
"a coroutine".metisValue()
}
table["__eq__"] = twoArgFunction { self, other ->
table["__eq__"] = twoArgFunction(true) { self, other ->
Value.Boolean.of(self === other)
}
table["__contains__"] = twoArgFunction { self, key ->
table["__contains__"] = twoArgFunction(true) { self, key ->
Value.Boolean.of(self.lookUp(key) != null)
}

table["step"] = oneArgFunction { self ->
table["step"] = oneArgFunction(true) { self ->
val coroutine = self.convertTo<Coroutine>()
if (coroutine.lastResult == StepResult.FINISHED) {
"finished".metisValue()
Expand All @@ -63,10 +63,10 @@ class Coroutine(state: State, chunk: Chunk.Instance, args: List<Value>) : Value
result.name.lowercase().metisValue()
}
}
table["lastResult"] = oneArgFunction { self ->
table["lastResult"] = oneArgFunction(true) { self ->
self.convertTo<Coroutine>().lastResult.name.lowercase().metisValue()
}
table["lastYielded"] = oneArgFunction { self ->
table["lastYielded"] = oneArgFunction(true) { self ->
self.convertTo<Coroutine>().lastYielded
}

Expand Down

0 comments on commit ca8f0a4

Please sign in to comment.