Add new modules to standard library
This commit is contained in:
@@ -2,6 +2,7 @@ package io.smnp.ext.lang
|
||||
|
||||
import io.smnp.ext.NativeModuleProvider
|
||||
import io.smnp.ext.lang.function.TypeOfFunction
|
||||
import io.smnp.ext.lang.method.CharAtMethod
|
||||
import io.smnp.ext.lang.method.ListAccessMethod
|
||||
import io.smnp.ext.lang.method.MapAccessMethod
|
||||
import org.pf4j.Extension
|
||||
@@ -9,5 +10,5 @@ import org.pf4j.Extension
|
||||
@Extension
|
||||
class LangModule : NativeModuleProvider("smnp.lang") {
|
||||
override fun functions() = listOf(TypeOfFunction())
|
||||
override fun methods() = listOf(ListAccessMethod(), MapAccessMethod())
|
||||
override fun methods() = listOf(ListAccessMethod(), MapAccessMethod(), CharAtMethod())
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package io.smnp.ext.lang.method
|
||||
|
||||
import io.smnp.callable.method.Method
|
||||
import io.smnp.callable.method.MethodDefinitionTool
|
||||
import io.smnp.callable.signature.Signature.Companion.simple
|
||||
import io.smnp.error.RuntimeException
|
||||
import io.smnp.type.enumeration.DataType.INT
|
||||
import io.smnp.type.enumeration.DataType.STRING
|
||||
import io.smnp.type.matcher.Matcher.Companion.ofType
|
||||
import io.smnp.type.model.Value
|
||||
|
||||
class CharAtMethod : Method(ofType(STRING),"charAt") {
|
||||
override fun define(new: MethodDefinitionTool) {
|
||||
new method simple(ofType(INT)) body { _, obj, (index) ->
|
||||
Value.string((obj.value!! as String).getOrNull(index.value!! as Int)?.toString() ?: throw RuntimeException("Index '${index.value!!}' runs out of string bounds"))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user