Implement some new stdlib functions and methods
This commit is contained in:
@@ -7,10 +7,11 @@ 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 io.smnp.ext.lang.method.StringifyMethod
|
||||
import org.pf4j.Extension
|
||||
|
||||
@Extension
|
||||
class LangModule : NativeModuleProvider("smnp.lang") {
|
||||
override fun functions() = listOf(IntConstructor(), NoteConstructor(), TypeOfFunction())
|
||||
override fun methods() = listOf(ListAccessMethod(), MapAccessMethod(), CharAtMethod())
|
||||
override fun methods() = listOf(ListAccessMethod(), MapAccessMethod(), CharAtMethod(), StringifyMethod())
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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.type.matcher.Matcher.Companion.anyType
|
||||
import io.smnp.type.model.Value
|
||||
|
||||
class StringifyMethod : Method(anyType(), "toString") {
|
||||
override fun define(new: MethodDefinitionTool) {
|
||||
new method simple() body { _, obj, _ ->
|
||||
Value.string(obj.stringify())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user