-
Notifications
You must be signed in to change notification settings - Fork 195
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
Improve output of userdata, handling__tostring
and NULL
#45
Open
hishamhm
wants to merge
2
commits into
kikito:master
Choose a base branch
from
hishamhm:tostring-userdata
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When interpreting userdata values using 'inspect', the numeric identifiers are useful to match identify of pointers (comparing the low counters like `<userdata 3> is easier than reading long pointers like `userdata: 0x749abc39efa29`). However, the `NULL` pointer is enough of a special case that it is important to know when one of those numbered pointers happens to be `NULL`. When one is dealing with things like JSON parsers, where the only usual userdata is `cjson.null`, one gets accostumed over time to interpret `<userdata 1>` to mean `NULL`. This is not obvious, however, and a seasoned user will trip up the day another userdata is used in the same table and `NULL` is now `<userdata 2>`. Adding a test for this would require compiling and loading a C extension.
2 similar comments
C3pa
reviewed
Dec 27, 2024
local toStringResult = mt and getToStringResultSafely(v, mt) | ||
if toStringResult then | ||
self:puts('<userdata ', self:getId(v), '>') | ||
self:puts(' -- ', escape(toStringResult)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this. Looks a bit strange when this is printed as a table key. An example:
[<userdata 1> -- light_de_candle_14_64] = <userdata 2> -- NiNode:Light_Com_Candle_03,
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR includes 2 commits:
The first one includes evaluation of
__tostring
for userdata values. This should be safe because__tostring
of userdata is unlikely to recurse intoinspect
. A test is included.The second one adds a special case for NULL userdata.
When interpreting userdata values using 'inspect', the numeric identifiers
are useful to match identify of pointers (comparing the low counters
like
<userdata 3> is easier than reading long pointers like
userdata: 0x749abc39efa29`).However, the
NULL
pointer is enough of a special case that it isimportant to know when one of those numbered pointers happens to
be
NULL
. When one is dealing with things like JSON parsers, wherethe only usual userdata is
cjson.null
, one gets accostumed overtime to interpret
<userdata 1>
to meanNULL
. This is not obvious,however, and a seasoned user will trip up the day another userdata
is used in the same table and
NULL
is now<userdata 2>
.Adding a test for this would require compiling and loading a C extension, such as
lua-cjson
. I can do so if desired.