From 4984ff4a7cdc181aa8d4ff913ddc4323e77f4bca Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 16 May 2009 21:43:21 +0000 Subject: Adding cd/dvdabstract classes to the lua exports. --- includes/luacd.h | 20 +++++++++++ lib/luacd.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/includes/luacd.h b/includes/luacd.h index 1f7768f..baa4929 100644 --- a/includes/luacd.h +++ b/includes/luacd.h @@ -27,6 +27,8 @@ #include #include #include +#include +#include #define CD_PUSHSTATICS(L) { \ Luacdutils::pushstatics(L); \ @@ -34,6 +36,8 @@ LuaPVD::pushstatics(L); \ LuaDirTree::pushstatics(L); \ Luaisobuilder::pushstatics(L); \ + Luacdabstract::pushconstruct(L); \ + Luadvdabstract::pushconstruct(L); \ } class Luacdutils : public LuaObject { @@ -89,4 +93,20 @@ class Luaisobuilder : public LuaObject { isobuilder * iso; }; +class Luacdabstract : public LuaHandle { + public: + static void pushconstruct(Lua *); + Luacdabstract(Handle *); + protected: + virtual void pushmembers(Lua *); +}; + +class Luadvdabstract : public LuaHandle { + public: + static void pushconstruct(Lua *); + Luadvdabstract(dvdabstract *); + protected: + virtual void pushmembers(Lua *); +}; + #endif diff --git a/lib/luacd.cpp b/lib/luacd.cpp index b619905..881f5ae 100644 --- a/lib/luacd.cpp +++ b/lib/luacd.cpp @@ -30,6 +30,12 @@ Luacdutils::Luacdutils(cdutils * _cd) : cd(_cd) { } class Luacdfile : public LuaHandle { public: Luacdfile(cdfile * h) : LuaHandle(h) {} + void pushmembers(Lua * L) { + LuaHandle::pushmembers(L); + L->push("__handletype"); + L->push("cdfile"); + L->settable(-3, true); + } }; enum cdutils_methods_t { @@ -1713,3 +1719,99 @@ int sLua_isobuilder::isobuilder_proceed_statics(Lua * L, int n, int caller) { return r; } + + + /********************************\ +|** the various abstract classes **| + \********************************/ + +class sLuacdabstract : public Base { + public: + static int cdprobe(lua_State * L); + static int new_cdabstract(lua_State * L); +}; + +int sLuacdabstract::cdprobe(lua_State * __L) { + Lua * L = Lua::find(__L); + + if (!cdabstract::canprobe()) + return 0; + + L->newtable(); + std::vector probed = cdabstract::probe(); + int j = 1; + + for (std::vector::iterator i = probed.begin(); i != probed.end(); i++, j++) { + L->push((lua_Number) j); + L->push(*i); + L->settable(); + } + + return 1; +} + +int sLuacdabstract::new_cdabstract(lua_State * __L) { + Lua * L = Lua::find(__L); + int n = L->gettop(); + + if ((n != 1) || !L->isstring()) { + L->error("Incorrect arguments to constructor `cdabstract'"); + } + + Luacdabstract m(cdabstract::open_cd(L->tostring())); + m.pushdestruct(L); + + return 1; +} + +Luacdabstract::Luacdabstract(Handle * h) : LuaHandle(h) { } + +void Luacdabstract::pushconstruct(Lua * L) { + L->declarefunc("cdprobe", sLuacdabstract::cdprobe); + L->declarefunc("cdabstract", sLuacdabstract::new_cdabstract); +} + +void Luacdabstract::pushmembers(Lua * L) { + LuaHandle::pushmembers(L); + L->push("__handletype"); + L->push("cdabstract"); + L->settable(-3, true); +} + +class sLuadvdabstract : public Base { + public: + static int new_dvdabstract(lua_State * L); +}; + +int sLuadvdabstract::new_dvdabstract(lua_State * __L) { + Lua * L = Lua::find(__L); + int n = L->gettop(); + bool forwrite = false; + String fname; + + if ((n > 2) || (n < 1) || !L->isstring(1)) { + L->error("Incorrect arguments to constructor `dvdabstract'"); + } + + if (n == 2) + forwrite = L->toboolean(2); + fname = L->tostring(1); + + Luadvdabstract m(new dvdabstract(forwrite ? (Handle *) new Output(fname, 0, 0) : (Handle *) new Input(fname))); + m.pushdestruct(L); + + return 1; +} + +Luadvdabstract::Luadvdabstract(dvdabstract * h) : LuaHandle(h) { } + +void Luadvdabstract::pushconstruct(Lua * L) { + L->declarefunc("dvdabstract", sLuadvdabstract::new_dvdabstract); +} + +void Luadvdabstract::pushmembers(Lua * L) { + LuaHandle::pushmembers(L); + L->push("__handletype"); + L->push("dvdabstract"); + L->settable(-3, true); +} -- cgit v1.2.3