From 656b3b9c2862114eb84ea0eea5225568015515f5 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 12 Sep 2016 12:02:07 +0200 Subject: [PATCH] Add a Lua wrapper to Glib::build_filename() --- libs/ardour/ardour/lua_api.h | 8 ++++++++ libs/ardour/lua_api.cc | 20 ++++++++++++++++++++ libs/ardour/luabindings.cc | 1 + 3 files changed, 29 insertions(+) diff --git a/libs/ardour/ardour/lua_api.h b/libs/ardour/ardour/lua_api.h index 9af9649620..f737eddc4b 100644 --- a/libs/ardour/ardour/lua_api.h +++ b/libs/ardour/ardour/lua_api.h @@ -130,6 +130,14 @@ namespace ARDOUR { namespace LuaAPI { * @returns 4 parameters: red, green, blue, alpha (in range 0..1) */ int hsla_to_rgba (lua_State *lua); + + /* Creates a filename from a series of elements using the correct separator for filenames. + * + * No attempt is made to force the resulting filename to be an absolute path. + * If the first element is a relative path, the result will be a relative path. + */ + int build_filename (lua_State *lua); + } } /* namespace */ namespace ARDOUR { namespace LuaOSC { diff --git a/libs/ardour/lua_api.cc b/libs/ardour/lua_api.cc index 890e268c59..1cf403b8b0 100644 --- a/libs/ardour/lua_api.cc +++ b/libs/ardour/lua_api.cc @@ -346,6 +346,26 @@ ARDOUR::LuaAPI::hsla_to_rgba (lua_State *L) return 4; } +int +ARDOUR::LuaAPI::build_filename (lua_State *L) +{ + std::vector elem; + int top = lua_gettop(L); + if (top < 1) { + return luaL_argerror (L, 1, "invalid number of arguments, build_filename (path, ...)"); + } + for (int i = 1; i <= top; ++i) { + int lt = lua_type (L, i); + if (lt != LUA_TSTRING) { + return luaL_argerror (L, i, "invalid argument type, expected string"); + } + elem.push_back (luaL_checkstring(L, i)); + } + + luabridge::Stack::push (L, Glib::build_filename (elem)); + return 1; +} + luabridge::LuaRef::Proxy& luabridge::LuaRef::Proxy::clone_instance (const void* classkey, void* p) { lua_rawgeti (m_L, LUA_REGISTRYINDEX, m_tableRef); diff --git a/libs/ardour/luabindings.cc b/libs/ardour/luabindings.cc index 3dce7f592a..e8b65353a5 100644 --- a/libs/ardour/luabindings.cc +++ b/libs/ardour/luabindings.cc @@ -1468,6 +1468,7 @@ LuaBindings::common (lua_State* L) .addCFunction ("plugin_automation", ARDOUR::LuaAPI::plugin_automation) .addCFunction ("hsla_to_rgba", ARDOUR::LuaAPI::hsla_to_rgba) .addFunction ("usleep", Glib::usleep) + .addCFunction ("build_filename", ARDOUR::LuaAPI::build_filename) .endNamespace () // end LuaAPI .endNamespace ();// end ARDOUR }