LuaState push для векторов

This commit is contained in:
DBotThePony 2023-03-26 22:16:44 +07:00
parent a46fa20748
commit ca23dd2b95
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 59 additions and 38 deletions

View File

@ -369,21 +369,7 @@ class Starbound : ISBFileLocator {
}
state.setTableFunction("imageSize", this) {args ->
val (width, height) = imageSize(args.getString())
with(args.lua) {
pushTable(arraySize = 2)
val table = stackTop
push(1)
push(width)
setTableValue(table)
push(2)
push(height)
setTableValue(table)
}
args.lua.push(imageSize(args.getString()))
1
}
@ -393,29 +379,7 @@ class Starbound : ISBFileLocator {
}
state.setTableFunction("nonEmptyRegion", this) { args ->
val (x, y, z, w) = imageData(args.getString()).nonEmptyRegion
with(args.lua) {
pushTable(arraySize = 4)
val table = stackTop
push(1)
push(x)
setTableValue(table)
push(2)
push(y)
setTableValue(table)
push(3)
push(z)
setTableValue(table)
push(4)
push(w)
setTableValue(table)
}
args.lua.push(imageData(args.getString()).nonEmptyRegion)
1
}

View File

@ -21,6 +21,9 @@ import org.lwjgl.system.MemoryStack
import org.lwjgl.system.MemoryUtil
import ru.dbotthepony.kstarbound.Starbound
import ru.dbotthepony.kstarbound.io.json.InternedJsonElementAdapter
import ru.dbotthepony.kvector.vector.nint.Vector2i
import ru.dbotthepony.kvector.vector.nint.Vector3i
import ru.dbotthepony.kvector.vector.nint.Vector4i
import java.io.Closeable
import java.lang.ref.Cleaner
import java.lang.ref.WeakReference
@ -695,6 +698,60 @@ class LuaState private constructor(private val pointer: Pointer, val stringInter
LuaJNR.INSTANCE.lua_pushboolean(this.pointer, if (value) 1 else 0)
}
fun push(value: Vector4i) {
pushTable(arraySize = 4)
val table = stackTop
val (x, y, z, w) = value
push(1)
push(x)
setTableValue(table)
push(2)
push(y)
setTableValue(table)
push(3)
push(z)
setTableValue(table)
push(4)
push(w)
setTableValue(table)
}
fun push(value: Vector3i) {
pushTable(arraySize = 3)
val table = stackTop
val (x, y, z) = value
push(1)
push(x)
setTableValue(table)
push(2)
push(y)
setTableValue(table)
push(3)
push(z)
setTableValue(table)
}
fun push(value: Vector2i) {
pushTable(arraySize = 2)
val table = stackTop
val (x, y) = value
push(1)
push(x)
setTableValue(table)
push(2)
push(y)
setTableValue(table)
}
fun pushStrings(strings: Iterable<String?>) {
val index = this.pushTable(arraySize = if (strings is Collection) strings.size else 0)