Add a locale-independent float/double format Lua method
authorRobin Gareus <robin@gareus.org>
Tue, 14 Aug 2018 21:49:43 +0000 (23:49 +0200)
committerRobin Gareus <robin@gareus.org>
Tue, 14 Aug 2018 21:50:11 +0000 (23:50 +0200)
print(ARDOUR.LuaAPI.ascii_dtostr(1.5))

libs/ardour/ardour/lua_api.h
libs/ardour/lua_api.cc
libs/ardour/luabindings.cc

index fe956c6b437ea83d8a6017de26bfc506574f5f1f..7c2c309982ed04ba72b72c35e5de171a851a2d5f 100644 (file)
@@ -187,6 +187,10 @@ namespace ARDOUR { namespace LuaAPI {
         */
        int color_to_rgba (lua_State *lua);
 
+       /**
+        */
+       std::string ascii_dtostr (const double d);
+
        /**
         * Creates a filename from a series of elements using the correct separator for filenames.
         *
index 59d27493998925a445366ce80b64755f28455614..82ff2fd651c47361a7c534bfa708ef617dcac839 100644 (file)
@@ -527,6 +527,14 @@ ARDOUR::LuaAPI::hsla_to_rgba (lua_State *L)
        return 4;
 }
 
+std::string
+ARDOUR::LuaAPI::ascii_dtostr (const double d)
+{
+       gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
+       g_ascii_dtostr (buf, sizeof(buf), d);
+       return std::string (buf);
+}
+
 int
 ARDOUR::LuaAPI::color_to_rgba (lua_State *L)
 {
index d82fb38bc6276f20dc799fcfd84ff6a821b44a41..90c8b8ad90066bab233790518e004f09f96d722f 100644 (file)
@@ -2330,6 +2330,7 @@ LuaBindings::common (lua_State* L)
                .addCFunction ("plugin_automation", ARDOUR::LuaAPI::plugin_automation)
                .addCFunction ("hsla_to_rgba", ARDOUR::LuaAPI::hsla_to_rgba)
                .addCFunction ("color_to_rgba", ARDOUR::LuaAPI::color_to_rgba)
+               .addFunction ("ascii_dtostr", ARDOUR::LuaAPI::ascii_dtostr)
                .addFunction ("usleep", Glib::usleep)
                .addFunction ("monotonic_time", ::g_get_monotonic_time)
                .addCFunction ("build_filename", ARDOUR::LuaAPI::build_filename)