Add Scope.requireClass helper for stdlib binding
This commit is contained in:
parent
d8d2eff436
commit
3f2c38c471
@ -898,4 +898,10 @@ open class Scope(
|
|||||||
fun new(): Scope =
|
fun new(): Scope =
|
||||||
Script.defaultImportManager.copy().newModuleAt(Pos.builtIn)
|
Script.defaultImportManager.copy().newModuleAt(Pos.builtIn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun requireClass(name: String): net.sergeych.lyng.obj.ObjClass {
|
||||||
|
val rec = get(name) ?: raiseSymbolNotFound(name)
|
||||||
|
return rec.value as? net.sergeych.lyng.obj.ObjClass
|
||||||
|
?: raiseClassCastError("Expected class $name, got ${rec.value.objClass.className}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -563,9 +563,7 @@ class Script(
|
|||||||
ImportManager(rootScope, SecurityManager.allowAll).apply {
|
ImportManager(rootScope, SecurityManager.allowAll).apply {
|
||||||
addPackage("lyng.stdlib") { module ->
|
addPackage("lyng.stdlib") { module ->
|
||||||
module.eval(Source("lyng.stdlib", rootLyng))
|
module.eval(Source("lyng.stdlib", rootLyng))
|
||||||
val cls = module["KotlinIterator"]?.value as? ObjClass
|
ObjKotlinIterator.bindTo(module.requireClass("KotlinIterator"))
|
||||||
?: module.raiseSymbolNotFound("KotlinIterator")
|
|
||||||
ObjKotlinIterator.bindTo(cls)
|
|
||||||
}
|
}
|
||||||
addPackage("lyng.buffer") {
|
addPackage("lyng.buffer") {
|
||||||
it.addConstDoc(
|
it.addConstDoc(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user