diff --git a/luna/src/main/java/org/classdump/luna/LuaFormat.java b/luna/src/main/java/org/classdump/luna/LuaFormat.java index a0baaefa..baea29e8 100644 --- a/luna/src/main/java/org/classdump/luna/LuaFormat.java +++ b/luna/src/main/java/org/classdump/luna/LuaFormat.java @@ -172,8 +172,12 @@ public final class LuaFormat { private static ByteString finiteDoubleToByteString(double f) { // f assumed not to be NaN or infinite - // TODO: check precision used in Lua - // TODO: don't go via java.lang.String + + // Lua 5.2 compat + if (Math.abs(f) % 1.0 <= 0.000000001) { + return ByteString.of(Long.toString((long) f)); + } + String s = Double.toString(f).toLowerCase(); return ByteString.of(s); } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemDescriptor.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemDescriptor.kt index 86e06b8c..eb492f5d 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemDescriptor.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemDescriptor.kt @@ -18,25 +18,23 @@ import org.classdump.luna.Table import org.classdump.luna.TableFactory import org.classdump.luna.runtime.ExecutionContext import ru.dbotthepony.kommons.gson.contains -import ru.dbotthepony.kommons.util.KOptional -import ru.dbotthepony.kstarbound.lua.StateMachine -import ru.dbotthepony.kstarbound.lua.from import ru.dbotthepony.kommons.gson.get -import ru.dbotthepony.kommons.gson.set import ru.dbotthepony.kommons.gson.value import ru.dbotthepony.kommons.io.StreamCodec import ru.dbotthepony.kommons.io.readVarLong import ru.dbotthepony.kommons.io.writeBinaryString import ru.dbotthepony.kommons.io.writeVarLong +import ru.dbotthepony.kommons.util.KOptional import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.VersionRegistry import ru.dbotthepony.kstarbound.io.readInternedString import ru.dbotthepony.kstarbound.item.ItemRegistry import ru.dbotthepony.kstarbound.item.ItemStack -import ru.dbotthepony.kstarbound.json.mergeJson import ru.dbotthepony.kstarbound.json.readJsonElement import ru.dbotthepony.kstarbound.json.writeJsonElement import ru.dbotthepony.kstarbound.lua.LuaEnvironment +import ru.dbotthepony.kstarbound.lua.StateMachine +import ru.dbotthepony.kstarbound.lua.from import ru.dbotthepony.kstarbound.lua.get import ru.dbotthepony.kstarbound.lua.indexNoYield import ru.dbotthepony.kstarbound.lua.toJson diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/BinaryJsonWriter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/BinaryJsonWriter.kt index f759d55f..c6cf422f 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/BinaryJsonWriter.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/json/BinaryJsonWriter.kt @@ -9,6 +9,7 @@ import ru.dbotthepony.kommons.io.writeBinaryString import ru.dbotthepony.kommons.io.writeSignedVarLong import ru.dbotthepony.kommons.io.writeVarInt import java.io.DataOutputStream +import kotlin.math.absoluteValue fun DataOutputStream.writeJsonElement(value: JsonElement) { when (value) { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/Conversions.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/Conversions.kt index 4b48ae11..746df9d2 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/Conversions.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/Conversions.kt @@ -187,7 +187,7 @@ fun TableFactory.from(value: JsonElement?): Any? { when (value) { is JsonPrimitive -> { if (value.isNumber) { - return value.asDouble + return value.asNumber } else if (value.isString) { return ByteString.of(value.asString) } else if (value.isBoolean) {