From ca23dd2b957d6b432ccce3ea52ee78a3ebb56f6b Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sun, 26 Mar 2023 22:16:44 +0700 Subject: [PATCH] =?UTF-8?q?LuaState=20push=20=D0=B4=D0=BB=D1=8F=20=D0=B2?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=BE=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/dbotthepony/kstarbound/Starbound.kt | 40 +------------ .../ru/dbotthepony/kstarbound/lua/LuaState.kt | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+), 38 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index 15e21682..c80371af 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -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 } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt index 6464e3f7..aca80c0f 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt @@ -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) { val index = this.pushTable(arraySize = if (strings is Collection) strings.size else 0)