diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/luacd.cpp | 102 |
1 files changed, 102 insertions, 0 deletions
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<String> probed = cdabstract::probe(); + int j = 1; + + for (std::vector<String>::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); +} |