Intern strings originating from Lua

This commit is contained in:
DBotThePony 2024-05-22 19:02:19 +07:00
parent e81079479b
commit 8eb1db919f
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -29,6 +29,7 @@ import ru.dbotthepony.kstarbound.math.vector.Vector2i
import ru.dbotthepony.kstarbound.json.InternedJsonElementAdapter import ru.dbotthepony.kstarbound.json.InternedJsonElementAdapter
import ru.dbotthepony.kstarbound.math.AABBi import ru.dbotthepony.kstarbound.math.AABBi
import ru.dbotthepony.kstarbound.math.Line2d import ru.dbotthepony.kstarbound.math.Line2d
import ru.dbotthepony.kstarbound.util.sbIntern
import ru.dbotthepony.kstarbound.world.physics.Poly import ru.dbotthepony.kstarbound.world.physics.Poly
fun ExecutionContext.toVector2i(table: Any): Vector2i { fun ExecutionContext.toVector2i(table: Any): Vector2i {
@ -122,8 +123,8 @@ fun ExecutionContext.toAABBi(table: Any): AABBi {
fun toJsonFromLua(value: Any?): JsonElement { fun toJsonFromLua(value: Any?): JsonElement {
return when (value) { return when (value) {
null, is JsonNull -> JsonNull.INSTANCE null, is JsonNull -> JsonNull.INSTANCE
is String -> JsonPrimitive(value) is String -> JsonPrimitive(value.sbIntern())
is ByteString -> JsonPrimitive(value.decode()) is ByteString -> JsonPrimitive(value.decode().sbIntern())
is Number -> JsonPrimitive(value) is Number -> JsonPrimitive(value)
is Boolean -> InternedJsonElementAdapter.of(value) is Boolean -> InternedJsonElementAdapter.of(value)
is Table -> value.toJson() is Table -> value.toJson()