Add support for defining custom methods
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user