diff options
Diffstat (limited to 'lib/luacd.cpp')
-rw-r--r-- | lib/luacd.cpp | 3317 |
1 files changed, 1659 insertions, 1658 deletions
diff --git a/lib/luacd.cpp b/lib/luacd.cpp index 97efe82..e4e2b23 100644 --- a/lib/luacd.cpp +++ b/lib/luacd.cpp @@ -1,1660 +1,1661 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002-2003 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: luacd.cpp,v 1.13 2004-05-03 12:55:04 pixel Exp $ */ - -#include "luacd.h" - - - /**************************\ -|** class cdutils exports **| - \**************************/ - -Luacdutils::Luacdutils(cdutils * _cd) : cd(_cd) { } -class Luacdfile : public LuaHandle {
+/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: luacd.cpp,v 1.14 2004-10-19 15:58:42 pixel Exp $ */
+
+#include "luacd.h"
+
+
+ /**************************\
+|** class cdutils exports **|
+ \**************************/
+
+Luacdutils::Luacdutils(cdutils * _cd) : cd(_cd) { }
+class Luacdfile : public LuaHandle {
+ public:
+ Luacdfile(cdfile * h) : LuaHandle(h) {}
+};
+
+enum cdutils_methods_t {
+ CDUTILS_SETISOW = 0,
+ CDUTILS_GUESSTYPE,
+ CDUTILS_SECTORSEEK,
+ CDUTILS_READSECTOR,
+ CDUTILS_READDATAS,
+ CDUTILS_READFILE,
+ CDUTILS_WRITESECTOR,
+ CDUTILS_WRITEDATAS,
+ CDUTILS_WRITEFILE,
+ CDUTILS_GETISOINFOS,
+ CDUTILS_GETPTINFOS,
+ CDUTILS_FINDPATH,
+ CDUTILS_FINDPARENT,
+ CDUTILS_FINDDIRENTRY,
+ CDUTILS_NEWCDFILE,
+ CDUTILS_UPDATESIZE,
+ CDUTILS_UPDATESECTOR,
+ CDUTILS_CREATESECTOR,
+};
+
+enum cdutils_functions_t {
+ CDUTILS_NEWCDUTILS = 0,
+ CDUTILS_SWAPWORD,
+ CDUTILS_SWAPDWORD,
+ CDUTILS_FROM_BCD,
+ CDUTILS_TO_BCD,
+ CDUTILS_IS_VALID_BCD,
+ CDUTILS_FROM_MSF,
+ CDUTILS_TO_MSF,
+};
+
+struct lua_functypes_t cdutils_methods[] = {
+ { CDUTILS_SETISOW, "set_iso_w", 1, 1, {LUA_OBJECT} },
+ { CDUTILS_GUESSTYPE, "guessmode", 0, 1, {LUA_NUMBER} },
+ { CDUTILS_SECTORSEEK, "sectorseek", 1, 1, {LUA_NUMBER} },
+ { CDUTILS_READSECTOR, "readsector", 0, 2, {LUA_NUMBER, LUA_NUMBER} },
+ { CDUTILS_READDATAS, "readdatas", 1, 3, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
+ { CDUTILS_READFILE, "readfile", 2, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
+ { CDUTILS_WRITESECTOR, "writesector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} },
+ { CDUTILS_WRITEDATAS, "writedatas", 2, 4, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
+ { CDUTILS_WRITEFILE, "writefile", 1, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
+ { CDUTILS_GETISOINFOS, "getisoinfos", 0, 0, 0 },
+ { CDUTILS_GETPTINFOS, "getptinfos", 0, 0, 0 },
+ { CDUTILS_FINDPATH, "findpath", 1, 1, {LUA_STRING} },
+ { CDUTILS_FINDPARENT, "findparent", 1, 1, {LUA_STRING} },
+ { CDUTILS_FINDDIRENTRY, "finddirentry", 2, 2, {LUA_OBJECT, LUA_STRING} },
+ { CDUTILS_NEWCDFILE, "cdfile", 1, 3, {LUA_ANY, LUA_NUMBER, LUA_NUMBER} },
+ { CDUTILS_UPDATESIZE, "updatesize", 2, 2, {LUA_STRING, LUA_NUMBER} },
+ { CDUTILS_UPDATESECTOR, "updatesector", 2, 2, {LUA_STRING, LUA_NUMBER} },
+ { CDUTILS_CREATESECTOR, "createsector", 2, 3, {LUA_NUMBER, LUA_NUMBER, LUA_BOOLEAN} },
+ { -1, 0, 0, 0, 0 }
+};
+
+struct lua_functypes_t cdutils_functions[] = {
+ { CDUTILS_NEWCDUTILS, "cdutils" , 1, 2, {LUA_OBJECT, LUA_OBJECT} },
+ { CDUTILS_SWAPWORD, "swapword", 1, 1, {LUA_NUMBER} },
+ { CDUTILS_SWAPDWORD, "swapdword", 1, 1, {LUA_NUMBER} },
+ { CDUTILS_FROM_BCD, "from_BCD", 1, 1, {LUA_NUMBER} },
+ { CDUTILS_TO_BCD, "to_BCD", 1, 1, {LUA_NUMBER} },
+ { CDUTILS_IS_VALID_BCD, "is_valid_BCD", 1, 1, {LUA_NUMBER} },
+ { CDUTILS_FROM_MSF, "from_MSF", 1, 4, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
+ { CDUTILS_TO_MSF, "to_MSF", 1, 2, {LUA_NUMBER, LUA_NUMBER} },
+ { -1, 0, 0, 0, 0 }
+};
+
+class sLua_cdutils : public Base {
+ public:
+ DECLARE_METHOD(cdutils, CDUTILS_SETISOW);
+ DECLARE_METHOD(cdutils, CDUTILS_GUESSTYPE);
+ DECLARE_METHOD(cdutils, CDUTILS_SECTORSEEK);
+ DECLARE_METHOD(cdutils, CDUTILS_READSECTOR);
+ DECLARE_METHOD(cdutils, CDUTILS_READDATAS);
+ DECLARE_METHOD(cdutils, CDUTILS_READFILE);
+ DECLARE_METHOD(cdutils, CDUTILS_WRITESECTOR);
+ DECLARE_METHOD(cdutils, CDUTILS_WRITEDATAS);
+ DECLARE_METHOD(cdutils, CDUTILS_WRITEFILE);
+ DECLARE_METHOD(cdutils, CDUTILS_GETISOINFOS);
+ DECLARE_METHOD(cdutils, CDUTILS_GETPTINFOS);
+ DECLARE_METHOD(cdutils, CDUTILS_FINDPATH);
+ DECLARE_METHOD(cdutils, CDUTILS_FINDPARENT);
+ DECLARE_METHOD(cdutils, CDUTILS_FINDDIRENTRY);
+ DECLARE_METHOD(cdutils, CDUTILS_NEWCDFILE);
+ DECLARE_METHOD(cdutils, CDUTILS_UPDATESIZE);
+ DECLARE_METHOD(cdutils, CDUTILS_UPDATESECTOR);
+ DECLARE_METHOD(cdutils, CDUTILS_CREATESECTOR);
+
+ DECLARE_FUNCTION(cdutils, CDUTILS_NEWCDUTILS);
+ DECLARE_FUNCTION(cdutils, CDUTILS_SWAPWORD);
+ DECLARE_FUNCTION(cdutils, CDUTILS_SWAPDWORD);
+ DECLARE_FUNCTION(cdutils, CDUTILS_FROM_BCD);
+ DECLARE_FUNCTION(cdutils, CDUTILS_TO_BCD);
+ DECLARE_FUNCTION(cdutils, CDUTILS_IS_VALID_BCD);
+ DECLARE_FUNCTION(cdutils, CDUTILS_FROM_MSF);
+ DECLARE_FUNCTION(cdutils, CDUTILS_TO_MSF);
+
+ private:
+ static int cdutils_proceed(Lua * L, int n, cdutils * obj, int caller);
+ static int cdutils_proceed_statics(Lua * L, int n, int caller);
+};
+
+void Luacdutils::pushmembers(Lua * L) {
+ pushme(L, cd);
+
+ PUSH_METHOD(cdutils, CDUTILS_SETISOW);
+ PUSH_METHOD(cdutils, CDUTILS_GUESSTYPE);
+ PUSH_METHOD(cdutils, CDUTILS_SECTORSEEK);
+ PUSH_METHOD(cdutils, CDUTILS_READSECTOR);
+ PUSH_METHOD(cdutils, CDUTILS_READDATAS);
+ PUSH_METHOD(cdutils, CDUTILS_READFILE);
+ PUSH_METHOD(cdutils, CDUTILS_WRITESECTOR);
+ PUSH_METHOD(cdutils, CDUTILS_WRITEDATAS);
+ PUSH_METHOD(cdutils, CDUTILS_WRITEFILE);
+ PUSH_METHOD(cdutils, CDUTILS_GETISOINFOS);
+ PUSH_METHOD(cdutils, CDUTILS_GETPTINFOS);
+ PUSH_METHOD(cdutils, CDUTILS_FINDPATH);
+ PUSH_METHOD(cdutils, CDUTILS_FINDPARENT);
+ PUSH_METHOD(cdutils, CDUTILS_FINDDIRENTRY);
+ PUSH_METHOD(cdutils, CDUTILS_NEWCDFILE);
+ PUSH_METHOD(cdutils, CDUTILS_UPDATESIZE);
+ PUSH_METHOD(cdutils, CDUTILS_UPDATESECTOR);
+ PUSH_METHOD(cdutils, CDUTILS_CREATESECTOR);
+}
+
+void Luacdutils::pushstatics(Lua * L) throw (GeneralException) {
+ CHECK_METHODS(cdutils);
+ CHECK_FUNCTIONS(cdutils);
+
+ PUSH_FUNCTION(cdutils, CDUTILS_NEWCDUTILS);
+ PUSH_FUNCTION(cdutils, CDUTILS_SWAPWORD);
+ PUSH_FUNCTION(cdutils, CDUTILS_SWAPDWORD);
+ PUSH_FUNCTION(cdutils, CDUTILS_FROM_BCD);
+ PUSH_FUNCTION(cdutils, CDUTILS_TO_BCD);
+ PUSH_FUNCTION(cdutils, CDUTILS_IS_VALID_BCD);
+ PUSH_FUNCTION(cdutils, CDUTILS_FROM_MSF);
+ PUSH_FUNCTION(cdutils, CDUTILS_TO_MSF);
+
+ L->push("MODE0");
+ L->push((lua_Number) MODE0);
+ L->setvar();
+
+ L->push("MODE1");
+ L->push((lua_Number) MODE1);
+ L->setvar();
+
+ L->push("MODE2");
+ L->push((lua_Number) MODE2);
+ L->setvar();
+
+ L->push("MODE2_FORM1");
+ L->push((lua_Number) MODE2_FORM1);
+ L->setvar();
+
+ L->push("MODE2_FORM2");
+ L->push((lua_Number) MODE2_FORM2);
+ L->setvar();
+
+ L->push("MORE_RAW");
+ L->push((lua_Number) MODE_RAW);
+ L->setvar();
+
+ L->push("GUESS");
+ L->push((lua_Number) GUESS);
+ L->setvar();
+
+ int i;
+
+ L->push("sec_sizes");
+ L->newtable();
+ for (i = 0; i <= GUESS; i++) {
+ L->push((lua_Number) i);
+ L->push((lua_Number) sec_sizes[i]);
+ L->settable();
+ }
+ L->setvar();
+
+ L->push("sec_offsts");
+ L->newtable();
+ for (i = 0; i <= GUESS; i++) {
+ L->push((lua_Number) i);
+ L->push((lua_Number) sec_offsts[i]);
+ L->settable();
+ }
+ L->setvar();
+
+ L->push("sec_modes");
+ L->newtable();
+ for (i = 0; i <= GUESS; i++) {
+ L->push((lua_Number) i);
+ L->push(sec_modes[i]);
+ L->settable();
+ }
+ L->setvar();
+}
+
+int sLua_cdutils::cdutils_proceed(Lua * L, int n, cdutils * cd, int caller) {
+ int r = 0, sect = -1, mode = GUESS, size = -1, i;
+ Handle * h;
+ Byte sdatas[2352], * datas;
+ String path;
+ cdutils::DirEntry * dir, * bdir, * adir, pdir;
+ bool invalid = false, eof = false;
+ int sector;
+ cdfile * cdf;
+
+ switch(caller) {
+ case CDUTILS_SETISOW:
+ h = (Handle *) LuaObject::getme(L, 2);
+ cd->set_iso_w(h);
+ break;
+ case CDUTILS_GUESSTYPE:
+ if (n == 1) {
+ sect = L->tonumber(2);
+ }
+ L->push((lua_Number) cd->guess_type(sect));
+ r = 1;
+ break;
+ case CDUTILS_SECTORSEEK:
+ sect = L->tonumber(2);
+ cd->sector_seek(sect);
+ break;
+ case CDUTILS_READSECTOR:
+ if (n >= 1)
+ sect = L->tonumber(2);
+ if (n == 2)
+ mode = L->tonumber(3);
+ size = cd->read_sector(sdatas, mode, sect);
+ L->newtable();
+ for (i = 0; i < size; i++) {
+ L->push((lua_Number) i);
+ L->push((lua_Number) sdatas[i]);
+ L->settable();
+ }
+ r = 1;
+ break;
+ case CDUTILS_READDATAS:
+ size = L->tonumber(2);
+ if (n >= 2)
+ sect = L->tonumber(3);
+ if (n == 3)
+ mode = L->tonumber(3);
+ datas = (Byte *) malloc(size);
+ cd->read_datas(datas, size, mode, sect);
+ L->newtable();
+ for (i = 0; i < size; i++) {
+ L->push((lua_Number) i);
+ L->push((lua_Number) datas[i]);
+ L->settable();
+ }
+ r = 1;
+ free(datas);
+ break;
+ case CDUTILS_READFILE:
+ h = (Handle *) LuaObject::getme(L, 2);
+ size = L->tonumber(5);
+ if (n >= 3)
+ sect = L->tonumber(4);
+ if (n == 4)
+ mode = L->tonumber(5);
+ cd->read_file(h, size, mode, sect);
+ break;
+ case CDUTILS_WRITESECTOR:
+ if (n >= 2)
+ sect = L->tonumber(3);
+ if (n == 3)
+ mode = L->tonumber(4);
+ for (i = 0; i < 2352; i++) {
+ L->push((lua_Number) i);
+ L->gettable(2);
+ sdatas[i] = L->tonumber();
+ L->pop();
+ }
+ cd->write_sector(datas, mode, sect);
+ break;
+ case CDUTILS_WRITEDATAS:
+ size = L->tonumber(3);
+ if (n >= 3)
+ sect = L->tonumber(4);
+ if (n == 4)
+ mode = L->tonumber(5);
+ datas = (Byte *) malloc(size);
+
+ for (i = 0; i < size; i++) {
+ L->push((lua_Number) i);
+ L->gettable(2);
+ sdatas[i] = L->tonumber();
+ L->pop();
+ }
+ cd->write_datas(datas, size, mode, sect);
+ free(datas);
+ break;
+ case CDUTILS_WRITEFILE:
+ h = (Handle *) LuaObject::getme(L, 2);
+ if (n >= 2)
+ size = L->tonumber(3);
+ if (n >= 3)
+ sect = L->tonumber(4);
+ if (n == 4)
+ mode = L->tonumber(5);
+ cd->write_file(h, size, mode, sect);
+ break;
+ case CDUTILS_GETISOINFOS:
+ L->push((lua_Number) cd->get_iso_infos());
+ r = 1;
+ break;
+ case CDUTILS_GETPTINFOS:
+ L->push((lua_Number) cd->get_pt_infos());
+ r = 1;
+ break;
+ case CDUTILS_FINDPATH:
+ path = L->tostring(2);
+ bdir = cd->find_path(&datas, path);
+ if ((bdir) && bdir->R) {
+ dir = (cdutils::DirEntry *) malloc(bdir->R);
+ memcpy(dir, bdir, bdir->R);
+ } else {
+ dir = 0;
+ }
+ if (dir) {
+ Luadirentry ldir(dir);
+ ldir.pushdestruct(L);
+ } else {
+ L->push();
+ }
+ r = 1;
+ free(datas);
+ break;
+ case CDUTILS_FINDPARENT:
+ path = L->tostring(2);
+ bdir = cd->find_parent(&datas, path);
+ if ((bdir) && bdir->R) {
+ dir = (cdutils::DirEntry *) malloc(bdir->R);
+ memcpy(dir, bdir, bdir->R);
+ } else {
+ dir = 0;
+ }
+ if (dir) {
+ Luadirentry ldir(dir);
+ ldir.pushdestruct(L);
+ } else {
+ L->push();
+ }
+ r = 1;
+ free(datas);
+ break;
+ case CDUTILS_FINDDIRENTRY:
+ adir = (cdutils::DirEntry *) LuaObject::getme(L, 2);
+ path = L->tostring(3);
+ bdir = cd->find_dir_entry(&datas, adir, path);
+ if ((bdir) && bdir->R) {
+ dir = (cdutils::DirEntry *) malloc(bdir->R);
+ memcpy(dir, bdir, bdir->R);
+ } else {
+ dir = 0;
+ }
+ if (dir) {
+ Luadirentry ldir(dir);
+ ldir.pushdestruct(L);
+ } else {
+ L->push();
+ }
+ r = 1;
+ free(datas);
+ break;
+ case CDUTILS_NEWCDFILE:
+ if (L->istable(2)) {
+ if (n <= 2) {
+ dir = (cdutils::DirEntry *) LuaObject::getme(L, 2);
+ if (n == 2)
+ mode = L->tonumber(3);
+ cdf = new cdfile(cd, dir, mode);
+ } else {
+ invalid = true;
+ }
+ } else if (L->isnumber(2)) {
+ if (n >= 1) {
+ sector = L->tonumber(2);
+ if (n >= 2)
+ size = L->tonumber(3);
+ if (n == 3)
+ mode = L->tonumber(4);
+ cdf = new cdfile(cd, sector, size, mode);
+ } else {
+ invalid = true;
+ }
+ } else {
+ invalid = true;
+ }
+ if (invalid) {
+ L->error("Invalid arguments to constructor of cdfile");
+ } else {
+ Luacdfile luacdf(cdf);
+ luacdf.pushdestruct(L);
+ r = 1;
+ }
+ break;
+ case CDUTILS_UPDATESIZE:
+ case CDUTILS_UPDATESECTOR:
+ path = L->tostring(2);
+ pdir = cd->find_parent(path);
+ dir = cd->find_path(&datas, path);
+ switch (caller) {
+ case CDUTILS_UPDATESIZE:
+ dir->Size = tolittle((Uint32) L->tonumber(3));
+ dir->BESize = tobig((Uint32) L->tonumber(3));
+ break;
+ case CDUTILS_UPDATESECTOR:
+ dir->Sector = tolittle((Uint32) L->tonumber(3));
+ dir->BESector = tobig((Uint32) L->tonumber(3));
+ break;
+ }
+ cd->write_datas(datas, pdir.Size, GUESS, pdir.Sector);
+ free(datas);
+ break;
+ case CDUTILS_CREATESECTOR:
+ mode = L->tonumber(2);
+ sect = L->tonumber(3);
+ if (n == 3)
+ eof = L->toboolean(4);
+ cd->create_sector(mode, sect, eof);
+ break;
+ }
+
+
+ return r;
+}
+
+int sLua_cdutils::cdutils_proceed_statics(Lua * L, int n, int caller) {
+ int r = 0;
+ Uint32 x;
+ Handle * isor = 0, * isow = 0;
+ Uint32 sector, msf, start = 150;
+ Byte m, s, f;
+
+ switch(caller) {
+ case CDUTILS_NEWCDUTILS:
+ isor = (Handle *) LuaObject::getme(L, 1);
+ if (n == 2)
+ isow = (Handle *) LuaObject::getme(L, 2);
+ {
+ Luacdutils cd(new cdutils(isor, isow));
+ cd.pushdestruct(L);
+ }
+ break;
+ case CDUTILS_SWAPWORD:
+ x = L->tonumber();
+ L->push((lua_Number) cdutils::swap_word(x));
+ r = 1;
+ break;
+ case CDUTILS_SWAPDWORD:
+ x = L->tonumber();
+ L->push((lua_Number) cdutils::swap_dword(x));
+ r = 1;
+ break;
+ case CDUTILS_FROM_BCD:
+ x = L->tonumber();
+ L->push((lua_Number) cdutils::from_BCD(x));
+ r = 1;
+ break;
+ case CDUTILS_TO_BCD:
+ x = L->tonumber();
+ L->push((lua_Number) cdutils::to_BCD(x));
+ r = 1;
+ break;
+ case CDUTILS_IS_VALID_BCD:
+ x = L->tonumber();
+ L->push(cdutils::is_valid_BCD(x));
+ r = 1;
+ break;
+ case CDUTILS_FROM_MSF:
+ if (n <= 2) {
+ msf = L->tonumber(1);
+ if (n == 2)
+ start = L->tonumber(2);
+ L->push((lua_Number) cdutils::from_MSF(msf, start));
+ } else {
+ m = L->tonumber(1);
+ s = L->tonumber(2);
+ f = L->tonumber(3);
+ if (n == 4)
+ start = L->tonumber(4);
+ L->push((lua_Number) cdutils::from_MSF(m, s, f, start));
+ }
+ r = 1;
+ break;
+ case CDUTILS_TO_MSF:
+ sector = L->tonumber(1);
+ if (n == 2)
+ start = L->tonumber(2);
+ cdutils::to_MSF(sector, m, s, f, start);
+ msf = cdutils::to_MSF(sector, start);
+ L->push((lua_Number) msf);
+ L->push((lua_Number) m);
+ L->push((lua_Number) s);
+ L->push((lua_Number) f);
+ r = 4;
+ break;
+ }
+
+ return r;
+}
+
+
+ /***************************\
+|** class direntry exports **|
+ \***************************/
+
+typedef cdutils::DirEntry direntry;
+
+Luadirentry::Luadirentry(cdutils::DirEntry * _dir) : dir(_dir) { }
+
+enum direntry_methods_t {
+ DIRENTRY_INDEX = 0,
+ DIRENTRY_ISHIDDEN,
+ DIRENTRY_ISDIR,
+ DIRENTRY_HASXA,
+ DIRENTRY_ISXADIR,
+ DIRENTRY_ISXAAUDIO,
+ DIRENTRY_ISXASTR,
+ DIRENTRY_ISXAXA,
+ DIRENTRY_ISXAFORM1,
+};
+
+struct lua_functypes_t direntry_methods[] = {
+ { DIRENTRY_INDEX, "index", 1, 1, {LUA_STRING} },
+ { DIRENTRY_ISHIDDEN, "ishidden", 0, 0, 0 },
+ { DIRENTRY_ISDIR, "isdir", 0, 0, 0 },
+ { DIRENTRY_HASXA, "hasxa", 0, 0, 0 },
+ { DIRENTRY_ISXADIR, "isxadir", 0, 0, 0 },
+ { DIRENTRY_ISXAAUDIO, "isxaaudio", 0, 0, 0 },
+ { DIRENTRY_ISXASTR, "isxastr", 0, 0, 0 },
+ { DIRENTRY_ISXAXA, "isxaxa", 0, 0, 0 },
+ { DIRENTRY_ISXAFORM1, "isxaform1", 0, 0, 0 },
+ { -1, 0, 0, 0, 0 }
+};
+
+class sLua_direntry : public Base {
+ public:
+ DECLARE_METHOD(direntry, DIRENTRY_INDEX);
+ DECLARE_METHOD(direntry, DIRENTRY_ISHIDDEN);
+ DECLARE_METHOD(direntry, DIRENTRY_ISDIR);
+ DECLARE_METHOD(direntry, DIRENTRY_HASXA);
+ DECLARE_METHOD(direntry, DIRENTRY_ISXADIR);
+ DECLARE_METHOD(direntry, DIRENTRY_ISXAAUDIO);
+ DECLARE_METHOD(direntry, DIRENTRY_ISXASTR);
+ DECLARE_METHOD(direntry, DIRENTRY_ISXAXA);
+ DECLARE_METHOD(direntry, DIRENTRY_ISXAFORM1);
+ private:
+ static int direntry_proceed(Lua * L, int n, direntry * obj, int caller);
+};
+
+void Luadirentry::pushmembers(Lua * L) {
+ pushme(L, dir, false);
+
+ PUSH_METAMETHOD(direntry, DIRENTRY_INDEX);
+ PUSH_METHOD(direntry, DIRENTRY_ISHIDDEN);
+ PUSH_METHOD(direntry, DIRENTRY_ISDIR);
+ PUSH_METHOD(direntry, DIRENTRY_HASXA);
+ PUSH_METHOD(direntry, DIRENTRY_ISXADIR);
+ PUSH_METHOD(direntry, DIRENTRY_ISXAAUDIO);
+ PUSH_METHOD(direntry, DIRENTRY_ISXASTR);
+ PUSH_METHOD(direntry, DIRENTRY_ISXAXA);
+ PUSH_METHOD(direntry, DIRENTRY_ISXAFORM1);
+}
+
+int sLua_direntry::direntry_proceed(Lua * L, int n, direntry * dir, int caller) {
+ int r = 0, s, pad;
+ String index;
+ bool has_xa = false;
+ Byte * p;
+
+ s = 33 + dir->N;
+ if (s & 1) {
+ s++;
+ pad = 1;
+ } else {
+ pad = 0;
+ }
+ if (s != dir->R) {
+ if ((s + 14) == dir->R) {
+ p = (Byte *) dir->id + dir->N + pad;
+ if ((p[6] == 'X') && (p[7] == 'A')) {
+ has_xa = true;
+ }
+ }
+ }
+
+ switch (caller) {
+ case DIRENTRY_HASXA:
+ L->push(has_xa);
+ r = 1;
+ break;
+ case DIRENTRY_ISHIDDEN:
+ L->push(dir->Flags & 1 ? true : false);
+ r = 1;
+ break;
+ case DIRENTRY_ISDIR:
+ L->push(dir->Flags & 2 ? true : false);
+ r = 1;
+ break;
+ case DIRENTRY_ISXADIR:
+ L->push(p[4] & 0x80 ? true : false);
+ r = 1;
+ break;
+ case DIRENTRY_ISXAAUDIO:
+ L->push(p[4] & 0x40 ? true : false);
+ r = 1;
+ break;
+ case DIRENTRY_ISXASTR:
+ L->push(p[4] & 0x20 ? true : false);
+ r = 1;
+ break;
+ case DIRENTRY_ISXAXA:
+ L->push(p[4] & 0x10 ? true : false);
+ r = 1;
+ break;
+ case DIRENTRY_ISXAFORM1:
+ L->push(p[4] & 0x08 ? true : false);
+ r = 1;
+ break;
+ case DIRENTRY_INDEX:
+ index = L->tostring();
+ r = 1;
+ if (index == "R") {
+ L->push((lua_Number) dir->R);
+ } else if (index == "NExt") {
+ L->push((lua_Number) dir->NExt);
+ } else if (index == "Sector") {
+ L->push((lua_Number) dir->Sector);
+ } else if (index == "Size") {
+ L->push((lua_Number) dir->Size);
+ } else if (index == "Year") {
+ L->push((lua_Number) dir->Year);
+ } else if (index == "Month") {
+ L->push((lua_Number) dir->Month);
+ } else if (index == "Day") {
+ L->push((lua_Number) dir->Day);
+ } else if (index == "Hour") {
+ L->push((lua_Number) dir->Hour);
+ } else if (index == "Minute") {
+ L->push((lua_Number) dir->Minute);
+ } else if (index == "Second") {
+ L->push((lua_Number) dir->Second);
+ } else if (index == "Offset") {
+ L->push((lua_Number) dir->Offset);
+ } else if (index == "Flags") {
+ L->push((lua_Number) dir->Flags);
+ } else if (index == "HandleUnit") {
+ L->push((lua_Number) dir->HandleUnit);
+ } else if (index == "HandleGap") {
+ L->push((lua_Number) dir->HandleGap);
+ } else if (index == "VolSeq") {
+ L->push((lua_Number) dir->VolSeq);
+ } else if (index == "N") {
+ L->push((lua_Number) dir->N);
+ } else if (index == "id") {
+ char pbuf[256];
+ memcpy(pbuf, dir->id, dir->N);
+ pbuf[dir->N] = 0;
+ L->push(pbuf, dir->N);
+ } else {
+ L->push();
+ }
+ }
+
+ return r;
+}
+
+
+ /***************************\
+|** class direntry exports **|
+ \***************************/
+
+typedef isobuilder::Date cddate;
+
+Luacddate::Luacddate(isobuilder::Date * _date) : date(_date) { }
+
+enum cddate_methods_t {
+ CDDATE_INDEX = 0,
+ CDDATE_NEWINDEX,
+};
+
+enum cddate_functions_t {
+ CDDATE_NEWCDDATE = 0,
+};
+
+struct lua_functypes_t cddate_methods[] = {
+ { CDDATE_INDEX, "index", 1, 1, {LUA_STRING} },
+ { CDDATE_NEWINDEX, "newindex", 2, 2, {LUA_STRING, LUA_NUMBER} },
+ { -1, 0, 0, 0, 0 }
+};
+
+struct lua_functypes_t cddate_functions[] = {
+ { CDDATE_NEWCDDATE, "cddate", 0, 0, 0 },
+ { -1, 0, 0, 0, 0 }
+};
+
+class sLua_cddate : public Base {
+ public:
+ DECLARE_METHOD(cddate, CDDATE_INDEX);
+ DECLARE_METHOD(cddate, CDDATE_NEWINDEX);
+ DECLARE_FUNCTION(cddate, CDDATE_NEWCDDATE);
+ private:
+ static int cddate_proceed(Lua * L, int n, cddate * obj, int caller);
+ static int cddate_proceed_statics(Lua * L, int n, int caller);
+};
+
+void Luacddate::pushmembers(Lua * L) {
+ pushme(L, date, false);
+
+ PUSH_METAMETHOD(cddate, CDDATE_INDEX);
+ PUSH_METAMETHOD(cddate, CDDATE_NEWINDEX);
+}
+
+void Luacddate::pushstatics(Lua * L) throw (GeneralException) {
+ CHECK_METHODS(cddate);
+ CHECK_FUNCTIONS(cddate);
+
+ PUSH_FUNCTION(cddate, CDDATE_NEWCDDATE);
+}
+
+int sLua_cddate::cddate_proceed(Lua * L, int n, cddate * date, int caller) {
+ int r, value;
+ String key;
+
+ switch (caller) {
+ case CDDATE_INDEX:
+ key = L->tostring(2);
+ r = 1;
+ if (key == "year") {
+ L->push((lua_Number) date->year);
+ } else if (key == "month") {
+ L->push((lua_Number) date->month);
+ } else if (key == "day") {
+ L->push((lua_Number) date->day);
+ } else if (key == "hour") {
+ L->push((lua_Number) date->hour);
+ } else if (key == "minute") {
+ L->push((lua_Number) date->minute);
+ } else if (key == "second") {
+ L->push((lua_Number) date->second);
+ } else if (key == "hundredths") {
+ L->push((lua_Number) date->hundredths);
+ } else if (key == "offset") {
+ L->push((lua_Number) date->offset);
+ } else {
+ L->error("Key " + key + " not in class Date");
+ }
+ break;
+ case CDDATE_NEWINDEX:
+ r = 0;
+ key = L->tostring(2);
+ value = L->tonumber(3);
+ if (key == "year") {
+ date->year = value;
+ } else if (key == "month") {
+ date->month = value;
+ } else if (key == "day") {
+ date->day = value;
+ } else if (key == "hour") {
+ date->hour = value;
+ } else if (key == "minute") {
+ date->minute = value;
+ } else if (key == "second") {
+ date->second = value;
+ } else if (key == "hundredths") {
+ date->hundredths = value;
+ } else if (key == "offset") {
+ date->offset = value;
+ } else {
+ L->error("Key " + key + " not in class Date");
+ }
+ break;
+ }
+
+ return r;
+}
+
+int sLua_cddate::cddate_proceed_statics(Lua * L, int n, int caller) {
+ int r = 0;
+
+ switch (caller) {
+ case CDDATE_NEWCDDATE:
+ {
+ Luacddate t(new isobuilder::Date());
+ t.pushdestruct(L);
+ }
+ }
+
+ return r;
+}
+
+ /**********************\
+|** class PVD exports **|
+ \**********************/
+
+typedef isobuilder::PVD PVD;
+
+LuaPVD::LuaPVD(struct isobuilder::PVD * _pvd) : pvd(_pvd) { }
+
+enum PVD_methods_t {
+ PVD_INDEX = 0,
+ PVD_NEWINDEX,
+};
+
+enum PVD_functions_t {
+ PVD_NEWPVD = 0,
+};
+
+struct lua_functypes_t PVD_methods[] = {
+ { PVD_INDEX, "index", 1, 1, {LUA_ANY} },
+ { PVD_NEWINDEX, "newindex", 2, 2, {LUA_ANY, LUA_ANY} },
+ { -1, 0, 0, 0, 0 }
+};
+
+struct lua_functypes_t PVD_functions[] = {
+ { PVD_NEWPVD, "PVD", 0, 0, 0 },
+ { -1, 0, 0, 0, 0 }
+};
+
+class sLua_PVD : public Base {
+ public:
+ DECLARE_METHOD(PVD, PVD_INDEX);
+ DECLARE_METHOD(PVD, PVD_NEWINDEX);
+
+ DECLARE_FUNCTION(PVD, PVD_NEWPVD);
+
+ private:
+ static int PVD_proceed(Lua * L, int n, PVD * obj, int caller);
+ static int PVD_proceed_statics(Lua * L, int n, int caller);
+};
+
+void LuaPVD::pushmembers(Lua * L) {
+ pushme(L, pvd, false);
+
+ PUSH_METAMETHOD(PVD, PVD_INDEX);
+ PUSH_METAMETHOD(PVD, PVD_NEWINDEX);
+}
+
+void LuaPVD::pushstatics(Lua * L) throw (GeneralException) {
+ CHECK_METHODS(PVD);
+ CHECK_FUNCTIONS(PVD);
+
+ PUSH_FUNCTION(PVD, PVD_NEWPVD);
+}
+
+int sLua_PVD::PVD_proceed(Lua * L, int n, PVD * pvd, int caller) {
+ int r = 0, key_i = 0, value_i;
+ String key_s, value_s;
+ cddate * value_date;
+ bool invalid = false, keyisstring;
+
+ if (L->isnumber(2)) {
+ keyisstring = false;
+ key_i = L->tonumber(2);
+ } else {
+ keyisstring = true;
+ key_s = L->tostring(2);
+ }
+
+ switch (caller) {
+ case PVD_INDEX:
+ r = 1;
+ if (keyisstring && (key_s == "sysid")) {
+ L->push(pvd->sysid);
+ } else if (keyisstring && (key_s == "volid")) {
+ L->push(pvd->volid);
+ } else if (keyisstring && (key_s == "volsetid")) {
+ L->push(pvd->volsetid);
+ } else if (keyisstring && (key_s == "pubid")) {
+ L->push(pvd->pubid);
+ } else if (keyisstring && (key_s == "prepid")) {
+ L->push(pvd->prepid);
+ } else if (keyisstring && (key_s == "appid")) {
+ L->push(pvd->appid);
+ } else if (keyisstring && (key_s == "copyright")) {
+ L->push(pvd->copyright);
+ } else if (keyisstring && (key_s == "abstract")) {
+ L->push(pvd->abstract);
+ } else if (keyisstring && (key_s == "biblio")) {
+ L->push(pvd->biblio);
+ } else if (keyisstring && (key_s == "volcreat")) {
+ {
+ Luacddate date(&pvd->volcreat);
+ date.push(L);
+ }
+ } else if (keyisstring && (key_s == "modif")) {
+ {
+ Luacddate date(&pvd->modif);
+ date.push(L);
+ }
+ } else if (keyisstring && (key_s == "volexp")) {
+ {
+ Luacddate date(&pvd->volexp);
+ date.push(L);
+ }
+ } else if (keyisstring && (key_s == "voleff")) {
+ {
+ Luacddate date(&pvd->voleff);
+ date.push(L);
+ }
+ } else if (!keyisstring && (key_i >= 0) && (key_i < 512)) {
+ L->push((lua_Number) pvd->appdata[key_i]);
+ } else {
+ invalid = true;
+ }
+ break;
+ case PVD_NEWINDEX:
+ if (keyisstring && (key_s == "sysid")) {
+ if (L->isstring(3)) {
+ value_s = L->tostring(3);
+ pvd->sysid = value_s;
+ } else {
+ invalid = true;
+ }
+ } else if (keyisstring && (key_s == "volid")) {
+ if (L->isstring(3)) {
+ value_s = L->tostring(3);
+ pvd->volid = value_s;
+ } else {
+ invalid = true;
+ }
+ } else if (keyisstring && (key_s == "volsetid")) {
+ if (L->isstring(3)) {
+ value_s = L->tostring(3);
+ pvd->volsetid = value_s;
+ } else {
+ invalid = true;
+ }
+ } else if (keyisstring && (key_s == "pubid")) {
+ if (L->isstring(3)) {
+ value_s = L->tostring(3);
+ pvd->pubid = value_s;
+ } else {
+ invalid = true;
+ }
+ } else if (keyisstring && (key_s == "prepid")) {
+ if (L->isstring(3)) {
+ value_s = L->tostring(3);
+ pvd->prepid = value_s;
+ } else {
+ invalid = true;
+ }
+ } else if (keyisstring && (key_s == "appid")) {
+ if (L->isstring(3)) {
+ value_s = L->tostring(3);
+ pvd->appid = value_s;
+ } else {
+ invalid = true;
+ }
+ } else if (keyisstring && (key_s == "copyright")) {
+ if (L->isstring(3)) {
+ value_s = L->tostring(3);
+ pvd->copyright = value_s;
+ } else {
+ invalid = true;
+ }
+ } else if (keyisstring && (key_s == "abstract")) {
+ if (L->isstring(3)) {
+ value_s = L->tostring(3);
+ pvd->abstract = value_s;
+ } else {
+ invalid = true;
+ }
+ } else if (keyisstring && (key_s == "biblio")) {
+ if (L->isstring(3)) {
+ value_s = L->tostring(3);
+ pvd->biblio = value_s;
+ } else {
+ invalid = true;
+ }
+ } else if (keyisstring && (key_s == "volcreat")) {
+ if (L->islightuserdata(3)) {
+ value_date = (cddate *) LuaObject::getme(L, 3);
+ pvd->volcreat = *value_date;
+ } else {
+ invalid = true;
+ }
+ } else if (keyisstring && (key_s == "modif")) {
+ if (L->islightuserdata(3)) {
+ value_date = (cddate *) LuaObject::getme(L, 3);
+ pvd->modif = *value_date;
+ } else {
+ invalid = true;
+ }
+ } else if (keyisstring && (key_s == "volexp")) {
+ if (L->islightuserdata(3)) {
+ value_date = (cddate *) LuaObject::getme(L, 3);
+ pvd->volexp = *value_date;
+ } else {
+ invalid = true;
+ }
+ } else if (keyisstring && (key_s == "voleff")) {
+ if (L->islightuserdata(3)) {
+ value_date = (cddate *) LuaObject::getme(L, 3);
+ pvd->voleff = *value_date;
+ } else {
+ invalid = true;
+ }
+ } else if (!keyisstring && (key_i >= 0) && (key_i < 512)) {
+ if (L->isnumber(3)) {
+ pvd->appdata[key_i] = L->tonumber(3);
+ } else {
+ invalid = true;
+ }
+ } else {
+ invalid = true;
+ }
+ break;
+ }
+
+ if (invalid) {
+ L->error("Invalid usage of structure PVD");
+ }
+
+ return r;
+}
+
+int sLua_PVD::PVD_proceed_statics(Lua * L, int n, int caller) {
+ int r = 0;
+
+ switch (caller) {
+ case PVD_NEWPVD:
+ r = 1;
+ {
+ LuaPVD pvd((PVD *) malloc(sizeof(PVD)));
+ pvd.pushdestruct(L);
+ }
+ break;
+ }
+
+ return r;
+}
+
+
+ /**************************\
+|** class DirTree exports **|
+ \**************************/
+
+typedef isobuilder::DirTree DirTree;
+
+LuaDirTree::LuaDirTree(isobuilder::DirTree * _dir) : dir(_dir) { }
+
+enum DirTree_methods_t {
+ DIRTREE_INDEX = 0,
+ DIRTREE_NEWINDEX,
+ DIRTREE_FROMDIR,
+ DIRTREE_SETBASICSXA,
+ DIRTREE_FIND,
+};
+
+enum DirTree_functions_t {
+ DIRTREE_NEWDIRTREE = 0,
+};
+
+struct lua_functypes_t DirTree_methods[] = {
+ { DIRTREE_INDEX, "index", 1, 1, {LUA_STRING} },
+ { DIRTREE_NEWINDEX, "newindex", 2, 2, {LUA_STRING, LUA_ANY} },
+ { DIRTREE_FROMDIR, "fromdir", 1, 1, {LUA_OBJECT} },
+ { DIRTREE_SETBASICSXA, "setbasicsxa", 0, 0, 0 },
+ { DIRTREE_FIND, "find", 1, 1, {LUA_STRING} },
+ { -1, 0, 0, 0, 0 }
+};
+
+struct lua_functypes_t DirTree_functions[] = {
+ { DIRTREE_NEWDIRTREE, "DirTree", 1, 2, {LUA_OBJECT, LUA_BOOLEAN} },
+ { -1, 0, 0, 0, 0 }
+};
+
+class sLua_DirTree : public Base {
+ public:
+ DECLARE_METHOD(DirTree, DIRTREE_INDEX);
+ DECLARE_METHOD(DirTree, DIRTREE_NEWINDEX);
+ DECLARE_METHOD(DirTree, DIRTREE_FROMDIR);
+ DECLARE_METHOD(DirTree, DIRTREE_SETBASICSXA);
+ DECLARE_METHOD(DirTree, DIRTREE_FIND);
+
+ DECLARE_FUNCTION(DirTree, DIRTREE_NEWDIRTREE);
+ private:
+ static int DirTree_proceed(Lua * L, int n, DirTree * obj, int caller);
+ static int DirTree_proceed_statics(Lua * L, int n, int caller);
+};
+
+void LuaDirTree::pushmembers(Lua * L) {
+ pushme(L, dir);
+
+ PUSH_METAMETHOD(DirTree, DIRTREE_INDEX);
+ PUSH_METAMETHOD(DirTree, DIRTREE_NEWINDEX);
+
+ PUSH_METHOD(DirTree, DIRTREE_FROMDIR);
+ PUSH_METHOD(DirTree, DIRTREE_SETBASICSXA);
+ PUSH_METHOD(DirTree, DIRTREE_FIND);
+}
+
+void LuaDirTree::pushstatics(Lua * L) throw (GeneralException) {
+ CHECK_METHODS(DirTree);
+ CHECK_FUNCTIONS(DirTree);
+
+ PUSH_FUNCTION(DirTree, DIRTREE_NEWDIRTREE);
+}
+
+int sLua_DirTree::DirTree_proceed(Lua * L, int n, DirTree * dir, int caller) {
+ int r = 0, value_i;
+ direntry * dirent;
+ DirTree * rdir;
+ String f, key, value_s;
+ bool invalid = false, value_b;
+ cddate * value_date;
+
+ switch (caller) {
+ case DIRTREE_FROMDIR:
+ dirent = (direntry *) LuaObject::getme(L, 2);
+ dir->fromdir(dirent);
+ break;
+ case DIRTREE_SETBASICSXA:
+ dir->setbasicsxa();
+ break;
+ case DIRTREE_FIND:
+ f = L->tostring(2);
+ rdir = dir->Find(f);
+ if (rdir) {
+ LuaDirTree dirt(rdir);
+ dirt.push(L);
+ } else {
+ L->push();
+ }
+ break;
+ case DIRTREE_INDEX:
+ key = L->tostring(2);
+ r = 1;
+ if (key == "sector") {
+ L->push((lua_Number) dir->sector);
+ } else if (key == "size") {
+ L->push((lua_Number) dir->size);
+ } else if (key == "hidden") {
+ L->push(dir->hidden);
+ } else if (key == "hardhide") {
+ L->push(dir->hardhide);
+ } else if (key == "name") {
+ L->push(dir->name);
+ } else if (key == "creation") {
+ Luacddate date(&dir->creation);
+ date.push(L);
+ } else if (key == "have_xa") {
+ L->push(dir->have_xa);
+ } else if (key == "xa_dir") {
+ L->push(dir->xa_dir);
+ } else if (key == "xa_audio") {
+ L->push(dir->xa_audio);
+ } else if (key == "xa_str") {
+ L->push(dir->xa_str);
+ } else if (key == "xa_xa") {
+ L->push(dir->xa_xa);
+ } else if (key == "xa_form1") {
+ L->push(dir->xa_form1);
+ } else if (key == "mode") {
+ L->push((lua_Number) dir->mode);
+ } else if (key == "father") {
+ LuaDirTree tdir(dir->Father());
+ tdir.push(L);
+ } else if (key == "child") {
+ LuaDirTree tdir(dir->Child());
+ tdir.push(L);
+ } else if (key == "brother") {
+ LuaDirTree tdir(dir->Brother());
+ tdir.push(L);
+ } else if (key == "isdir") {
+ L->push(dir->isdir());
+ } else {
+ invalid = true;
+ }
+ break;
+ case DIRTREE_NEWINDEX:
+ key = L->tostring(2);
+ if (key == "sector") {
+ if (L->isnumber(3)) {
+ value_i = L->tonumber(3);
+ dir->sector = value_i;
+ } else {
+ invalid = true;
+ }
+ } else if (key == "size") {
+ if (L->isnumber(3)) {
+ value_i = L->tonumber(3);
+ dir->size = value_i;
+ } else {
+ invalid = true;
+ }
+ } else if (key == "hidden") {
+ if (L->isboolean(3)) {
+ value_b = L->toboolean(3);
+ dir->hidden = value_b;
+ } else {
+ invalid = true;
+ }
+ } else if (key == "hardhide") {
+ if (L->isboolean(3)) {
+ value_b = L->toboolean(3);
+ dir->hardhide = value_b;
+ } else {
+ invalid = true;
+ }
+ } else if (key == "name") {
+ if (L->isstring(3)) {
+ value_s = L->tostring(3);
+ dir->name = value_s;
+ } else {
+ invalid = true;
+ }
+ } else if (key == "creation") {
+ if (L->islightuserdata(3)) {
+ value_date = (cddate *) LuaObject::getme(L, 3);
+ dir->creation = *value_date;
+ } else {
+ invalid = true;
+ }
+ } else if (key == "have_xa") {
+ if (L->isboolean(3)) {
+ value_b = L->toboolean(3);
+ dir->have_xa = value_b;
+ } else {
+ invalid = true;
+ }
+ } else if (key == "xa_dir") {
+ if (L->isboolean(3)) {
+ value_b = L->toboolean(3);
+ dir->xa_dir = value_b;
+ } else {
+ invalid = true;
+ }
+ } else if (key == "xa_audio") {
+ if (L->isboolean(3)) {
+ value_b = L->toboolean(3);
+ dir->xa_audio = value_b;
+ } else {
+ invalid = true;
+ }
+ } else if (key == "xa_str") {
+ if (L->isboolean(3)) {
+ value_b = L->toboolean(3);
+ dir->xa_str = value_b;
+ } else {
+ invalid = true;
+ }
+ } else if (key == "xa_xa") {
+ if (L->isboolean(3)) {
+ value_b = L->toboolean(3);
+ dir->xa_xa = value_b;
+ } else {
+ invalid = true;
+ }
+ } else if (key == "xa_form1") {
+ if (L->isboolean(3)) {
+ value_b = L->toboolean(3);
+ dir->xa_form1 = value_b;
+ } else {
+ invalid = true;
+ }
+ } else if (key == "mode") {
+ if (L->isnumber(3)) {
+ value_i = L->tonumber(3);
+ dir->mode = value_i;
+ } else {
+ invalid = true;
+ }
+ } else {
+ invalid = true;
+ }
+ break;
+ }
+
+ if (invalid) {
+ L->error("Invalid usage of structure DirTree");
+ }
+
+ return r;
+}
+
+int sLua_DirTree::DirTree_proceed_statics(Lua * L, int n, int caller) {
+ int r;
+ DirTree * father;
+ bool dir = true;
+
+ switch (caller) {
+ case DIRTREE_NEWDIRTREE:
+ father = (DirTree *) LuaObject::getme(L, 1);
+ if (n == 2)
+ dir = L->toboolean(2);
+ {
+ LuaDirTree dirt(new DirTree(father, dir));
+ dirt.pushdestruct(L);
+ }
+ break;
+ }
+
+ return r;
+}
+
+
+ /*****************************\
+|** class isobuilder exports **|
+ \*****************************/
+
+Luaisobuilder::Luaisobuilder(isobuilder * _iso) : iso(_iso) { }
+
+enum isobuilder_methods_t {
+ ISOBUILDER_FOREWORD = 0,
+ ISOBUILDER_FOREWORD_HANDLE,
+ ISOBUILDER_FOREWORD_ARRAY,
+ ISOBUILDER_GETDISPSECT,
+ ISOBUILDER_PUTFILE,
+ ISOBUILDER_PUTDATAS,
+ ISOBUILDER_CREATESECTOR,
+ ISOBUILDER_SETEOF,
+ ISOBUILDER_CLEAREOF,
+ ISOBUILDER_SETBASICS,
+ ISOBUILDER_CREATEDIR,
+ ISOBUILDER_CREATEFILE,
+ ISOBUILDER_COPYDIR,
+ ISOBUILDER_CLOSE,
+};
+
+enum isobuilder_functions_t {
+ ISOBUILDER_NEWISOBUILDER = 0,
+ ISOBUILDER_CREATEPVD_HANDLE,
+ ISOBUILDER_CREATEPVD,
+ ISOBUILDER_CREATEPVD_ARRAY,
+};
+
+struct lua_functypes_t isobuilder_methods[] = {
+ { ISOBUILDER_FOREWORD, "foreword", 1, 1, {LUA_OBJECT} },
+ { ISOBUILDER_FOREWORD_HANDLE, "foreword_handle", 1, 2, {LUA_OBJECT, LUA_NUMBER} },
+ { ISOBUILDER_FOREWORD_ARRAY, "foreword_array", 1, 2, {LUA_TABLE, LUA_NUMBER} },
+ { ISOBUILDER_GETDISPSECT, "getdispsect", 0, 0, 0},
+ { ISOBUILDER_PUTFILE, "putfile", 1, 3, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER} },
+ { ISOBUILDER_PUTDATAS, "putdatas", 2, 4, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
+ { ISOBUILDER_CREATESECTOR, "createsector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} },
+ { ISOBUILDER_SETEOF, "setEOF", 0, 0, 0 },
+ { ISOBUILDER_CLEAREOF, "clearEOF", 0, 0, 0 },
+ { ISOBUILDER_SETBASICS, "setbasics", 1, 5, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
+ { ISOBUILDER_CREATEDIR, "createdir", 2, 5, {LUA_OBJECT, LUA_STRING, LUA_NUMBER, LUA_OBJECT, LUA_NUMBER} },
+ { ISOBUILDER_CREATEFILE, "createfile", 3, 5, {LUA_OBJECT, LUA_STRING, LUA_OBJECT, LUA_OBJECT, LUA_NUMBER} },
+ { ISOBUILDER_COPYDIR, "copydir", 3, 4, {LUA_OBJECT, LUA_OBJECT, LUA_OBJECT, LUA_NUMBER} },
+ { ISOBUILDER_CLOSE, "close", 0, 3, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER} },
+ { -1, 0, 0, 0, 0 }
+};
+
+struct lua_functypes_t isobuilder_functions[] = {
+ { ISOBUILDER_NEWISOBUILDER, "isobuilder", 1, 2, {LUA_OBJECT, LUA_NUMBER} },
+ { ISOBUILDER_CREATEPVD_HANDLE, "createpvd_handle", 1, 1, {LUA_OBJECT} },
+ { ISOBUILDER_CREATEPVD, "createpvd", 1, 1, {LUA_OBJECT} },
+ { ISOBUILDER_CREATEPVD_ARRAY, "createpvd_array", 1, 1, {LUA_TABLE} },
+ { -1, 0, 0, 0, 0 }
+};
+
+class sLua_isobuilder : public Base {
public:
- Luacdfile(cdfile * h) : LuaHandle(h) {}
+ DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD);
+ DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD_HANDLE);
+ DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD_ARRAY);
+ DECLARE_METHOD(isobuilder, ISOBUILDER_GETDISPSECT);
+ DECLARE_METHOD(isobuilder, ISOBUILDER_PUTFILE);
+ DECLARE_METHOD(isobuilder, ISOBUILDER_PUTDATAS);
+ DECLARE_METHOD(isobuilder, ISOBUILDER_CREATESECTOR);
+ DECLARE_METHOD(isobuilder, ISOBUILDER_SETEOF);
+ DECLARE_METHOD(isobuilder, ISOBUILDER_CLEAREOF);
+ DECLARE_METHOD(isobuilder, ISOBUILDER_SETBASICS);
+ DECLARE_METHOD(isobuilder, ISOBUILDER_CREATEDIR);
+ DECLARE_METHOD(isobuilder, ISOBUILDER_CREATEFILE);
+ DECLARE_METHOD(isobuilder, ISOBUILDER_COPYDIR);
+ DECLARE_METHOD(isobuilder, ISOBUILDER_CLOSE);
+
+ DECLARE_FUNCTION(isobuilder, ISOBUILDER_NEWISOBUILDER);
+ DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_HANDLE);
+ DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD);
+ DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_ARRAY);
+
+ private:
+ static int isobuilder_proceed(Lua * L, int n, isobuilder * obj, int caller);
+ static int isobuilder_proceed_statics(Lua * L, int n, int caller);
};
- -enum cdutils_methods_t { - CDUTILS_SETISOW = 0, - CDUTILS_GUESSTYPE, - CDUTILS_SECTORSEEK, - CDUTILS_READSECTOR, - CDUTILS_READDATAS, - CDUTILS_READFILE, - CDUTILS_WRITESECTOR, - CDUTILS_WRITEDATAS, - CDUTILS_WRITEFILE, - CDUTILS_GETISOINFOS, - CDUTILS_GETPTINFOS, - CDUTILS_FINDPATH, - CDUTILS_FINDPARENT, - CDUTILS_FINDDIRENTRY, - CDUTILS_NEWCDFILE, - CDUTILS_UPDATESIZE, - CDUTILS_UPDATESECTOR, - CDUTILS_CREATESECTOR, -}; - -enum cdutils_functions_t { - CDUTILS_NEWCDUTILS = 0, - CDUTILS_SWAPWORD, - CDUTILS_SWAPDWORD, - CDUTILS_FROM_BCD, - CDUTILS_TO_BCD, - CDUTILS_IS_VALID_BCD, - CDUTILS_FROM_MSF, - CDUTILS_TO_MSF, -}; - -struct lua_functypes_t cdutils_methods[] = { - { CDUTILS_SETISOW, "set_iso_w", 1, 1, {LUA_OBJECT} }, - { CDUTILS_GUESSTYPE, "guessmode", 0, 1, {LUA_NUMBER} }, - { CDUTILS_SECTORSEEK, "sectorseek", 1, 1, {LUA_NUMBER} }, - { CDUTILS_READSECTOR, "readsector", 0, 2, {LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_READDATAS, "readdatas", 1, 3, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_READFILE, "readfile", 2, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_WRITESECTOR, "writesector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_WRITEDATAS, "writedatas", 2, 4, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_WRITEFILE, "writefile", 1, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_GETISOINFOS, "getisoinfos", 0, 0, 0 }, - { CDUTILS_GETPTINFOS, "getptinfos", 0, 0, 0 }, - { CDUTILS_FINDPATH, "findpath", 1, 1, {LUA_STRING} }, - { CDUTILS_FINDPARENT, "findparent", 1, 1, {LUA_STRING} }, - { CDUTILS_FINDDIRENTRY, "finddirentry", 2, 2, {LUA_OBJECT, LUA_STRING} }, - { CDUTILS_NEWCDFILE, "cdfile", 1, 3, {LUA_ANY, LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_UPDATESIZE, "updatesize", 2, 2, {LUA_STRING, LUA_NUMBER} }, - { CDUTILS_UPDATESECTOR, "updatesector", 2, 2, {LUA_STRING, LUA_NUMBER} }, - { CDUTILS_CREATESECTOR, "createsector", 2, 3, {LUA_NUMBER, LUA_NUMBER, LUA_BOOLEAN} }, - { -1, 0, 0, 0, 0 } -}; - -struct lua_functypes_t cdutils_functions[] = { - { CDUTILS_NEWCDUTILS, "cdutils" , 1, 2, {LUA_OBJECT, LUA_OBJECT} }, - { CDUTILS_SWAPWORD, "swapword", 1, 1, {LUA_NUMBER} }, - { CDUTILS_SWAPDWORD, "swapdword", 1, 1, {LUA_NUMBER} }, - { CDUTILS_FROM_BCD, "from_BCD", 1, 1, {LUA_NUMBER} }, - { CDUTILS_TO_BCD, "to_BCD", 1, 1, {LUA_NUMBER} }, - { CDUTILS_IS_VALID_BCD, "is_valid_BCD", 1, 1, {LUA_NUMBER} }, - { CDUTILS_FROM_MSF, "from_MSF", 1, 4, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, - { CDUTILS_TO_MSF, "to_MSF", 1, 2, {LUA_NUMBER, LUA_NUMBER} }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_cdutils : public Base { - public: - DECLARE_METHOD(cdutils, CDUTILS_SETISOW); - DECLARE_METHOD(cdutils, CDUTILS_GUESSTYPE); - DECLARE_METHOD(cdutils, CDUTILS_SECTORSEEK); - DECLARE_METHOD(cdutils, CDUTILS_READSECTOR); - DECLARE_METHOD(cdutils, CDUTILS_READDATAS); - DECLARE_METHOD(cdutils, CDUTILS_READFILE); - DECLARE_METHOD(cdutils, CDUTILS_WRITESECTOR); - DECLARE_METHOD(cdutils, CDUTILS_WRITEDATAS); - DECLARE_METHOD(cdutils, CDUTILS_WRITEFILE); - DECLARE_METHOD(cdutils, CDUTILS_GETISOINFOS); - DECLARE_METHOD(cdutils, CDUTILS_GETPTINFOS); - DECLARE_METHOD(cdutils, CDUTILS_FINDPATH); - DECLARE_METHOD(cdutils, CDUTILS_FINDPARENT); - DECLARE_METHOD(cdutils, CDUTILS_FINDDIRENTRY); - DECLARE_METHOD(cdutils, CDUTILS_NEWCDFILE); - DECLARE_METHOD(cdutils, CDUTILS_UPDATESIZE); - DECLARE_METHOD(cdutils, CDUTILS_UPDATESECTOR); - DECLARE_METHOD(cdutils, CDUTILS_CREATESECTOR); - - DECLARE_FUNCTION(cdutils, CDUTILS_NEWCDUTILS); - DECLARE_FUNCTION(cdutils, CDUTILS_SWAPWORD); - DECLARE_FUNCTION(cdutils, CDUTILS_SWAPDWORD); - DECLARE_FUNCTION(cdutils, CDUTILS_FROM_BCD); - DECLARE_FUNCTION(cdutils, CDUTILS_TO_BCD); - DECLARE_FUNCTION(cdutils, CDUTILS_IS_VALID_BCD); - DECLARE_FUNCTION(cdutils, CDUTILS_FROM_MSF); - DECLARE_FUNCTION(cdutils, CDUTILS_TO_MSF); - - private: - static int cdutils_proceed(Lua * L, int n, cdutils * obj, int caller); - static int cdutils_proceed_statics(Lua * L, int n, int caller); -}; - -void Luacdutils::pushmembers(Lua * L) { - pushme(L, cd); - - PUSH_METHOD(cdutils, CDUTILS_SETISOW); - PUSH_METHOD(cdutils, CDUTILS_GUESSTYPE); - PUSH_METHOD(cdutils, CDUTILS_SECTORSEEK); - PUSH_METHOD(cdutils, CDUTILS_READSECTOR); - PUSH_METHOD(cdutils, CDUTILS_READDATAS); - PUSH_METHOD(cdutils, CDUTILS_READFILE); - PUSH_METHOD(cdutils, CDUTILS_WRITESECTOR); - PUSH_METHOD(cdutils, CDUTILS_WRITEDATAS); - PUSH_METHOD(cdutils, CDUTILS_WRITEFILE); - PUSH_METHOD(cdutils, CDUTILS_GETISOINFOS); - PUSH_METHOD(cdutils, CDUTILS_GETPTINFOS); - PUSH_METHOD(cdutils, CDUTILS_FINDPATH); - PUSH_METHOD(cdutils, CDUTILS_FINDPARENT); - PUSH_METHOD(cdutils, CDUTILS_FINDDIRENTRY); - PUSH_METHOD(cdutils, CDUTILS_NEWCDFILE); - PUSH_METHOD(cdutils, CDUTILS_UPDATESIZE); - PUSH_METHOD(cdutils, CDUTILS_UPDATESECTOR); - PUSH_METHOD(cdutils, CDUTILS_CREATESECTOR); -} - -void Luacdutils::pushstatics(Lua * L) throw (GeneralException) { - CHECK_METHODS(cdutils); - CHECK_FUNCTIONS(cdutils); - - PUSH_FUNCTION(cdutils, CDUTILS_NEWCDUTILS); - PUSH_FUNCTION(cdutils, CDUTILS_SWAPWORD); - PUSH_FUNCTION(cdutils, CDUTILS_SWAPDWORD); - PUSH_FUNCTION(cdutils, CDUTILS_FROM_BCD); - PUSH_FUNCTION(cdutils, CDUTILS_TO_BCD); - PUSH_FUNCTION(cdutils, CDUTILS_IS_VALID_BCD); - PUSH_FUNCTION(cdutils, CDUTILS_FROM_MSF); - PUSH_FUNCTION(cdutils, CDUTILS_TO_MSF); - - L->push("MODE0"); - L->push((lua_Number) MODE0); - L->setvar(); - - L->push("MODE1"); - L->push((lua_Number) MODE1); - L->setvar(); - - L->push("MODE2"); - L->push((lua_Number) MODE2); - L->setvar(); - - L->push("MODE2_FORM1"); - L->push((lua_Number) MODE2_FORM1); - L->setvar(); - - L->push("MODE2_FORM2"); - L->push((lua_Number) MODE2_FORM2); - L->setvar(); - - L->push("MORE_RAW"); - L->push((lua_Number) MODE_RAW); - L->setvar(); - - L->push("GUESS"); - L->push((lua_Number) GUESS); - L->setvar(); - - int i; - - L->push("sec_sizes"); - L->newtable(); - for (i = 0; i <= GUESS; i++) { - L->push((lua_Number) i); - L->push((lua_Number) sec_sizes[i]); - L->settable(); - } - L->setvar(); - - L->push("sec_offsts"); - L->newtable(); - for (i = 0; i <= GUESS; i++) { - L->push((lua_Number) i); - L->push((lua_Number) sec_offsts[i]); - L->settable(); - } - L->setvar(); - - L->push("sec_modes"); - L->newtable(); - for (i = 0; i <= GUESS; i++) { - L->push((lua_Number) i); - L->push(sec_modes[i]); - L->settable(); - } - L->setvar(); -} - -int sLua_cdutils::cdutils_proceed(Lua * L, int n, cdutils * cd, int caller) { - int r = 0, sect = -1, mode = GUESS, size = -1, i; - Handle * h; - Byte sdatas[2352], * datas; - String path; - cdutils::DirEntry * dir, * bdir, * adir, pdir; - bool invalid = false, eof = false; - int sector; - cdfile * cdf; - - switch(caller) { - case CDUTILS_SETISOW: - h = (Handle *) LuaObject::getme(L, 2); - cd->set_iso_w(h); - break; - case CDUTILS_GUESSTYPE: - if (n == 1) { - sect = L->tonumber(2); - } - L->push((lua_Number) cd->guess_type(sect)); - r = 1; - break; - case CDUTILS_SECTORSEEK: - sect = L->tonumber(2); - cd->sector_seek(sect); - break; - case CDUTILS_READSECTOR: - if (n >= 1) - sect = L->tonumber(2); - if (n == 2) - mode = L->tonumber(3); - size = cd->read_sector(sdatas, mode, sect); - L->newtable(); - for (i = 0; i < size; i++) { - L->push((lua_Number) i); - L->push((lua_Number) sdatas[i]); - L->settable(); - } - r = 1; - break; - case CDUTILS_READDATAS: - size = L->tonumber(2); - if (n >= 2) - sect = L->tonumber(3); - if (n == 3) - mode = L->tonumber(3); - datas = (Byte *) malloc(size); - cd->read_datas(datas, size, mode, sect); - L->newtable(); - for (i = 0; i < size; i++) { - L->push((lua_Number) i); - L->push((lua_Number) datas[i]); - L->settable(); - } - r = 1; - free(datas); - break; - case CDUTILS_READFILE: - h = (Handle *) LuaObject::getme(L, 2); - size = L->tonumber(5); - if (n >= 3) - sect = L->tonumber(4); - if (n == 4) - mode = L->tonumber(5); - cd->read_file(h, size, mode, sect); - break; - case CDUTILS_WRITESECTOR: - if (n >= 2) - sect = L->tonumber(3); - if (n == 3) - mode = L->tonumber(4); - for (i = 0; i < 2352; i++) { - L->push((lua_Number) i); - L->gettable(2); - sdatas[i] = L->tonumber(); - L->pop(); - } - cd->write_sector(datas, mode, sect); - break; - case CDUTILS_WRITEDATAS: - size = L->tonumber(3); - if (n >= 3) - sect = L->tonumber(4); - if (n == 4) - mode = L->tonumber(5); - datas = (Byte *) malloc(size); - - for (i = 0; i < size; i++) { - L->push((lua_Number) i); - L->gettable(2); - sdatas[i] = L->tonumber(); - L->pop(); - } - cd->write_datas(datas, size, mode, sect); - free(datas); - break; - case CDUTILS_WRITEFILE: - h = (Handle *) LuaObject::getme(L, 2); - if (n >= 2) - size = L->tonumber(3); - if (n >= 3) - sect = L->tonumber(4); - if (n == 4) - mode = L->tonumber(5); - cd->write_file(h, size, mode, sect); - break; - case CDUTILS_GETISOINFOS: - L->push((lua_Number) cd->get_iso_infos()); - r = 1; - break; - case CDUTILS_GETPTINFOS: - L->push((lua_Number) cd->get_pt_infos()); - r = 1; - break; - case CDUTILS_FINDPATH: - path = L->tostring(2); - bdir = cd->find_path(&datas, path); - if ((bdir) && bdir->R) { - dir = (cdutils::DirEntry *) malloc(bdir->R); - memcpy(dir, bdir, bdir->R); - } else { - dir = 0; - } - if (dir) { - Luadirentry ldir(dir); - ldir.pushdestruct(L); - } else { - L->push(); - } - r = 1; - free(datas); - break; - case CDUTILS_FINDPARENT: - path = L->tostring(2); - bdir = cd->find_parent(&datas, path); - if ((bdir) && bdir->R) { - dir = (cdutils::DirEntry *) malloc(bdir->R); - memcpy(dir, bdir, bdir->R); - } else { - dir = 0; - } - if (dir) { - Luadirentry ldir(dir); - ldir.pushdestruct(L); - } else { - L->push(); - } - r = 1; - free(datas); - break; - case CDUTILS_FINDDIRENTRY: - adir = (cdutils::DirEntry *) LuaObject::getme(L, 2); - path = L->tostring(3); - bdir = cd->find_dir_entry(&datas, adir, path); - if ((bdir) && bdir->R) { - dir = (cdutils::DirEntry *) malloc(bdir->R); - memcpy(dir, bdir, bdir->R); - } else { - dir = 0; - } - if (dir) { - Luadirentry ldir(dir); - ldir.pushdestruct(L); - } else { - L->push(); - } - r = 1; - free(datas); - break; - case CDUTILS_NEWCDFILE: - if (L->istable(2)) { - if (n <= 2) { - dir = (cdutils::DirEntry *) LuaObject::getme(L, 2); - if (n == 2) - mode = L->tonumber(3); - cdf = new cdfile(cd, dir, mode); - } else { - invalid = true; - } - } else if (L->isnumber(2)) { - if (n >= 1) { - sector = L->tonumber(2); - if (n >= 2) - size = L->tonumber(3); - if (n == 3) - mode = L->tonumber(4); - cdf = new cdfile(cd, sector, size, mode); - } else { - invalid = true; - } - } else { - invalid = true; - } - if (invalid) { - L->error("Invalid arguments to constructor of cdfile"); - } else { - Luacdfile luacdf(cdf); - luacdf.pushdestruct(L); - r = 1; - } - break; - case CDUTILS_UPDATESIZE: - case CDUTILS_UPDATESECTOR: - path = L->tostring(2); - pdir = cd->find_parent(path); - dir = cd->find_path(&datas, path); - switch (caller) { - case CDUTILS_UPDATESIZE: - dir->Size = tolittle((Uint32) L->tonumber(3)); - dir->BESize = tobig((Uint32) L->tonumber(3)); - break; - case CDUTILS_UPDATESECTOR: - dir->Sector = tolittle((Uint32) L->tonumber(3)); - dir->BESector = tobig((Uint32) L->tonumber(3)); - break; - } - cd->write_datas(datas, pdir.Size, GUESS, pdir.Sector); - free(datas); - break; - case CDUTILS_CREATESECTOR: - mode = L->tonumber(2); - sect = L->tonumber(3); - if (n == 3) - eof = L->toboolean(4); - cd->create_sector(mode, sect, eof); - break; - } - - - return r; -} - -int sLua_cdutils::cdutils_proceed_statics(Lua * L, int n, int caller) { - int r = 0; - Uint32 x; - Handle * isor = 0, * isow = 0; - Uint32 sector, msf, start = 150; - Byte m, s, f; - - switch(caller) { - case CDUTILS_NEWCDUTILS: - isor = (Handle *) LuaObject::getme(L, 1); - if (n == 2) - isow = (Handle *) LuaObject::getme(L, 2); - { - Luacdutils cd(new cdutils(isor, isow)); - cd.pushdestruct(L); - } - break; - case CDUTILS_SWAPWORD: - x = L->tonumber(); - L->push((lua_Number) cdutils::swap_word(x)); - r = 1; - break; - case CDUTILS_SWAPDWORD: - x = L->tonumber(); - L->push((lua_Number) cdutils::swap_dword(x)); - r = 1; - break; - case CDUTILS_FROM_BCD: - x = L->tonumber(); - L->push((lua_Number) cdutils::from_BCD(x)); - r = 1; - break; - case CDUTILS_TO_BCD: - x = L->tonumber(); - L->push((lua_Number) cdutils::to_BCD(x)); - r = 1; - break; - case CDUTILS_IS_VALID_BCD: - x = L->tonumber(); - L->push(cdutils::is_valid_BCD(x)); - r = 1; - break; - case CDUTILS_FROM_MSF: - if (n <= 2) { - msf = L->tonumber(1); - if (n == 2) - start = L->tonumber(2); - L->push((lua_Number) cdutils::from_MSF(msf, start)); - } else { - m = L->tonumber(1); - s = L->tonumber(2); - f = L->tonumber(3); - if (n == 4) - start = L->tonumber(4); - L->push((lua_Number) cdutils::from_MSF(m, s, f, start)); - } - r = 1; - break; - case CDUTILS_TO_MSF: - sector = L->tonumber(1); - if (n == 2) - start = L->tonumber(2); - cdutils::to_MSF(sector, m, s, f, start); - msf = cdutils::to_MSF(sector, start); - L->push((lua_Number) msf); - L->push((lua_Number) m); - L->push((lua_Number) s); - L->push((lua_Number) f); - r = 4; - break; - } - - return r; -} - - - /***************************\ -|** class direntry exports **| - \***************************/ - -typedef cdutils::DirEntry direntry; - -Luadirentry::Luadirentry(cdutils::DirEntry * _dir) : dir(_dir) { } - -enum direntry_methods_t { - DIRENTRY_INDEX = 0, - DIRENTRY_ISHIDDEN, - DIRENTRY_ISDIR, - DIRENTRY_HASXA, - DIRENTRY_ISXADIR, - DIRENTRY_ISXAAUDIO, - DIRENTRY_ISXASTR, - DIRENTRY_ISXAXA, - DIRENTRY_ISXAFORM1, -}; - -struct lua_functypes_t direntry_methods[] = { - { DIRENTRY_INDEX, "index", 1, 1, {LUA_STRING} }, - { DIRENTRY_ISHIDDEN, "ishidden", 0, 0, 0 }, - { DIRENTRY_ISDIR, "isdir", 0, 0, 0 }, - { DIRENTRY_HASXA, "hasxa", 0, 0, 0 }, - { DIRENTRY_ISXADIR, "isxadir", 0, 0, 0 }, - { DIRENTRY_ISXAAUDIO, "isxaaudio", 0, 0, 0 }, - { DIRENTRY_ISXASTR, "isxastr", 0, 0, 0 }, - { DIRENTRY_ISXAXA, "isxaxa", 0, 0, 0 }, - { DIRENTRY_ISXAFORM1, "isxaform1", 0, 0, 0 }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_direntry : public Base { - public: - DECLARE_METHOD(direntry, DIRENTRY_INDEX); - DECLARE_METHOD(direntry, DIRENTRY_ISHIDDEN); - DECLARE_METHOD(direntry, DIRENTRY_ISDIR); - DECLARE_METHOD(direntry, DIRENTRY_HASXA); - DECLARE_METHOD(direntry, DIRENTRY_ISXADIR); - DECLARE_METHOD(direntry, DIRENTRY_ISXAAUDIO); - DECLARE_METHOD(direntry, DIRENTRY_ISXASTR); - DECLARE_METHOD(direntry, DIRENTRY_ISXAXA); - DECLARE_METHOD(direntry, DIRENTRY_ISXAFORM1); - private: - static int direntry_proceed(Lua * L, int n, direntry * obj, int caller); -}; - -void Luadirentry::pushmembers(Lua * L) { - pushme(L, dir, false); - - PUSH_METAMETHOD(direntry, DIRENTRY_INDEX); - PUSH_METHOD(direntry, DIRENTRY_ISHIDDEN); - PUSH_METHOD(direntry, DIRENTRY_ISDIR); - PUSH_METHOD(direntry, DIRENTRY_HASXA); - PUSH_METHOD(direntry, DIRENTRY_ISXADIR); - PUSH_METHOD(direntry, DIRENTRY_ISXAAUDIO); - PUSH_METHOD(direntry, DIRENTRY_ISXASTR); - PUSH_METHOD(direntry, DIRENTRY_ISXAXA); - PUSH_METHOD(direntry, DIRENTRY_ISXAFORM1); -} - -int sLua_direntry::direntry_proceed(Lua * L, int n, direntry * dir, int caller) { - int r = 0, s, pad; - String index; - bool has_xa = false; - Byte * p; - - s = 33 + dir->N; - if (s & 1) { - s++; - pad = 1; - } else { - pad = 0; - } - if (s != dir->R) { - if ((s + 14) == dir->R) { - p = (Byte *) dir->id + dir->N + pad; - if ((p[6] == 'X') && (p[7] == 'A')) { - has_xa = true; - } - } - } - - switch (caller) { - case DIRENTRY_HASXA: - L->push(has_xa); - r = 1; - break; - case DIRENTRY_ISHIDDEN: - L->push(dir->Flags & 1 ? true : false); - r = 1; - break; - case DIRENTRY_ISDIR: - L->push(dir->Flags & 2 ? true : false); - r = 1; - break; - case DIRENTRY_ISXADIR: - L->push(p[4] & 0x80 ? true : false); - r = 1; - break; - case DIRENTRY_ISXAAUDIO: - L->push(p[4] & 0x40 ? true : false); - r = 1; - break; - case DIRENTRY_ISXASTR: - L->push(p[4] & 0x20 ? true : false); - r = 1; - break; - case DIRENTRY_ISXAXA: - L->push(p[4] & 0x10 ? true : false); - r = 1; - break; - case DIRENTRY_ISXAFORM1: - L->push(p[4] & 0x08 ? true : false); - r = 1; - break; - case DIRENTRY_INDEX: - index = L->tostring(); - r = 1; - if (index == "R") { - L->push((lua_Number) dir->R); - } else if (index == "NExt") { - L->push((lua_Number) dir->NExt); - } else if (index == "Sector") { - L->push((lua_Number) dir->Sector); - } else if (index == "Size") { - L->push((lua_Number) dir->Size); - } else if (index == "Year") { - L->push((lua_Number) dir->Year); - } else if (index == "Month") { - L->push((lua_Number) dir->Month); - } else if (index == "Day") { - L->push((lua_Number) dir->Day); - } else if (index == "Hour") { - L->push((lua_Number) dir->Hour); - } else if (index == "Minute") { - L->push((lua_Number) dir->Minute); - } else if (index == "Second") { - L->push((lua_Number) dir->Second); - } else if (index == "Offset") { - L->push((lua_Number) dir->Offset); - } else if (index == "Flags") { - L->push((lua_Number) dir->Flags); - } else if (index == "HandleUnit") { - L->push((lua_Number) dir->HandleUnit); - } else if (index == "HandleGap") { - L->push((lua_Number) dir->HandleGap); - } else if (index == "VolSeq") { - L->push((lua_Number) dir->VolSeq); - } else if (index == "N") { - L->push((lua_Number) dir->N); - } else if (index == "id") { - char pbuf[256]; - memcpy(pbuf, dir->id, dir->N); - pbuf[dir->N] = 0; - L->push(pbuf, dir->N); - } else { - L->push(); - } - } - - return r; -} - - - /***************************\ -|** class direntry exports **| - \***************************/ - -typedef isobuilder::Date cddate; - -Luacddate::Luacddate(isobuilder::Date * _date) : date(_date) { } - -enum cddate_methods_t { - CDDATE_INDEX = 0, - CDDATE_NEWINDEX, -}; - -enum cddate_functions_t { - CDDATE_NEWCDDATE = 0, -}; - -struct lua_functypes_t cddate_methods[] = { - { CDDATE_INDEX, "index", 1, 1, {LUA_STRING} }, - { CDDATE_NEWINDEX, "newindex", 2, 2, {LUA_STRING, LUA_NUMBER} }, - { -1, 0, 0, 0, 0 } -}; - -struct lua_functypes_t cddate_functions[] = { - { CDDATE_NEWCDDATE, "cddate", 0, 0, 0 }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_cddate : public Base { - public: - DECLARE_METHOD(cddate, CDDATE_INDEX); - DECLARE_METHOD(cddate, CDDATE_NEWINDEX); - DECLARE_FUNCTION(cddate, CDDATE_NEWCDDATE); - private: - static int cddate_proceed(Lua * L, int n, cddate * obj, int caller); - static int cddate_proceed_statics(Lua * L, int n, int caller); -}; - -void Luacddate::pushmembers(Lua * L) { - pushme(L, date, false); - - PUSH_METAMETHOD(cddate, CDDATE_INDEX); - PUSH_METAMETHOD(cddate, CDDATE_NEWINDEX); -} - -void Luacddate::pushstatics(Lua * L) throw (GeneralException) { - CHECK_METHODS(cddate); - CHECK_FUNCTIONS(cddate); - - PUSH_FUNCTION(cddate, CDDATE_NEWCDDATE); -} - -int sLua_cddate::cddate_proceed(Lua * L, int n, cddate * date, int caller) { - int r, value; - String key; - - switch (caller) { - case CDDATE_INDEX: - key = L->tostring(2); - r = 1; - if (key == "year") { - L->push((lua_Number) date->year); - } else if (key == "month") { - L->push((lua_Number) date->month); - } else if (key == "day") { - L->push((lua_Number) date->day); - } else if (key == "hour") { - L->push((lua_Number) date->hour); - } else if (key == "minute") { - L->push((lua_Number) date->minute); - } else if (key == "second") { - L->push((lua_Number) date->second); - } else if (key == "hundredths") { - L->push((lua_Number) date->hundredths); - } else if (key == "offset") { - L->push((lua_Number) date->offset); - } else { - L->error("Key " + key + " not in class Date"); - } - break; - case CDDATE_NEWINDEX: - key = L->tostring(2); - value = L->tonumber(3); - if (key == "year") { - date->year = value; - } else if (key == "month") { - date->month = value; - } else if (key == "day") { - date->day = value; - } else if (key == "hour") { - date->hour = value; - } else if (key == "minute") { - date->minute = value; - } else if (key == "second") { - date->second = value; - } else if (key == "hundredths") { - date->hundredths = value; - } else if (key == "offset") { - date->offset = value; - } else { - L->error("Key " + key + " not in class Date"); - } - break; - } - - return r; -} - -int sLua_cddate::cddate_proceed_statics(Lua * L, int n, int caller) { - int r = 0; - - switch (caller) { - case CDDATE_NEWCDDATE: - { - Luacddate t(new cddate()); - t.pushdestruct(L); - } - } - - return r; -} - - /**********************\ -|** class PVD exports **| - \**********************/ - -typedef isobuilder::PVD PVD; - -LuaPVD::LuaPVD(struct isobuilder::PVD * _pvd) : pvd(_pvd) { } - -enum PVD_methods_t { - PVD_INDEX = 0, - PVD_NEWINDEX, -}; - -enum PVD_functions_t { - PVD_NEWPVD = 0, -}; - -struct lua_functypes_t PVD_methods[] = { - { PVD_INDEX, "index", 1, 1, {LUA_ANY} }, - { PVD_NEWINDEX, "newindex", 2, 2, {LUA_ANY, LUA_ANY} }, - { -1, 0, 0, 0, 0 } -}; - -struct lua_functypes_t PVD_functions[] = { - { PVD_NEWPVD, "PVD", 0, 0, 0 }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_PVD : public Base { - public: - DECLARE_METHOD(PVD, PVD_INDEX); - DECLARE_METHOD(PVD, PVD_NEWINDEX); - - DECLARE_FUNCTION(PVD, PVD_NEWPVD); - - private: - static int PVD_proceed(Lua * L, int n, PVD * obj, int caller); - static int PVD_proceed_statics(Lua * L, int n, int caller); -}; - -void LuaPVD::pushmembers(Lua * L) { - pushme(L, pvd, false); - - PUSH_METAMETHOD(PVD, PVD_INDEX); - PUSH_METAMETHOD(PVD, PVD_NEWINDEX); -} - -void LuaPVD::pushstatics(Lua * L) throw (GeneralException) { - CHECK_METHODS(PVD); - CHECK_FUNCTIONS(PVD); - - PUSH_FUNCTION(PVD, PVD_NEWPVD); -} - -int sLua_PVD::PVD_proceed(Lua * L, int n, PVD * pvd, int caller) { - int r = 0, key_i = 0, value_i; - String key_s, value_s; - cddate * value_date; - bool invalid = false, keyisstring; - - if (L->isnumber(2)) { - keyisstring = false; - key_i = L->tonumber(2); - } else { - keyisstring = true; - key_s = L->tostring(2); - } - - switch (caller) { - case PVD_INDEX: - r = 1; - if (keyisstring && (key_s == "sysid")) { - L->push(pvd->sysid); - } else if (keyisstring && (key_s == "volid")) { - L->push(pvd->volid); - } else if (keyisstring && (key_s == "volsetid")) { - L->push(pvd->volsetid); - } else if (keyisstring && (key_s == "pubid")) { - L->push(pvd->pubid); - } else if (keyisstring && (key_s == "prepid")) { - L->push(pvd->prepid); - } else if (keyisstring && (key_s == "appid")) { - L->push(pvd->appid); - } else if (keyisstring && (key_s == "copyright")) { - L->push(pvd->copyright); - } else if (keyisstring && (key_s == "abstract")) { - L->push(pvd->abstract); - } else if (keyisstring && (key_s == "biblio")) { - L->push(pvd->biblio); - } else if (keyisstring && (key_s == "volcreat")) { - { - Luacddate date(&pvd->volcreat); - date.push(L); - } - } else if (keyisstring && (key_s == "modif")) { - { - Luacddate date(&pvd->modif); - date.push(L); - } - } else if (keyisstring && (key_s == "volexp")) { - { - Luacddate date(&pvd->volexp); - date.push(L); - } - } else if (keyisstring && (key_s == "voleff")) { - { - Luacddate date(&pvd->voleff); - date.push(L); - } - } else if (!keyisstring && (key_i >= 0) && (key_i < 512)) { - L->push((lua_Number) pvd->appdata[key_i]); - } else { - invalid = true; - } - break; - case PVD_NEWINDEX: - if (keyisstring && (key_s == "sysid")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->sysid = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "volid")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->volid = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "volsetid")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->volsetid = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "pubid")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->pubid = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "prepid")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->prepid = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "appid")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->appid = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "copyright")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->copyright = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "abstract")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->abstract = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "biblio")) { - if (L->isstring(3)) { - value_s = L->tostring(3); - pvd->biblio = value_s; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "volcreat")) { - if (L->islightuserdata(3)) { - value_date = (cddate *) LuaObject::getme(L, 3); - pvd->volcreat = *value_date; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "modif")) { - if (L->islightuserdata(3)) { - value_date = (cddate *) LuaObject::getme(L, 3); - pvd->modif = *value_date; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "volexp")) { - if (L->islightuserdata(3)) { - value_date = (cddate *) LuaObject::getme(L, 3); - pvd->volexp = *value_date; - } else { - invalid = true; - } - } else if (keyisstring && (key_s == "voleff")) { - if (L->islightuserdata(3)) { - value_date = (cddate *) LuaObject::getme(L, 3); - pvd->voleff = *value_date; - } else { - invalid = true; - } - } else if (!keyisstring && (key_i >= 0) && (key_i < 512)) { - if (L->isnumber(3)) { - pvd->appdata[key_i] = L->tonumber(3); - } else { - invalid = true; - } - } else { - invalid = true; - } - break; - } - - if (invalid) { - L->error("Invalid usage of structure PVD"); - } - - return r; -} - -int sLua_PVD::PVD_proceed_statics(Lua * L, int n, int caller) { - int r = 0; - - switch (caller) { - case PVD_NEWPVD: - r = 1; - { - LuaPVD pvd((PVD *) malloc(sizeof(PVD))); - pvd.pushdestruct(L); - } - break; - } - - return r; -} - - - /**************************\ -|** class DirTree exports **| - \**************************/ - -typedef isobuilder::DirTree DirTree; - -LuaDirTree::LuaDirTree(isobuilder::DirTree * _dir) : dir(_dir) { } - -enum DirTree_methods_t { - DIRTREE_INDEX = 0, - DIRTREE_NEWINDEX, - DIRTREE_FROMDIR, - DIRTREE_SETBASICSXA, - DIRTREE_FIND, -}; - -enum DirTree_functions_t { - DIRTREE_NEWDIRTREE = 0, -}; - -struct lua_functypes_t DirTree_methods[] = { - { DIRTREE_INDEX, "index", 1, 1, {LUA_STRING} }, - { DIRTREE_NEWINDEX, "newindex", 2, 2, {LUA_STRING, LUA_ANY} }, - { DIRTREE_FROMDIR, "fromdir", 1, 1, {LUA_OBJECT} }, - { DIRTREE_SETBASICSXA, "setbasicsxa", 0, 0, 0 }, - { DIRTREE_FIND, "find", 1, 1, {LUA_STRING} }, - { -1, 0, 0, 0, 0 } -}; - -struct lua_functypes_t DirTree_functions[] = { - { DIRTREE_NEWDIRTREE, "DirTree", 1, 2, {LUA_OBJECT, LUA_BOOLEAN} }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_DirTree : public Base { - public: - DECLARE_METHOD(DirTree, DIRTREE_INDEX); - DECLARE_METHOD(DirTree, DIRTREE_NEWINDEX); - DECLARE_METHOD(DirTree, DIRTREE_FROMDIR); - DECLARE_METHOD(DirTree, DIRTREE_SETBASICSXA); - DECLARE_METHOD(DirTree, DIRTREE_FIND); - - DECLARE_FUNCTION(DirTree, DIRTREE_NEWDIRTREE); - private: - static int DirTree_proceed(Lua * L, int n, DirTree * obj, int caller); - static int DirTree_proceed_statics(Lua * L, int n, int caller); -}; - -void LuaDirTree::pushmembers(Lua * L) { - pushme(L, dir); - - PUSH_METAMETHOD(DirTree, DIRTREE_INDEX); - PUSH_METAMETHOD(DirTree, DIRTREE_NEWINDEX); - - PUSH_METHOD(DirTree, DIRTREE_FROMDIR); - PUSH_METHOD(DirTree, DIRTREE_SETBASICSXA); - PUSH_METHOD(DirTree, DIRTREE_FIND); -} - -void LuaDirTree::pushstatics(Lua * L) throw (GeneralException) { - CHECK_METHODS(DirTree); - CHECK_FUNCTIONS(DirTree); - - PUSH_FUNCTION(DirTree, DIRTREE_NEWDIRTREE); -} - -int sLua_DirTree::DirTree_proceed(Lua * L, int n, DirTree * dir, int caller) { - int r = 0, value_i; - direntry * dirent; - DirTree * rdir; - String f, key, value_s; - bool invalid = false, value_b; - cddate * value_date; - - switch (caller) { - case DIRTREE_FROMDIR: - dirent = (direntry *) LuaObject::getme(L, 2); - dir->fromdir(dirent); - break; - case DIRTREE_SETBASICSXA: - dir->setbasicsxa(); - break; - case DIRTREE_FIND: - f = L->tostring(2); - rdir = dir->Find(f); - if (rdir) { - LuaDirTree dirt(rdir); - dirt.push(L); - } else { - L->push(); - } - break; - case DIRTREE_INDEX: - key = L->tostring(2); - r = 1; - if (key == "sector") { - L->push((lua_Number) dir->sector); - } else if (key == "size") { - L->push((lua_Number) dir->size); - } else if (key == "hidden") { - L->push(dir->hidden); - } else if (key == "hardhide") { - L->push(dir->hardhide); - } else if (key == "name") { - L->push(dir->name); - } else if (key == "creation") { - Luacddate date(&dir->creation); - date.push(L); - } else if (key == "have_xa") { - L->push(dir->have_xa); - } else if (key == "xa_dir") { - L->push(dir->xa_dir); - } else if (key == "xa_audio") { - L->push(dir->xa_audio); - } else if (key == "xa_str") { - L->push(dir->xa_str); - } else if (key == "xa_xa") { - L->push(dir->xa_xa); - } else if (key == "xa_form1") { - L->push(dir->xa_form1); - } else if (key == "mode") { - L->push((lua_Number) dir->mode); - } else if (key == "father") { - LuaDirTree tdir(dir->Father()); - tdir.push(L); - } else if (key == "child") { - LuaDirTree tdir(dir->Child()); - tdir.push(L); - } else if (key == "brother") { - LuaDirTree tdir(dir->Brother()); - tdir.push(L); - } else if (key == "isdir") { - L->push(dir->isdir()); - } else { - invalid = true; - } - break; - case DIRTREE_NEWINDEX: - key = L->tostring(2); - if (key == "sector") { - if (L->isnumber(3)) { - value_i = L->tonumber(3); - dir->sector = value_i; - } else { - invalid = true; - } - } else if (key == "size") { - if (L->isnumber(3)) { - value_i = L->tonumber(3); - dir->size = value_i; - } else { - invalid = true; - } - } else if (key == "hidden") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->hidden = value_b; - } else { - invalid = true; - } - } else if (key == "hardhide") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->hardhide = value_b; - } else { - invalid = true; - } - } else if (key == "name") { - if (L->isstring(3)) { - value_s = L->tostring(3); - dir->name = value_s; - } else { - invalid = true; - } - } else if (key == "creation") { - if (L->islightuserdata(3)) { - value_date = (cddate *) LuaObject::getme(L, 3); - dir->creation = *value_date; - } else { - invalid = true; - } - } else if (key == "have_xa") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->have_xa = value_b; - } else { - invalid = true; - } - } else if (key == "xa_dir") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->xa_dir = value_b; - } else { - invalid = true; - } - } else if (key == "xa_audio") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->xa_audio = value_b; - } else { - invalid = true; - } - } else if (key == "xa_str") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->xa_str = value_b; - } else { - invalid = true; - } - } else if (key == "xa_xa") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->xa_xa = value_b; - } else { - invalid = true; - } - } else if (key == "xa_form1") { - if (L->isboolean(3)) { - value_b = L->toboolean(3); - dir->xa_form1 = value_b; - } else { - invalid = true; - } - } else if (key == "mode") { - if (L->isnumber(3)) { - value_i = L->tonumber(3); - dir->mode = value_i; - } else { - invalid = true; - } - } else { - invalid = true; - } - break; - } - - if (invalid) { - L->error("Invalid usage of structure DirTree"); - } - - return r; -} - -int sLua_DirTree::DirTree_proceed_statics(Lua * L, int n, int caller) { - int r; - DirTree * father; - bool dir = true; - - switch (caller) { - case DIRTREE_NEWDIRTREE: - father = (DirTree *) LuaObject::getme(L, 1); - if (n == 2) - dir = L->toboolean(2); - { - LuaDirTree dirt(new DirTree(father, dir)); - dirt.pushdestruct(L); - } - break; - } - - return r; -} - - - /*****************************\ -|** class isobuilder exports **| - \*****************************/ - -Luaisobuilder::Luaisobuilder(isobuilder * _iso) : iso(_iso) { } - -enum isobuilder_methods_t { - ISOBUILDER_FOREWORD = 0, - ISOBUILDER_FOREWORD_HANDLE, - ISOBUILDER_FOREWORD_ARRAY, - ISOBUILDER_GETDISPSECT, - ISOBUILDER_PUTFILE, - ISOBUILDER_PUTDATAS, - ISOBUILDER_CREATESECTOR, - ISOBUILDER_SETEOF, - ISOBUILDER_CLEAREOF, - ISOBUILDER_SETBASICS, - ISOBUILDER_CREATEDIR, - ISOBUILDER_CREATEFILE, - ISOBUILDER_COPYDIR, - ISOBUILDER_CLOSE, -}; - -enum isobuilder_functions_t { - ISOBUILDER_NEWISOBUILDER = 0, - ISOBUILDER_CREATEPVD_HANDLE, - ISOBUILDER_CREATEPVD, - ISOBUILDER_CREATEPVD_ARRAY, -}; - -struct lua_functypes_t isobuilder_methods[] = { - { ISOBUILDER_FOREWORD, "foreword", 1, 1, {LUA_OBJECT} }, - { ISOBUILDER_FOREWORD_HANDLE, "foreword_handle", 1, 2, {LUA_OBJECT, LUA_NUMBER} }, - { ISOBUILDER_FOREWORD_ARRAY, "foreword_array", 1, 2, {LUA_TABLE, LUA_NUMBER} }, - { ISOBUILDER_GETDISPSECT, "getdispsect", 0, 0, 0}, - { ISOBUILDER_PUTFILE, "putfile", 1, 3, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER} }, - { ISOBUILDER_PUTDATAS, "putdatas", 2, 4, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, - { ISOBUILDER_CREATESECTOR, "createsector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} }, - { ISOBUILDER_SETEOF, "setEOF", 0, 0, 0 }, - { ISOBUILDER_CLEAREOF, "clearEOF", 0, 0, 0 }, - { ISOBUILDER_SETBASICS, "setbasics", 1, 5, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, - { ISOBUILDER_CREATEDIR, "createdir", 2, 5, {LUA_OBJECT, LUA_STRING, LUA_NUMBER, LUA_OBJECT, LUA_NUMBER} }, - { ISOBUILDER_CREATEFILE, "createfile", 3, 5, {LUA_OBJECT, LUA_STRING, LUA_OBJECT, LUA_OBJECT, LUA_NUMBER} }, - { ISOBUILDER_COPYDIR, "copydir", 3, 4, {LUA_OBJECT, LUA_OBJECT, LUA_OBJECT, LUA_NUMBER} }, - { ISOBUILDER_CLOSE, "close", 0, 3, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER} }, - { -1, 0, 0, 0, 0 } -}; - -struct lua_functypes_t isobuilder_functions[] = { - { ISOBUILDER_NEWISOBUILDER, "isobuilder", 1, 2, {LUA_OBJECT, LUA_NUMBER} }, - { ISOBUILDER_CREATEPVD_HANDLE, "createpvd_handle", 1, 1, {LUA_OBJECT} }, - { ISOBUILDER_CREATEPVD, "createpvd", 1, 1, {LUA_OBJECT} }, - { ISOBUILDER_CREATEPVD_ARRAY, "createpvd_array", 1, 1, {LUA_TABLE} }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_isobuilder : public Base { - public: - DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD); - DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD_HANDLE); - DECLARE_METHOD(isobuilder, ISOBUILDER_FOREWORD_ARRAY); - DECLARE_METHOD(isobuilder, ISOBUILDER_GETDISPSECT); - DECLARE_METHOD(isobuilder, ISOBUILDER_PUTFILE); - DECLARE_METHOD(isobuilder, ISOBUILDER_PUTDATAS); - DECLARE_METHOD(isobuilder, ISOBUILDER_CREATESECTOR); - DECLARE_METHOD(isobuilder, ISOBUILDER_SETEOF); - DECLARE_METHOD(isobuilder, ISOBUILDER_CLEAREOF); - DECLARE_METHOD(isobuilder, ISOBUILDER_SETBASICS); - DECLARE_METHOD(isobuilder, ISOBUILDER_CREATEDIR); - DECLARE_METHOD(isobuilder, ISOBUILDER_CREATEFILE); - DECLARE_METHOD(isobuilder, ISOBUILDER_COPYDIR); - DECLARE_METHOD(isobuilder, ISOBUILDER_CLOSE); - - DECLARE_FUNCTION(isobuilder, ISOBUILDER_NEWISOBUILDER); - DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_HANDLE); - DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD); - DECLARE_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_ARRAY); - - private: - static int isobuilder_proceed(Lua * L, int n, isobuilder * obj, int caller); - static int isobuilder_proceed_statics(Lua * L, int n, int caller); -}; - -void Luaisobuilder::pushmembers(Lua * L) { - pushme(L, iso); - - PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD); - PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD_HANDLE); - PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD_ARRAY); - PUSH_METHOD(isobuilder, ISOBUILDER_GETDISPSECT); - PUSH_METHOD(isobuilder, ISOBUILDER_PUTFILE); - PUSH_METHOD(isobuilder, ISOBUILDER_PUTDATAS); - PUSH_METHOD(isobuilder, ISOBUILDER_CREATESECTOR); - PUSH_METHOD(isobuilder, ISOBUILDER_SETEOF); - PUSH_METHOD(isobuilder, ISOBUILDER_CLEAREOF); - PUSH_METHOD(isobuilder, ISOBUILDER_SETBASICS); - PUSH_METHOD(isobuilder, ISOBUILDER_CREATEDIR); - PUSH_METHOD(isobuilder, ISOBUILDER_CREATEFILE); - PUSH_METHOD(isobuilder, ISOBUILDER_COPYDIR); - PUSH_METHOD(isobuilder, ISOBUILDER_CLOSE); -} - -void Luaisobuilder::pushstatics(Lua * L) throw (GeneralException) { - CHECK_METHODS(isobuilder); - CHECK_FUNCTIONS(isobuilder); - - PUSH_FUNCTION(isobuilder, ISOBUILDER_NEWISOBUILDER); - PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_HANDLE); - PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD); - PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_ARRAY); -} - -int sLua_isobuilder::isobuilder_proceed(Lua * L, int n, isobuilder * iso, int caller) { - int r = 0, i; - Handle * h = 0; - int mode = -1, sector = -1, rootsize = 1, ptsize = 1, nvd = 1, rootsect = -1, nsects = -1; - size_t size; - Byte datas[2352 * 16], * p; - PVD * pvd; - DirTree * dirt, * rdir; - direntry * dire = 0; - String name; - cdutils * cd; - - switch (caller) { - case ISOBUILDER_FOREWORD: - cd = (cdutils *) LuaObject::getme(L, 2); - iso->foreword(cd); - break; - case ISOBUILDER_FOREWORD_HANDLE: - mode = MODE_RAW; - h = (Handle *) LuaObject::getme(L, 2); - if (n == 2) - mode = L->tonumber(3); - iso->foreword(h, mode); - break; - case ISOBUILDER_FOREWORD_ARRAY: - mode = MODE_RAW; - if (n == 2) - mode = L->tonumber(3); - for (i = 0; i < 16 * 2352; i++) { - L->push((lua_Number) i); - L->gettable(2); - datas[i] = L->tonumber(); - L->pop(); - } - iso->foreword(datas, mode); - break; - case ISOBUILDER_GETDISPSECT: - L->push((lua_Number) iso->getdispsect()); - r = 1; - break; - case ISOBUILDER_PUTFILE: - h = (Handle *) LuaObject::getme(L, 2); - if (n >= 2) - mode = L->tonumber(3); - if (n >= 3) - sector = L->tonumber(4); - L->push((lua_Number) iso->putfile(h, mode, sector)); - r = 1; - break; - case ISOBUILDER_PUTDATAS: - size = L->tonumber(3); - if (n >= 3) - mode = L->tonumber(4); - if (n >= 4) - sector = L->tonumber(5); - p = (Byte *) malloc(size); - for (i = 0; i < size; i++) { - L->push((lua_Number) i); - L->gettable(2); - p[i] = L->tonumber(); - L->pop(); - } - L->push((lua_Number) iso->putdatas(p, size, mode, sector)); - r = 1; - free(p); - break; - case ISOBUILDER_CREATESECTOR: - if (n >= 2) - mode = L->tonumber(3); - if (n >= 3) - sector = L->tonumber(4); - for (i = 0; i < 2352; i++) { - L->push((lua_Number) i); - L->gettable(2); - datas[i] = L->tonumber(); - L->pop(); - } - L->push((lua_Number) iso->createsector(datas, mode, sector)); - r = 1; - break; - case ISOBUILDER_SETEOF: - iso->setEOF(); - break; - case ISOBUILDER_CLEAREOF: - iso->clearEOF(); - break; - case ISOBUILDER_SETBASICS: - pvd = (PVD *) LuaObject::getme(L, 2); - if (n >= 2) - rootsize = L->tonumber(3); - if (n >= 3) - ptsize = L->tonumber(4); - if (n >= 4) - nvd = L->tonumber(5); - if (n >= 5) - rootsect = L->tonumber(6); - rdir = iso->setbasics(*pvd, rootsize, ptsize, nvd, rootsect); - { - LuaDirTree t(rdir); - t.push(L); - } - r = 1; - break; - case ISOBUILDER_CREATEDIR: - size = 1; - dirt = 0; - dirt = (DirTree *) LuaObject::getme(L, 2); - name = L->tostring(3); - if (n >= 3) - size = L->tonumber(4); - if (n >= 4) - dire = (direntry *) LuaObject::getme(L, 5); - if (n >= 5) - mode = L->tonumber(6); - rdir = iso->createdir(dirt, name, size, dire, mode); - { - LuaDirTree t(rdir); - t.push(L); - } - r = 1; - break; - case ISOBUILDER_CREATEFILE: - dirt = (DirTree *) LuaObject::getme(L, 2); - name = L->tostring(3); - h = (Handle *) LuaObject::getme(L, 4); - if (n >= 4) - dire = (direntry *) LuaObject::getme(L, 5); - if (n >= 5) - mode = L->tonumber(6); - rdir = iso->createfile(dirt, h, name, dire, mode); - { - LuaDirTree t(rdir); - t.push(L); - } - r = 1; - break; - case ISOBUILDER_COPYDIR: - dirt = (DirTree *) LuaObject::getme(L, 2); - cd = (cdutils *) LuaObject::getme(L, 3); - dire = (direntry *) LuaObject::getme(L, 4); - if (n >= 4) - mode = L->tonumber(5); - iso->copydir(dirt, cd, dire, mode); - break; - case ISOBUILDER_CLOSE: - if (n >= 1) - h = (Handle *) LuaObject::getme(L, 2); - if (n >= 2) - mode = L->tonumber(3); - if (n >= 3) - nsects = L->tonumber(4); - iso->close(h, mode, nsects); - break; - } - - return r; -} - -int sLua_isobuilder::isobuilder_proceed_statics(Lua * L, int n, int caller) { - int r = 0, i; - Handle * h; - int mode = MODE2_FORM1; - cdutils * cd; - Byte datas[2048]; - PVD * pvd; - - switch (caller) { - case ISOBUILDER_NEWISOBUILDER: - h = (Handle *) LuaObject::getme(L, 1); - if (n >= 2) - mode = L->tonumber(); - { - Luaisobuilder t(new isobuilder(h, mode)); - t.pushdestruct(L); - } - r = 1; - break; - case ISOBUILDER_CREATEPVD_HANDLE: - h = (Handle *) LuaObject::getme(L, 1); - pvd = (PVD *) malloc(sizeof(PVD)); - *pvd = isobuilder::createpvd(h); - { - LuaPVD t(pvd); - t.pushdestruct(L); - } - r = 1; - break; - case ISOBUILDER_CREATEPVD: - cd = (cdutils *) LuaObject::getme(L, 1); - pvd = (PVD *) malloc(sizeof(PVD)); - *pvd = isobuilder::createpvd(cd); - { - LuaPVD t(pvd); - t.pushdestruct(L); - } - r = 1; - break; - case ISOBUILDER_CREATEPVD_ARRAY: - for (i = 0; i < 2048; i++) { - L->push((lua_Number) i); - L->gettable(1); - datas[i] = L->tonumber(); - L->pop(); - } - pvd = (PVD *) malloc(sizeof(PVD)); - *pvd = isobuilder::createpvd(datas); - { - LuaPVD t(pvd); - t.pushdestruct(L); - } - r = 1; - break; - } - - return r; -} +
+void Luaisobuilder::pushmembers(Lua * L) {
+ pushme(L, iso);
+
+ PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD);
+ PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD_HANDLE);
+ PUSH_METHOD(isobuilder, ISOBUILDER_FOREWORD_ARRAY);
+ PUSH_METHOD(isobuilder, ISOBUILDER_GETDISPSECT);
+ PUSH_METHOD(isobuilder, ISOBUILDER_PUTFILE);
+ PUSH_METHOD(isobuilder, ISOBUILDER_PUTDATAS);
+ PUSH_METHOD(isobuilder, ISOBUILDER_CREATESECTOR);
+ PUSH_METHOD(isobuilder, ISOBUILDER_SETEOF);
+ PUSH_METHOD(isobuilder, ISOBUILDER_CLEAREOF);
+ PUSH_METHOD(isobuilder, ISOBUILDER_SETBASICS);
+ PUSH_METHOD(isobuilder, ISOBUILDER_CREATEDIR);
+ PUSH_METHOD(isobuilder, ISOBUILDER_CREATEFILE);
+ PUSH_METHOD(isobuilder, ISOBUILDER_COPYDIR);
+ PUSH_METHOD(isobuilder, ISOBUILDER_CLOSE);
+}
+
+void Luaisobuilder::pushstatics(Lua * L) throw (GeneralException) {
+ CHECK_METHODS(isobuilder);
+ CHECK_FUNCTIONS(isobuilder);
+
+ PUSH_FUNCTION(isobuilder, ISOBUILDER_NEWISOBUILDER);
+ PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_HANDLE);
+ PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD);
+ PUSH_FUNCTION(isobuilder, ISOBUILDER_CREATEPVD_ARRAY);
+}
+
+int sLua_isobuilder::isobuilder_proceed(Lua * L, int n, isobuilder * iso, int caller) {
+ int r = 0, i;
+ Handle * h = 0;
+ int mode = -1, sector = -1, rootsize = 1, ptsize = 1, nvd = 1, rootsect = -1, nsects = -1;
+ size_t size;
+ Byte datas[2352 * 16], * p;
+ PVD * pvd;
+ DirTree * dirt, * rdir;
+ direntry * dire = 0;
+ String name;
+ cdutils * cd;
+
+ switch (caller) {
+ case ISOBUILDER_FOREWORD:
+ cd = (cdutils *) LuaObject::getme(L, 2);
+ iso->foreword(cd);
+ break;
+ case ISOBUILDER_FOREWORD_HANDLE:
+ mode = MODE_RAW;
+ h = (Handle *) LuaObject::getme(L, 2);
+ if (n == 2)
+ mode = L->tonumber(3);
+ iso->foreword(h, mode);
+ break;
+ case ISOBUILDER_FOREWORD_ARRAY:
+ mode = MODE_RAW;
+ if (n == 2)
+ mode = L->tonumber(3);
+ for (i = 0; i < 16 * 2352; i++) {
+ L->push((lua_Number) i);
+ L->gettable(2);
+ datas[i] = L->tonumber();
+ L->pop();
+ }
+ iso->foreword(datas, mode);
+ break;
+ case ISOBUILDER_GETDISPSECT:
+ L->push((lua_Number) iso->getdispsect());
+ r = 1;
+ break;
+ case ISOBUILDER_PUTFILE:
+ h = (Handle *) LuaObject::getme(L, 2);
+ if (n >= 2)
+ mode = L->tonumber(3);
+ if (n >= 3)
+ sector = L->tonumber(4);
+ L->push((lua_Number) iso->putfile(h, mode, sector));
+ r = 1;
+ break;
+ case ISOBUILDER_PUTDATAS:
+ size = L->tonumber(3);
+ if (n >= 3)
+ mode = L->tonumber(4);
+ if (n >= 4)
+ sector = L->tonumber(5);
+ p = (Byte *) malloc(size);
+ for (i = 0; i < size; i++) {
+ L->push((lua_Number) i);
+ L->gettable(2);
+ p[i] = L->tonumber();
+ L->pop();
+ }
+ L->push((lua_Number) iso->putdatas(p, size, mode, sector));
+ r = 1;
+ free(p);
+ break;
+ case ISOBUILDER_CREATESECTOR:
+ if (n >= 2)
+ mode = L->tonumber(3);
+ if (n >= 3)
+ sector = L->tonumber(4);
+ for (i = 0; i < 2352; i++) {
+ L->push((lua_Number) i);
+ L->gettable(2);
+ datas[i] = L->tonumber();
+ L->pop();
+ }
+ L->push((lua_Number) iso->createsector(datas, mode, sector));
+ r = 1;
+ break;
+ case ISOBUILDER_SETEOF:
+ iso->setEOF();
+ break;
+ case ISOBUILDER_CLEAREOF:
+ iso->clearEOF();
+ break;
+ case ISOBUILDER_SETBASICS:
+ pvd = (PVD *) LuaObject::getme(L, 2);
+ if (n >= 2)
+ rootsize = L->tonumber(3);
+ if (n >= 3)
+ ptsize = L->tonumber(4);
+ if (n >= 4)
+ nvd = L->tonumber(5);
+ if (n >= 5)
+ rootsect = L->tonumber(6);
+ rdir = iso->setbasics(*pvd, rootsize, ptsize, nvd, rootsect);
+ {
+ LuaDirTree t(rdir);
+ t.push(L);
+ }
+ r = 1;
+ break;
+ case ISOBUILDER_CREATEDIR:
+ size = 1;
+ dirt = 0;
+ dirt = (DirTree *) LuaObject::getme(L, 2);
+ name = L->tostring(3);
+ if (n >= 3)
+ size = L->tonumber(4);
+ if (n >= 4)
+ dire = (direntry *) LuaObject::getme(L, 5);
+ if (n >= 5)
+ mode = L->tonumber(6);
+ rdir = iso->createdir(dirt, name, size, dire, mode);
+ {
+ LuaDirTree t(rdir);
+ t.push(L);
+ }
+ r = 1;
+ break;
+ case ISOBUILDER_CREATEFILE:
+ dirt = (DirTree *) LuaObject::getme(L, 2);
+ name = L->tostring(3);
+ h = (Handle *) LuaObject::getme(L, 4);
+ if (n >= 4)
+ dire = (direntry *) LuaObject::getme(L, 5);
+ if (n >= 5)
+ mode = L->tonumber(6);
+ rdir = iso->createfile(dirt, h, name, dire, mode);
+ {
+ LuaDirTree t(rdir);
+ t.push(L);
+ }
+ r = 1;
+ break;
+ case ISOBUILDER_COPYDIR:
+ dirt = (DirTree *) LuaObject::getme(L, 2);
+ cd = (cdutils *) LuaObject::getme(L, 3);
+ dire = (direntry *) LuaObject::getme(L, 4);
+ if (n >= 4)
+ mode = L->tonumber(5);
+ iso->copydir(dirt, cd, dire, mode);
+ break;
+ case ISOBUILDER_CLOSE:
+ if (n >= 1)
+ h = (Handle *) LuaObject::getme(L, 2);
+ if (n >= 2)
+ mode = L->tonumber(3);
+ if (n >= 3)
+ nsects = L->tonumber(4);
+ iso->close(h, mode, nsects);
+ break;
+ }
+
+ return r;
+}
+
+int sLua_isobuilder::isobuilder_proceed_statics(Lua * L, int n, int caller) {
+ int r = 0, i;
+ Handle * h;
+ int mode = MODE2_FORM1;
+ cdutils * cd;
+ Byte datas[2048];
+ PVD * pvd;
+
+ switch (caller) {
+ case ISOBUILDER_NEWISOBUILDER:
+ h = (Handle *) LuaObject::getme(L, 1);
+ if (n >= 2)
+ mode = L->tonumber();
+ {
+ Luaisobuilder t(new isobuilder(h, mode));
+ t.pushdestruct(L);
+ }
+ r = 1;
+ break;
+ case ISOBUILDER_CREATEPVD_HANDLE:
+ h = (Handle *) LuaObject::getme(L, 1);
+ pvd = (PVD *) malloc(sizeof(PVD));
+ *pvd = isobuilder::createpvd(h);
+ {
+ LuaPVD t(pvd);
+ t.pushdestruct(L);
+ }
+ r = 1;
+ break;
+ case ISOBUILDER_CREATEPVD:
+ cd = (cdutils *) LuaObject::getme(L, 1);
+ pvd = (PVD *) malloc(sizeof(PVD));
+ *pvd = isobuilder::createpvd(cd);
+ {
+ LuaPVD t(pvd);
+ t.pushdestruct(L);
+ }
+ r = 1;
+ break;
+ case ISOBUILDER_CREATEPVD_ARRAY:
+ for (i = 0; i < 2048; i++) {
+ L->push((lua_Number) i);
+ L->gettable(1);
+ datas[i] = L->tonumber();
+ L->pop();
+ }
+ pvd = (PVD *) malloc(sizeof(PVD));
+ *pvd = isobuilder::createpvd(datas);
+ {
+ LuaPVD t(pvd);
+ t.pushdestruct(L);
+ }
+ r = 1;
+ break;
+ }
+
+ return r;
+}
|