mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-27 11:57:38 +00:00
Support arguments being coerced from strings
In this case, we use Lua's tostring(x) semantics (well, modulo metamethods), instead of Java's Object.toString(x) call. This ensures that values are formatted (mostly) consistently between Lua and Java methods. - Add IArguments.getStringCoerced, which uses Lua's tostring semantics. - Add a Coerced<T> wrapper type, which says to use the .getXCoerced methods. I'm not thrilled about this interface - there's definitely an argument for using annotations - but this is probably more consistent for now. - Convert existing methods to use this call. Closes #1445
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
package dan200.computercraft.gametest
|
||||
|
||||
import dan200.computercraft.api.lua.ObjectArguments
|
||||
import dan200.computercraft.api.lua.Coerced
|
||||
import dan200.computercraft.client.gui.AbstractComputerScreen
|
||||
import dan200.computercraft.core.apis.RedstoneAPI
|
||||
import dan200.computercraft.core.apis.TermAPI
|
||||
@@ -88,7 +88,7 @@ class Computer_Test {
|
||||
@ClientGameTest
|
||||
fun Open_on_client(context: GameTestHelper) = context.sequence {
|
||||
// Write "Hello, world!" and then print each event to the terminal.
|
||||
thenOnComputer { getApi<TermAPI>().write(ObjectArguments("Hello, world!")) }
|
||||
thenOnComputer { getApi<TermAPI>().write(Coerced("Hello, world!")) }
|
||||
thenStartComputer {
|
||||
val term = getApi<TermAPI>().terminal
|
||||
while (true) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
package dan200.computercraft.gametest
|
||||
|
||||
import dan200.computercraft.api.lua.ObjectArguments
|
||||
import dan200.computercraft.api.lua.Coerced
|
||||
import dan200.computercraft.client.pocket.ClientPocketComputers
|
||||
import dan200.computercraft.core.apis.TermAPI
|
||||
import dan200.computercraft.gametest.api.*
|
||||
@@ -34,7 +34,7 @@ class Pocket_Computer_Test {
|
||||
context.givePocketComputer(unique)
|
||||
}
|
||||
// Write some text to the computer.
|
||||
thenOnComputer(unique) { getApi<TermAPI>().write(ObjectArguments("Hello, world!")) }
|
||||
thenOnComputer(unique) { getApi<TermAPI>().write(Coerced("Hello, world!")) }
|
||||
// And ensure its synced to the client.
|
||||
thenIdle(4)
|
||||
thenOnClient {
|
||||
@@ -49,7 +49,7 @@ class Pocket_Computer_Test {
|
||||
val term = getApi<TermAPI>()
|
||||
term.setCursorPos(1, 1)
|
||||
term.setCursorBlink(true)
|
||||
term.write(ObjectArguments("Updated text :)"))
|
||||
term.write(Coerced("Updated text :)"))
|
||||
}
|
||||
// And ensure the new computer state and terminal are sent.
|
||||
thenIdle(4)
|
||||
|
||||
Reference in New Issue
Block a user