Lua string.format

Started by garry23, May 05, 2017, 09:33:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

garry23

I hope some kind soul can put me out of my misery, as I've not used string.format before.

I've read up on line and I think I'm doing things correctly.

'All' I'm trying to do is format a string to print: here is the demo code:

b_diff = 45.6577
info_message = string.format("Blur_Diff = %f", b_diff )


But all I get back when I print is

Blur_Diff = f

I've tried %0.2f and still get the same as above.

Where am I going wrong?

chris_overseas

What happens if you use %%f instead of just %f? This is just a guess and I don't know Lua, but based on your output it seems like there's an escape issue of some sort.
EOS R5 1.1.0 | Canon 16-35mm f4.0L | Tamron SP 24-70mm f/2.8 Di VC USD G2 | Canon 70-200mm f2.8L IS II | Canon 100-400mm f4.5-5.6L II | Canon 800mm f5.6L | Canon 100mm f2.8L macro | Sigma 14mm f/1.8 DG HSM Art | Yongnuo YN600EX-RT II

dmilligan

Canon's printf() implementation is not standards compliant and does not support %f (amongst various other things). I suppose you are using the main nightly builds, and I suppose they are still using Canon's printf (it was fixed to use our own standards compliant libc implementation, but that was so long ago, I don't remember if it has made it into unified).

garry23

@dmilligan

David

Through trail and error I worked out that it wasn't implemented, so have solved my needs through another approach.

I'll publish my script soon, which is an infinity focus helper.

Cheers

Garry

a1ex

I had a half-successful experiment about 64-bit integers in Lua, but don't remember doing anything about floating-point. At least, there's no %f in api_test.lua from the lua_fix branch...

The branch about replacing Canon's printf with a standards-compliant implementation didn't progress because I hoped for some sort of help from the other developers (as there are *lots* of strings to be updated in that branch, and it's fairly easy to do so - just follow compiler messages - but it takes a lot of time).

For floating-point, the dietlibc library probably has to be recompiled (didn't try, but that would be the first thing).

There's also the possibility of formatting errors (very easy to get unnoticed, as every single formatted string has the chance to give different output after the update -- for a proof, just see the hdparm example from the PR page), so I'm tempted to implement this before converting to standards-compliant printf (because it would highlight such errors).