Repository navigation
Conversation
log_error, log_warn and log_info are declared in API.h as C variadic functions. Bound straight through, calling one from Lua with a colon passes self as the first argument, so the struct pointer lands in the format parameter and printf starts reading it as a format string. That is an access violation, not a Lua error, so pcall does not catch it. On a live game uevr.params.functions:log_info("...") killed the process while the script was still loading.
The wrappers now take a ready string and pass it as an argument to a %s format, so percent signs in the text are harmless and the colon syntax keeps working.
print was never bound, so the stock implementation ran and wrote to a stdout the game does not have. No script output ever reached log.txt, and there was no error either, which is easy to mistake for the script not running at all. ScriptContext::log already writes to OutputDebugStringA, stderr and API::log_info with a safe %s format, it was only used internally. print goes through it now. Arguments are stringified by Lua's own tostring, so any type works and arguments are tab separated, same as stock print. Also adds a global log table with info, warn and error, since the warn and error levels had no safe route from a script.
This file contains hidden or 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
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.
Two things that bite anyone writing Lua for UEVR. One file, one commit each, and they are
independent if you only want one of them.
printdid nothingThere is no binding for it, so the stock implementation runs and writes to a stdout the game
does not have. Nothing reaches log.txt and there is no error either. It just looks like the
script never ran, which is an easy hour to lose.
lua-api/examples/hello_world.luais built almost entirely onprint, so the example thatships with the repo currently produces no output at all.
ScriptContext::logalready does the right thing (OutputDebugStringA, stderr, andAPI::log_infowith a%sformat), it was only used internally.printnow goes throughit. Arguments are stringified by Lua's own
tostring, so any type works and arguments aretab separated, same as stock print.
log_infocrashes if you call it the usual wayThe three fields are declared in API.h as C variadics:
They were bound straight through, so this kills the process:
These are struct fields, not methods, so sol uses the object only to fetch the pointer and
then forwards whatever Lua passed. The colon adds the object as an extra first argument, so
the format parameter gets something that is not a format string and printf reads it as one.
It is an access violation rather than a Lua error, so
pcalldoes not help and the log endsmid-line. With a dot it works, but the message itself is the format string, so any
%in itis a landmine.
The wrappers now take a ready string and pass it as an argument to
"%s". Percent signs inthe text are harmless and the colon syntax keeps working.
Also adds a global
logtable withinfo,warnanderror, since the warn and errorlevels had no safe route at all. If a global is too much, say so and I will move it under
uevr.Tested
Release build, The Outer Worlds 2 (UE5). Before:
functions:log_info("...")took the gamedown while the script was still loading, and no
printoutput ever appeared in log.txt.After: both write to log.txt, and a
%in the message no longer matters. Been running onit daily for a couple of weeks.