Jump to content




[1.63] string.format("a%-2sc", "b") doesn't pad spaces


  • You cannot reply to this topic
6 replies to this topic

#1 electrodude512

  • Members
  • 167 posts
  • LocationEastern USA

Posted 09 July 2014 - 06:52 PM

Version:
ComputerCraft 1.63 on Minecraft 1.6.4

Description:
string.format("a%-2sc", "b") returns "abc"

This is probably a LuaJ bug. Is it fixable, or should it be added to the list of broken string functions at http://computercraft...tring_%28API%29?

Expected Result:
string.format("a%-2sc", "b") returns "ab c"

Reproduction Steps:
ComputerCraft:
lua> string.format("a%-2sc", "b")
abc

Lua 5.1
bash $ lua
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> =string.format("a%-2sc", "b")
ab c
>

Edited by electrodude512, 09 July 2014 - 08:44 PM.


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 09 July 2014 - 08:58 PM

String.format is broken in the LuaJ implementation in a number of ways, so feel free to add the space-padding part of the %s type to the list. It would be misleading to state that string.format is broken in general, since it does mostly work. Can anyone verify that the syntax of the command is correct and duplicate the results before this gets added to the wiki? I'm not around a Lua interpreter at the moment.

#3 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 09 July 2014 - 09:27 PM

Using lua.org's online emulator, I came up with the same result.

#4 electrodude512

  • Members
  • 167 posts
  • LocationEastern USA

Posted 09 July 2014 - 10:02 PM

I requested wiki edit priveleges on the wiki edit privileges page. In case a moderator sees this post before my post on that page, my wiki username is Electrodude512. I'll add how padding is broken and I'll put my above example and probably also a fully functional (or closer to fully functional) string.format (but in lua so slower) because I'm about to write one anyway.

Edited by electrodude512, 09 July 2014 - 10:12 PM.


#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 09 July 2014 - 11:56 PM

Adding a differently broken string.format wouldn't help anything.

#6 electrodude512

  • Members
  • 167 posts
  • LocationEastern USA

Posted 10 July 2014 - 12:16 AM

View PostLyqyd, on 09 July 2014 - 11:56 PM, said:

Adding a differently broken string.format wouldn't help anything.
OK, then I'll add a fully standards-compliant implementation instead of one that only adds padding. I might not be able to add it any time soon though, because I'll be busy with real life and I'll want to debug it before posting it. However, I can write that padding doesn't work without posting a fixed version as soon as I get wiki edit privileges.

Edited by electrodude512, 10 July 2014 - 12:17 AM.


#7 YoYoYonnY

  • Members
  • 49 posts

Posted 21 July 2014 - 07:24 PM

Want proof?
Posted Image
There you go!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users