Create smnp.lang package with basic get() methods for map and list
This commit is contained in:
@@ -19,7 +19,7 @@ abstract class Function(val name: String) {
|
||||
.firstOrNull { (_, args) -> args.signatureMatched }
|
||||
?: throw FunctionInvocationException(this, arguments)
|
||||
|
||||
return definition.body(environment, args.arguments)
|
||||
return definition.body(environment, arguments.toList())
|
||||
}
|
||||
|
||||
val signature: String
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.smnp.environment
|
||||
|
||||
import io.smnp.ext.ModuleRegistry
|
||||
import io.smnp.type.module.Module
|
||||
|
||||
class Environment {
|
||||
@@ -7,7 +8,10 @@ class Environment {
|
||||
private val loadedModules = mutableListOf<String>()
|
||||
|
||||
fun loadModule(path: String) {
|
||||
|
||||
ModuleRegistry.requestModulesForPath(path).forEach {
|
||||
rootModule.addSubmodule(it)
|
||||
loadedModules.add(path)
|
||||
}
|
||||
}
|
||||
|
||||
fun printModules(printContent: Boolean) {
|
||||
|
||||
3
api/src/main/kotlin/io/smnp/error/RuntimeException.kt
Normal file
3
api/src/main/kotlin/io/smnp/error/RuntimeException.kt
Normal file
@@ -0,0 +1,3 @@
|
||||
package io.smnp.error
|
||||
|
||||
class RuntimeException(message: String?) : Exception(message)
|
||||
21
api/src/main/kotlin/io/smnp/ext/ModuleRegistry.kt
Normal file
21
api/src/main/kotlin/io/smnp/ext/ModuleRegistry.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
package io.smnp.ext
|
||||
|
||||
import io.smnp.type.module.Module
|
||||
import org.pf4j.DefaultPluginManager
|
||||
|
||||
object ModuleRegistry {
|
||||
private val modules = mutableListOf<Pair<String, Module>>()
|
||||
init {
|
||||
val pluginManager = DefaultPluginManager()
|
||||
pluginManager.loadPlugins()
|
||||
pluginManager.startPlugins()
|
||||
|
||||
pluginManager.getExtensions(ModuleDefinition::class.java).forEach {
|
||||
modules.add(Pair(it.modulePath(), Module.create(it.modulePath(), it.functions(), it.methods())))
|
||||
}
|
||||
}
|
||||
|
||||
fun requestModulesForPath(path: String): List<Module> {
|
||||
return modules.filter { it.first == path }.map { it.second }
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import io.smnp.data.entity.Note
|
||||
import io.smnp.error.ShouldNeverReachThisLineException
|
||||
import io.smnp.type.enumeration.DataType
|
||||
|
||||
class Value private constructor(val type: DataType, val value: Any?, val properties: Map<String, Value> = emptyMap()) {
|
||||
data class Value(val type: DataType, val value: Any?, val properties: Map<String, Value> = emptyMap()) {
|
||||
init {
|
||||
if(!type.isInstance(value)) {
|
||||
throw RuntimeException("'$value' is not of type $type")
|
||||
|
||||
Reference in New Issue
Block a user