Skip to content

Provide __tostring metamethod for built-in library functions that return userdatas #334

@hello-42

Description

@hello-42

In the past, built-in library APIs like net.request returned a table that could be pretty-printed. Now it returns a userdata in the form of <(Response)> when printed. In the spirit of improving Lune's developer experience, I think userdatas that are returned from specific built-in library functions should be encoded and decoded internally when __tostring() is called via print(userdata).

Something valuable to note:
When called, __tostring() will cause errors if the returned value's type isn't string.

I'm not sure what this means for the implementation of pretty-printed tables from userdatas, since you'll have to encode a table to a string and then decode the desired data structure back to a Luau table in order to pretty print it. My hope is there's some funny business that can be done internally to remedy that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions