Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalise string coersion in Java functions #1445

Closed
SquidDev opened this issue May 17, 2023 · 0 comments
Closed

Normalise string coersion in Java functions #1445

SquidDev opened this issue May 17, 2023 · 0 comments
Labels
area-Core This affects CC's core (the Lua runtime, APIs, computer internals). area-Minecraft This affects CC's Minecraft-specific content. enhancement An extension of a feature or a new feature.
Milestone

Comments

@SquidDev
Copy link
Member

There are several functions (term.write, writing to a file handle or websocket), which accept any Lua value and convert it to a string. However, as this conversion is done in Java (after conversion from Lua values), the behaviour can be pretty confusing.

For instance, using term.write({}) on a normal computer will print {} (which uses the native terminal), while on an advanced computer (which uses multishell), you get table: 0xfffff.

We should probably standardise on the Lua representation of these strings. This is technically a breaking change, but I'm going to handwave it away by arguing that the current behaviour is buggy.

I think we probably need to make the following changes:

  • Add a new IArguments.getStringCoerced method, which calls LuaValue.toString() on the original value. This may require some extra thought to handle tostring does not obey __name.  Cobalt#69. We should probably have an Optional<T> version of this too.
  • Add some way to request these coerced values from @LuaFunctions. Maybe an annotation on the argument, or a Coerced<T> wrapper type. Not sure - there's an argument we'd want to extend this to Number-like types in the future too.
  • Convert the existing calls to StringUtil.toString to call this instead.
@SquidDev SquidDev added enhancement An extension of a feature or a new feature. area-Core This affects CC's core (the Lua runtime, APIs, computer internals). area-Minecraft This affects CC's Minecraft-specific content. labels May 17, 2023
@SquidDev SquidDev added this to the 1.105.0 milestone May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Core This affects CC's core (the Lua runtime, APIs, computer internals). area-Minecraft This affects CC's Minecraft-specific content. enhancement An extension of a feature or a new feature.
Projects
None yet
Development

No branches or pull requests

1 participant