Jump to content

LuaJ Bugs

3 replies to this topic

#1 gamax92

  • Members
  • 157 posts

Posted 11 July 2014 - 03:59 PM

 * The string.sub+find combo
Nutshell: Strings from string.sub won t work properly in string.find, giving
    wrong offsets.
Detail: the indexOf in LuaString does not give numbers minus the string offset
    (which is usually zero). string.find uses said function, where strings with
    a different offset can be generated by string.sub (it reuses the string
By putting any special pattern character (and parameter 4 is not true), bug
    goes away.

 * string.format
Takes "%" as a valid format (no format letter passed afterwards)
Does not do a separate check to see if a value was specified for current code
    (shown by above bug).
Codes e,E,f,g,G are not implemented and do not handle flags
Codes s,c do nothing involving flags like precision and width
For o,u,x,X: the flags (space) and + are not ignored. the flag # is not
You can never specify all flags at once, the internal counter is always one off

 * string.rep
Breaks if the amount to duplicate is a negative number, should instead return
    an empty string

 * tostring
doubles are checked as long and if its the same, Long.toString is used (result
    is still correct but just formatted differently)
doing tostring on a double will return a rather low precision string version.
LuaDouble is converting the double to a string, by converting it to Float first.

 * tonumber
Numbers are scanned as longs instead of doubles.
The simple character subtraction done in scanlong makes it simple, but also
    results in letters below lowercase "a" being accepted: [\]^_`
 * (internal compiler)
Code that relied on lexerror checking if the token was non zero (and adding the
    "near <something>") message will lack this message. lexerror does this
    token check, but then throws an error without the additional info.

I've noticed that the string.rep and string.format bugs are missing from the String (API) page.
Seeing as I cannot edit the wiki, it would be nice if someone adds up this info.

EDIT: Added bugs regarding o,u,x,X on string.format
Added bug about max flags
EDIT: Added %c to the no flags list.
EDIT: Mentioned no flags on e,E,f,g,G</something>

Edited by gamax92, 11 July 2014 - 07:12 PM.

#2 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 11 July 2014 - 04:19 PM

I'm about the edit that wiki page. But first

View Postgamax92, on 11 July 2014 - 03:59 PM, said:

* string.format
Does not do a seperate check to see if a value was specified for current code
(shown by above bug).
What do you exactly mean by that?

#3 gamax92

  • Members
  • 157 posts

Posted 11 July 2014 - 05:36 PM

so in the lua source code theres a check to see if a value is there for the current flag.
Should give a "no value" error

Oh and I found more formatting bugs, will put an "EDIT" on the first post once they've been added.

EDIT: Also %c does nothing regarding flags

Edited by gamax92, 11 July 2014 - 05:48 PM.

#4 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 15 June 2015 - 09:22 PM

I really hate myself for bumping this thread, but this thread is really appropriate since it is a LuaJ bug.

I am currently creating a program which has the following snippet:
local sNumber = ""
local sChar = sSequence:sub (nIndex, nIndex)
while tonumber ( sChar ) do
   sNumber = sNumber .. sChar
   nIndex = nIndex + 1
   sChar = sSequence:sub (nIndex, nIndex)
   if nIndex == sSequence:len() then
local number = tonumber( sNumber )
As you might have noticed, I am parsing a big number until a non-digit has been hit and continue with that code. The problem what I was hitting is that sSequence contained dashes, which at first didn't should not be a problem in this code. However, "-" gets recognized as a number, more precisely as 0.

After getting odd errors in my code after this, I wanted to investigate and ran the following script on pure lua (v 5.1.4) and on CC Lua (currently written in CC-Lua to get to the point):
local file = fs.open ("log.log", "w")
for i = 1, 255 do
	local sChar = string.char ( i )
	file.writeLine( string.format( "%s -> %s", sChar, tostring(tonumber(sChar)) ) )
The important output of pure Lua
The important output of CC Lua
As you can see it differs, which can be fatal in a case like where I use tonumber. I hope to see that this is fixed in a next version to prevent such weird errors. For the record, this has been done with CC 1.73 which is the latest version as of writing this post to my knowledge.

Also, this error only happens when the dash is the only character in the string, when it is combined with other digits tonumber will return nil!

Here is a temporary tonumber fix:
local backup_tonumber = tonumber
function tonumber ( s )
   local result = backup_tonumber ( s )
   if result == 0 and s == "-" then
   return result

Edited by Engineer, 15 June 2015 - 09:23 PM.

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users