Add support for defining custom methods

This commit is contained in:
2020-03-12 21:46:11 +01:00
parent e7268bf18a
commit 26d072d46f
10 changed files with 106 additions and 12 deletions

View File

@@ -11,7 +11,7 @@ import io.smnp.type.model.Value
class ListAccessMethod : Method(ofType(LIST), "get") {
override fun define(new: MethodDefinitionTool) {
new method simple(ofType(INT)) define { _, value, (index) ->
new method simple(ofType(INT)) body { _, value, (index) ->
val list = value.value!! as List<Value>
val i = index.value!! as Int

View File

@@ -11,7 +11,7 @@ import io.smnp.type.model.Value
class MapAccessMethod : Method(ofType(MAP), "get") {
override fun define(new: MethodDefinitionTool) {
new method simple(allTypes()) define { _, obj, (key) ->
new method simple(allTypes()) body { _, obj, (key) ->
val map = (obj.value!! as Map<Value, Value>)
map[key] ?: throw RuntimeException("Key '${key.value!!}' not found")
}