com.skillw.asahi.internal.namespacing.infix.linking.InfixArray.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Pouvoir Show documentation
Show all versions of Pouvoir Show documentation
Bukkit Script Engine Plugin.
package com.skillw.asahi.internal.namespacing.infix.linking
import com.skillw.asahi.api.annotation.AsahiInfix
import com.skillw.asahi.api.member.parser.infix.namespacing.BaseInfix
/**
* @className ActionArray
*
* @author Glom
* @date 2022/8/9 16:26 Copyright 2022 user.
*/
@AsahiInfix
internal object InfixArray : BaseInfix>(Array::class.java) {
init {
//添加后缀动作 这个obj是当前操作的对象
infix("get") { obj ->
//预期下一个Token是 "at"
expect("at")
// 获取一个Int
val index = parse()
//返回结果
return@infix obj[index]
}
infix("set") { obj ->
obj as? Array ?: error("The tokenizer should be a Array")
expect("at")
val index = parse()
expect("to")
val value = parse()
obj[index] = value
return@infix value
}
infix("length") { it.size }
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy