consistent lua binding name (nil is a reserved word in lua)
[ardour.git] / libs / ardour / lua_api.cc
index 176a62005245e86f4360a2eb2f2e4402c332dade..8a52a2ccb787f8953418ce6eadb1ffc709d88bd0 100644 (file)
 #include "ardour/plugin_insert.h"
 #include "ardour/plugin_manager.h"
 
+#include "LuaBridge/LuaBridge.h"
+
 #include "i18n.h"
 
 using namespace ARDOUR;
 using namespace PBD;
 using namespace std;
 
+int
+ARDOUR::LuaAPI::datatype_ctor_null (lua_State *L)
+{
+       DataType dt (DataType::NIL);
+       luabridge::Stack <DataType>::push (L, dt);
+       return 1;
+}
+
+int
+ARDOUR::LuaAPI::datatype_ctor_audio (lua_State *L)
+{
+       DataType dt (DataType::AUDIO);
+       // NB luabridge will copy construct the object and manage lifetime.
+       luabridge::Stack <DataType>::push (L, dt);
+       return 1;
+}
+
+int
+ARDOUR::LuaAPI::datatype_ctor_midi (lua_State *L)
+{
+       DataType dt (DataType::MIDI);
+       luabridge::Stack <DataType>::push (L, dt);
+       return 1;
+}
+
 boost::shared_ptr<Processor>
 ARDOUR::LuaAPI::new_luaproc (Session *s, const string& name)
 {
@@ -43,9 +70,9 @@ ARDOUR::LuaAPI::new_luaproc (Session *s, const string& name)
 
        LuaScriptInfoPtr spi;
        ARDOUR::LuaScriptList & _scripts (LuaScripting::instance ().scripts (LuaScriptInfo::DSP));
-       for (LuaScriptList::const_iterator s = _scripts.begin(); s != _scripts.end(); ++s) {
-               if (name == (*s)->name) {
-                       spi = *s;
+       for (LuaScriptList::const_iterator i = _scripts.begin(); i != _scripts.end(); ++i) {
+               if (name == (*i)->name) {
+                       spi = *i;
                        break;
                }
        }
@@ -67,14 +94,9 @@ ARDOUR::LuaAPI::new_luaproc (Session *s, const string& name)
        return boost::shared_ptr<Processor> (new PluginInsert (*s, p));
 }
 
-
-boost::shared_ptr<Processor>
-ARDOUR::LuaAPI::new_plugin (Session *s, const string& name, ARDOUR::PluginType type, const string& preset)
+PluginInfoPtr
+ARDOUR::LuaAPI::new_plugin_info (const string& name, ARDOUR::PluginType type)
 {
-       if (!s) {
-               return boost::shared_ptr<Processor> ();
-       }
-
        PluginManager& manager = PluginManager::instance();
        PluginInfoList all_plugs;
        all_plugs.insert(all_plugs.end(), manager.ladspa_plugin_info().begin(), manager.ladspa_plugin_info().end());
@@ -91,13 +113,23 @@ ARDOUR::LuaAPI::new_plugin (Session *s, const string& name, ARDOUR::PluginType t
        all_plugs.insert(all_plugs.end(), manager.lv2_plugin_info().begin(), manager.lv2_plugin_info().end());
 #endif
 
-       PluginInfoPtr pip;
        for (PluginInfoList::const_iterator i = all_plugs.begin(); i != all_plugs.end(); ++i) {
                if (((*i)->name == name || (*i)->unique_id == name) && (*i)->type == type) {
-                       pip = *i;
-                       break;
+                       return *i;
                }
        }
+       return PluginInfoPtr ();
+}
+
+boost::shared_ptr<Processor>
+ARDOUR::LuaAPI::new_plugin (Session *s, const string& name, ARDOUR::PluginType type, const string& preset)
+{
+       if (!s) {
+               return boost::shared_ptr<Processor> ();
+       }
+
+       PluginInfoPtr pip = new_plugin_info (name, type);
+
        if (!pip) {
                return boost::shared_ptr<Processor> ();
        }
@@ -146,9 +178,9 @@ ARDOUR::LuaAPI::set_processor_param (boost::shared_ptr<Processor> proc, uint32_t
 }
 
 int
-ARDOUR::LuaAPI::LuaOSCAddress::send (lua_State *L)
+ARDOUR::LuaOSC::Address::send (lua_State *L)
 {
-       LuaOSCAddress * const luaosc = luabridge::Userdata::get <LuaOSCAddress> (L, 1, false);
+       Address * const luaosc = luabridge::Userdata::get <Address> (L, 1, false);
        if (!luaosc) {
                return luaL_error (L, "Invalid pointer to OSC.Address");
        }
@@ -217,6 +249,6 @@ ARDOUR::LuaAPI::LuaOSCAddress::send (lua_State *L)
 
        int rv = lo_send_message (luaosc->_addr, path, msg);
        lo_message_free (msg);
-       luabridge::Stack<int>::push (L, rv);
+       luabridge::Stack<bool>::push (L, (rv == 0));
        return 1;
 }