question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

string.format hex conversion throws error

See original GitHub issue

NeoLua Version: 1.3.11

Converting an integer value into a range between 0x555 and 0xFFF, fails with ‘format specifier was invalid’ If I leave the value between 0 and 255, with a 2 digit conversion, it works fine, but the moment I try a 3 digit (or 4 digit) hex conversion it fails - I’m unable to see at this point whether it’s the AT.MIN.Tools formathex or sprintf causing the issue -

Ok… I’m getting closer.

Example to reproduce:

        elseif style == "HexRange" then
          val = round(tonumber(Value) * 27.3) + 1365
          Debug("Infodriver value before transform :" ..val) 
          score = string.format('%03X',tonumber(val))

Stacktrace:

9/10/2020 12:44:35 pm:SeriousError:CRITCAL ERROR:<Bold>Error Unhandled Exception:</Bold>Format specifier was invalid.
9/10/2020 12:44:35 pm:SeriousError:CRITCAL ERROR:<Bold>Trace:</Bold>   at System.Number.FormatDouble(Double value, String format, NumberFormatInfo info)
   at System.Double.ToString(String format, IFormatProvider provider)
   at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.Format(String format, Object arg0)
   at AT.MIN.Tools.FormatHex(String NativeFormat, Boolean Alternate, Int32 FieldLength, Int32 FieldPrecision, Boolean Left2Right, Char Padding, Object Value) in C:\Users\scott\Documents\GitHub\neolua\NeoLua\Extern\printf.cs:line 628
   at AT.MIN.Tools.sprintf(String Format, Object[] Parameters) in C:\Users\scott\Documents\GitHub\neolua\NeoLua\Extern\printf.cs:line 443
   at Neo.IronLua.LuaLibraryString.format(String formatstring, Object[] args) in C:\Users\scott\Documents\GitHub\neolua\NeoLua\LuaLibraries.cs:line 353
   at CallSite.Target(Closure , CallSite , Object , Object , Object )

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
neolithoscommented, Oct 9, 2020

It would be nice, if you check my changes. And let me know, if we need improvments. Or make a pull request.

0reactions
neolithoscommented, Oct 10, 2020

You are welcome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does converting between decimal and hex throw a ...
So you need to specify int instead of decimal. Because Hex format exists only for integral values. Share.
Read more >
Byte32 error, even after converting string to hex
In this line, you are trying to convert complete request body in hex not a property of it, which doesn't seem a desired...
Read more >
String.Format Method (System)
Converts the value of objects to strings based on the formats specified and inserts them into another string. If you are new to...
Read more >
FormatException Class (System)
The exception that is thrown when the format of an argument is invalid, or when a composite format string is not well formed....
Read more >
HexFormat (Java SE 17 & JDK 17)
HexFormat converts between bytes and chars and hex-encoded strings which may include additional formatting markup such as prefixes, suffixes, and delimiters ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found