[JW Lua] Automatic float to integer conversion ... Lua 5.3 ?!

Bruce Olson Finale at web.yosound.com
Tue Nov 10 17:03:57 CET 2015


Jan,

 

Thanks for tracking down the documentation. I found the same error on
Sunday, see the PageFormatPrefs.SystemStaffHeight error: bad argument #2 to
'?' (number has no integer representation) message I sent on Sunday last.

 

-- 

Regards,

Bruce

 

From: JWLua [mailto:jwlua-bounces at jwmusic.nu] On Behalf Of Charles O.
Lawrence
Sent: Tuesday, November 10, 2015 8:16 AM
To: 'The JW Lua script plug-in.'
Subject: Re: [JW Lua] Automatic float to integer conversion ... Lua 5.3 ?!

 

Jan,

 

Interesting info.  I think you hit on the answer to the strange errors.

 

Charles

 

From: JWLua [mailto:jwlua-bounces at jwmusic.nu] On Behalf Of Jan Angermüller
Sent: Tuesday, November 10, 2015 8:11 AM
To: The JW Lua script plug-in. <jwlua at jwmusic.nu>
Subject: Re: [JW Lua] Automatic float to integer conversion ... Lua 5.3 ?!

 

Probably this is due to a change in Lua 5.3:
the chapter on integer/float conversion is new (
http://www.lua.org/manual/5.3/manual.html#3.4.3 ) and didn't exist for Lua
5.2.
It states: 
"The conversion from float to integer checks whether the float has an exact
representation as an integer (that is, the float has an integral value and
it is in the range of integer representation). If it does, that
representation is the result. Otherwise, the conversion fails."

Lesson learned: 
Don't assign float types to properties that expect integers in Lua 5.3. 
They will not be automatically converted to integers anymore.

This document gives a good overview of the new integer/float handling in Lua
5.3:
http://www.lua.org/wshop14/Ierusalimschy.pdf

So it seems that I will have a lot of fails now...
Bad luck then ... at least it leads to a cleaner code in the end.

Jan

Am 10.11.2015 um 11:08 schrieb Jan Angermüller:

Jari,

I am trying to make my scripts compatible with v.40/v.42 and get lots of bad
argument errors as Charles described some days ago ("Strange Error
Message"-thread), although with different descriptions, for example:
bad argument #2 to '?' (number has no integer representation)
And in my case these errors have not occured when running the scripts in
previous versions of JW Lua.

For example:
(a is an FCArticulationDef)
a.MainHandleVerticalOffset=a.MainHandleVerticalOffset+vertoffset         
It used to work fine for any vertoffset value, even with vertoffset being a
float type.
Now it throws the error message above WITHOUT the code line and requires an
explicit integer conversion to work:
a.MainHandleVerticalOffset=a.MainHandleVerticalOffset+math.floor(vertoffset)

Although the error message is technically correct (a float is not an
integer), the automatic type conversion used to work fine.
That will be probably be days of work to fix in more than 30.000 lines of
code if you have to track down every error without a debugger.

What's the reason for the new error message ? Is it a stricter parser or Lua
5.3 or anything else ?
Do you see any chance of solving that without having to rewrite all the
code.
Or at least add the code line when a "Bad Argument" error is thrown ? 

All the best,
Jan

Am 28.10.2015 um 22:40 schrieb Charles O. Lawrence:

Jari,

Sometimes when running a script I get an error message like this.  There is
no line number nor is there a red marker at any source line.  It makes
locating the problem rather difficult in a large script.  Any ideas?  Beta
0.42

 

bad argument #2 to '?' (number expected, got boolean)

 

Thanks,Charles

 

Sorry, I left off the subject





_______________________________________________
JWLua mailing list
JWLua at jwmusic.nu
http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu






_______________________________________________
JWLua mailing list
JWLua at jwmusic.nu
http://jwmusic.nu/mailman/listinfo/jwlua_jwmusic.nu

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20151110/5f814564/attachment-0002.html>


More information about the JWLua mailing list