From d789ef7c6bcc3be3d223392e4b6f5a57b33a5ed6 Mon Sep 17 00:00:00 2001 From: Kyzentun Date: Thu, 2 Apr 2015 13:36:41 -0600 Subject: [PATCH] Exposed commify function to lua and made it handle decimal numbers. --- Docs/Changelog_sm5.txt | 8 ++++ Docs/Luadoc/Lua.xml | 1 + Docs/Luadoc/LuaDocumentation.xml | 9 +++++ Themes/_fallback/Scripts/00 init.lua | 6 +-- src/RageUtil.cpp | 58 ++++++++++++++++++++++++---- src/RageUtil.h | 2 +- 6 files changed, 70 insertions(+), 14 deletions(-) diff --git a/Docs/Changelog_sm5.txt b/Docs/Changelog_sm5.txt index 7e5ff65cc4..0ec0d5ad7a 100644 --- a/Docs/Changelog_sm5.txt +++ b/Docs/Changelog_sm5.txt @@ -4,6 +4,14 @@ The StepMania 5 Changelog covers all post-sm-ssc changes. For a list of changes from StepMania 4 alpha 5 to sm-ssc v1.2.5, see Changelog_sm-ssc.txt. ________________________________________________________________________________ +2015/04/02 +---------- +* [global] commify function exposed to lua. [kyzentun] + +================================================================================ +StepMania 5.0.7 | 20150401 +-------------------------------------------------------------------------------- + 2015/03/30 ---------- * [Select Music] Ctrl+Shift+R mapped to reload the current song. [kyzentun] diff --git a/Docs/Luadoc/Lua.xml b/Docs/Luadoc/Lua.xml index 7cc8733d3f..35f2706c47 100644 --- a/Docs/Luadoc/Lua.xml +++ b/Docs/Luadoc/Lua.xml @@ -209,6 +209,7 @@ + diff --git a/Docs/Luadoc/LuaDocumentation.xml b/Docs/Luadoc/LuaDocumentation.xml index 30255d2bce..2546f90afe 100644 --- a/Docs/Luadoc/LuaDocumentation.xml +++ b/Docs/Luadoc/LuaDocumentation.xml @@ -109,6 +109,15 @@ save yourself some time, copy this for undocumented things: [03 Gameplay.lua] Returns the UserPrefComboUnderField user preference value. + + This will take the number and insert a comma every three digits, as normal in English for writing large numbers.
+ number can be a string, an integer, or a float.
+ comma is an optional argument that is used instead of a comma.
+ "commify(1234, 'cat')" will result in "1cat234".
+ dot is an optional argument that is used instead of a dot to find the end of the part that should be commified.
+ "commify('1234cat5678', ',', 'cat')" will result in "1,234cat5678", but "commify('1234cat5678')" will result in "12,34c,at5,678".
+ The comma and dot arguments are provided to ease compliance with locales or languages that do not use comma and dot in numbers the way English does. +
Tries to connect to the server at sAddress. diff --git a/Themes/_fallback/Scripts/00 init.lua b/Themes/_fallback/Scripts/00 init.lua index a3c353f946..50bfa04d4d 100644 --- a/Themes/_fallback/Scripts/00 init.lua +++ b/Themes/_fallback/Scripts/00 init.lua @@ -60,11 +60,7 @@ function split(delimiter, text) end function join(delimiter, list) - local ret = list[1] - for i = 2,table.getn(list) do - ret = ret .. delimiter .. list[i] - end - return ret or "" + return table.concat(list, delimiter) end -- (c) 2006 Glenn Maynard diff --git a/src/RageUtil.cpp b/src/RageUtil.cpp index ea10ac5fb3..fddc281f9a 100644 --- a/src/RageUtil.cpp +++ b/src/RageUtil.cpp @@ -332,17 +332,39 @@ RString Commify( int iNum ) return Commify( sNum ); } -RString Commify( RString sNum, RString sSeperator ) +RString Commify(const RString& num, const RString& sep, const RString& dot) { - RString sReturn; - for( unsigned i=0; i