diff options
author | pixel <pixel> | 2003-12-07 04:44:37 +0000 |
---|---|---|
committer | pixel <pixel> | 2003-12-07 04:44:37 +0000 |
commit | b3b4fd468cb4703ceed95ed78a567bb759cdb338 (patch) | |
tree | 7d6153d25bfbf37e3babc046d3b822e328e8637c | |
parent | 845451a49fe822f4ccbf221e9b56889d5386713d (diff) |
LUA work work work
-rw-r--r-- | MSVC/Tools/Tools.vcproj | 3 | ||||
-rw-r--r-- | cd-tool.cpp | 20 | ||||
-rw-r--r-- | includes/luacd.h | 21 | ||||
-rw-r--r-- | lib/luacd.cpp | 461 |
4 files changed, 336 insertions, 169 deletions
diff --git a/MSVC/Tools/Tools.vcproj b/MSVC/Tools/Tools.vcproj index a8c93ac..1ba289f 100644 --- a/MSVC/Tools/Tools.vcproj +++ b/MSVC/Tools/Tools.vcproj @@ -49,6 +49,9 @@ <File
RelativePath="..\..\lzss-main.cpp">
</File>
+ <File
+ RelativePath="..\..\testlua.lua">
+ </File>
</Filter>
<Filter
Name="Xenogears tools"
diff --git a/cd-tool.cpp b/cd-tool.cpp index bf3d879..fd123a2 100644 --- a/cd-tool.cpp +++ b/cd-tool.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: cd-tool.cpp,v 1.16 2003-12-06 04:26:16 pixel Exp $ */ +/* $Id: cd-tool.cpp,v 1.17 2003-12-07 04:44:38 pixel Exp $ */ #include <getopt.h> #include <stdio.h> @@ -38,6 +38,14 @@ #include "isobuilder.h" #include "luacd.h" +static int myprint(lua_State * L) { + const char * t = lua_tostring(L, -1); + + Base::printm(M_INFO, "From LUA: %s\n", t); + + return 0; +} + int lga = 0; struct option long_options[] = { {"help", 0, NULL, 'h'}, @@ -330,14 +338,22 @@ virtual int startup() throw (GeneralException) { } arg1 = argv[optind]; Lua * L = new Lua(); + L->open_math(); + L->open_string(); LuaInput::pushconstruct(L); LuaOutput::pushconstruct(L); LuaBuffer::pushconstruct(L); - L->push("cdutil"); + Luacdutils::pushstatics(L); + Luacdfile::pushstatics(L); + L->push("print"); + L->push(myprint); + L->settable(LUA_GLOBALSINDEX); Luacdutils lcdutil(cdutil); + L->push("cdutil"); lcdutil.push(L); L->settable(LUA_GLOBALSINDEX); L->load(&Input(arg1)); + getchar(); } else { showhelp(); printm(M_ERROR, "Command %s unknow.\n", argv[optind]); diff --git a/includes/luacd.h b/includes/luacd.h index a1c1e2a..f32eadd 100644 --- a/includes/luacd.h +++ b/includes/luacd.h @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: luacd.h,v 1.1 2003-12-06 04:26:17 pixel Exp $ */ +/* $Id: luacd.h,v 1.2 2003-12-07 04:44:38 pixel Exp $ */ #ifndef __LUACD_H__ #define __LUACD_H__ @@ -27,26 +27,27 @@ #include <LuaHandle.h>
#include <cdutils.h>
-class Luacdfile : public LuaHandle {
- public:
- static void pushconstruct(Lua *);
- Luacdfile(cdfile *);
- protected:
- virtual void pushmembers(Lua *);
-};
- class Luacdutils : public LuaObject { public: - static void pushconstruct(Lua *);
+ static void pushstatics(Lua *);
Luacdutils(cdutils *); protected:
virtual void pushmembers(Lua *);
cdutils * cd;
}; +class Luacdfile : public LuaHandle {
+ public:
+ static void pushstatics(Lua *) throw (GeneralException);
+ Luacdfile(cdfile *);
+ protected:
+ virtual void pushmembers(Lua *);
+};
+ class Luadirentry : public LuaObject { public: Luadirentry(cdutils::DirEntry *); + const cdutils::DirEntry * getdir(); protected: virtual void pushmembers(Lua *); cdutils::DirEntry * dir; diff --git a/lib/luacd.cpp b/lib/luacd.cpp index 9d8f6df..bda2c10 100644 --- a/lib/luacd.cpp +++ b/lib/luacd.cpp @@ -17,26 +17,20 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: luacd.cpp,v 1.1 2003-12-06 04:26:17 pixel Exp $ */ +/* $Id: luacd.cpp,v 1.2 2003-12-07 04:44:39 pixel Exp $ */ #include "luacd.h" -Luacdfile::Luacdfile(cdfile * h) : LuaHandle(h) { }
-Luacdutils::Luacdutils(cdutils * _cd) : cd(_cd) { }
-Luadirentry::Luadirentry(cdutils::DirEntry * _dir) : dir(_dir) { }
-enum {
- LUA_ANY = 0,
- LUA_OBJECT,
- LUA_TABLE,
- LUA_BOOLEAN,
- LUA_NUMBER,
- LUA_STRING,
- LUA_FUNCTION,
-};
+/****************************\
+|** class cdutils exports **|
+\****************************/
-enum {
- CDUTILS_GUESSTYPE = 0,
+Luacdutils::Luacdutils(cdutils * _cd) : cd(_cd) { }
+
+enum cdutils_methods_t {
+ CDUTILS_SETISOW = 0,
+ CDUTILS_GUESSTYPE,
CDUTILS_SECTORSEEK,
CDUTILS_READSECTOR,
CDUTILS_READDATAS,
@@ -51,139 +45,176 @@ enum { CDUTILS_FINDDIRENTRY,
};
-struct functypes_t {
- int number;
- char * name;
- int minargs, maxargs;
- int argtypes[32];
+enum cdutils_functions_t {
+ CDUTILS_NEWCDUTILS = 0,
+ CDUTILS_SWAPWORD,
+ CDUTILS_SWAPDWORD,
+ CDUTILS_FROM_BCD,
+ CDUTILS_TO_BCD,
+ CDUTILS_IS_VALID_BCD,
+ CDUTILS_FROM_MSF,
};
-struct functypes_t cdfunctions[] = {
- { CDUTILS_GUESSTYPE, "cdutils::guesstype", 0, 1, {LUA_NUMBER} },
- { CDUTILS_SECTORSEEK, "cdutils::sectorseek", 1, 1, {LUA_NUMBER} },
- { CDUTILS_READSECTOR, "cdutils::readsector", 0, 2, {LUA_NUMBER, LUA_NUMBER} },
- { CDUTILS_READDATAS, "cdutils::readdatas", 3, 3, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
- { CDUTILS_READFILE, "cdutils::readfile", 4, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
- { CDUTILS_WRITESECTOR, "cdutils::writesector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} },
- { CDUTILS_WRITEDATAS, "cdutils::writedatas", 4, 4, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
- { CDUTILS_WRITEFILE, "cdutils::writefile", 1, 3, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER} },
- { CDUTILS_GETISOINFOS, "cdutils::getisoinfos", 0, 0, 0 },
- { CDUTILS_GETPTINFOS, "cdutils::getptinfos", 0, 0, 0 },
- { CDUTILS_FINDPATH, "cdutils::findpath", 1, 1, {LUA_STRING} },
- { CDUTILS_FINDPARENT, "cdutils::findparent", 1, 1, {LUA_STRING} },
- { CDUTILS_FINDDIRENTRY, "cdutils::finddirentry", 2, 2, {LUA_OBJECT, LUA_STRING} },
+struct lua_functypes_t cdutils_methods[] = {
+ { CDUTILS_SETISOW, "set_iso_w", 1, 1, {LUA_OBJECT} },
+ { CDUTILS_GUESSTYPE, "guesstype", 0, 1, {LUA_NUMBER} },
+ { CDUTILS_SECTORSEEK, "sectorseek", 1, 1, {LUA_NUMBER} },
+ { CDUTILS_READSECTOR, "readsector", 0, 2, {LUA_NUMBER, LUA_NUMBER} },
+ { CDUTILS_READDATAS, "readdatas", 3, 3, {LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
+ { CDUTILS_READFILE, "readfile", 4, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
+ { CDUTILS_WRITESECTOR, "writesector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} },
+ { CDUTILS_WRITEDATAS, "writedatas", 4, 4, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} },
+ { CDUTILS_WRITEFILE, "writefile", 1, 3, {LUA_OBJECT, 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} },
+ { -1, 0, 0, 0, 0 }
};
-#define DECLARE_FUNC(enumvar) static int method_##enumvar(lua_State * L) { return multiplex(enumvar, L); }
-#define PUSH_FUNC(enumvar) pushit(L, cdfunctions[enumvar].name, sLuacd::method_##enumvar)
+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} },
+ { -1, 0, 0, 0, 0 }
+};
-class sLuacd : public Base {
+class sLua_cdutils : public Base {
public:
- static int newcdfile(lua_State * L);
- static int newcdutils(lua_State * L);
-
- DECLARE_FUNC(CDUTILS_GUESSTYPE);
- DECLARE_FUNC(CDUTILS_SECTORSEEK);
- DECLARE_FUNC(CDUTILS_READSECTOR);
- DECLARE_FUNC(CDUTILS_READDATAS);
- DECLARE_FUNC(CDUTILS_READFILE);
- DECLARE_FUNC(CDUTILS_WRITESECTOR);
- DECLARE_FUNC(CDUTILS_WRITEDATAS);
- DECLARE_FUNC(CDUTILS_WRITEFILE);
- DECLARE_FUNC(CDUTILS_GETISOINFOS);
- DECLARE_FUNC(CDUTILS_GETPTINFOS);
- DECLARE_FUNC(CDUTILS_FINDPATH);
- DECLARE_FUNC(CDUTILS_FINDPARENT);
- DECLARE_FUNC(CDUTILS_FINDDIRENTRY);
+ 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_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);
private:
- static int multiplex(int caller, lua_State * L);
- static int proceed(Lua * L, int n, void * obj, int caller);
+ static int cdutils_proceed(Lua * L, int n, cdutils * obj, int caller);
+ static int cdutils_proceed_statics(Lua * L, int n, int caller);
};
-void Luacdfile::pushconstruct(Lua * L) {
- L->declarefunc("cdfile", sLuacd::newcdfile);
-}
+void Luacdutils::pushmembers(Lua * L) {
+ pushme(L, cd);
-void Luacdutils::pushconstruct(Lua * L) {
- L->declarefunc("cdutils", sLuacd::newcdutils);
+ 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);
}
-int sLuacd::newcdfile(lua_State * _L) {
- /***TODO***/
- /* Creation of a 'cdfile' from within lua. */
+void Luacdutils::pushstatics(Lua * L) throw (GeneralException) {
+ CHECK_METHODS(cdutils);
+ CHECK_FUNCTIONS(cdutils);
- return 0;
-}
+ 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);
-int sLuacd::newcdutils(lua_State * _L) {
- /***TODO***/
- /* Creation of a 'cdutils' from within lua. */
+ L->push("MODE0");
+ L->push((lua_Number) MODE0);
+ L->setvar();
- return 0;
-}
+ 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 sLuacd::multiplex(int caller, lua_State * _L) {
- Lua * L = Lua::find(_L);
- int n = L->gettop() - 1;
- void * obj = LuaObject::getme(L);
int i;
- bool invalid = false;
-
- if ((n < cdfunctions[caller].minargs) || (n > cdfunctions[caller].maxargs)) {
- invalid = true;
- } else {
- for (i = 0; i < cdfunctions[caller].maxargs && !invalid; i++) {
- if (n >= (i + 1)) {
- switch(cdfunctions[caller].argtypes[i]) {
- case LUA_ANY:
- break;
- case LUA_OBJECT:
- invalid = !L->istable(i + 2);
- if (!invalid) {
- L->push("__obj");
- L->gettable(i + 2);
- invalid = L->islightuserdata();
- L->pop();
- }
- break;
- case LUA_TABLE:
- invalid = !L->istable(i + 2);
- break;
- case LUA_BOOLEAN:
- invalid = !L->isboolean(i + 2);
- break;
- case LUA_NUMBER:
- invalid = !L->isnumber(i + 2);
- break;
- case LUA_STRING:
- invalid = !L->isstring(i + 2);
- break;
- case LUA_FUNCTION:
- invalid = !L->isfunction(i + 2);
- break;
- }
- }
- }
- }
- if (invalid) {
- L->error(String("Invalid arguments to method `") + cdfunctions[caller].name + "'");
+ 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();
}
-
- return proceed(L, n, obj, caller);
+ 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 sLuacd::proceed(Lua * L, int n, void * obj, int caller) {
+int sLua_cdutils::cdutils_proceed(Lua * L, int n, cdutils * cd, int caller) {
int r = 0, sect = -1, mode = GUESS, size, i;
Handle * h;
Byte sdatas[2352], * datas;
String path;
-
- cdutils * cd = (cdutils *) obj;
- cdutils::DirEntry * dir = (cdutils::DirEntry *) obj, * bdir, * adir;
+ cdutils::DirEntry * dir, * bdir, * adir;
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();
@@ -316,56 +347,172 @@ int sLuacd::proceed(Lua * L, int n, void * obj, int caller) { return r;
}
+int sLua_cdutils::cdutils_proceed_statics(Lua * L, int n, int caller) {
+ int r = 0;
+ Uint32 x;
+
+ switch(caller) {
+ case CDUTILS_NEWCDUTILS:
+ /***TODO***/
+ 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:
+ /***TODO***/
+ break;
+ }
+
+ return r;
+}
+
+
+/***************************\
+|** class cdfile exports **|
+\***************************/
+
+Luacdfile::Luacdfile(cdfile * h) : LuaHandle(h) { }
+
+enum cdfile_functions_t {
+ CDFILE_NEWCDFILE = 0,
+};
+
+struct lua_functypes_t cdfile_functions[] = {
+ { CDFILE_NEWCDFILE, "cdfile", 1, 4, {LUA_OBJECT, LUA_ANY, LUA_NUMBER, LUA_NUMBER} },
+ { -1, 0, 0, 0, 0 }
+};
+
+class sLua_cdfile : public Base {
+ public:
+ DECLARE_FUNCTION(cdfile, CDFILE_NEWCDFILE);
+ private:
+ static int cdfile_proceed_statics(Lua * L, int n, int caller);
+};
+
void Luacdfile::pushmembers(Lua * L) {
LuaHandle::pushmembers(L);
}
-void Luacdutils::pushmembers(Lua * L) {
- pushme(L, cd);
+void Luacdfile::pushstatics(Lua * L) {
+ CHECK_FUNCTIONS(cdfile);
+ PUSH_FUNCTION(cdfile, CDFILE_NEWCDFILE);
+}
- PUSH_FUNC(CDUTILS_GUESSTYPE);
- PUSH_FUNC(CDUTILS_SECTORSEEK);
- PUSH_FUNC(CDUTILS_READSECTOR);
- PUSH_FUNC(CDUTILS_READDATAS);
- PUSH_FUNC(CDUTILS_READFILE);
- PUSH_FUNC(CDUTILS_WRITESECTOR);
- PUSH_FUNC(CDUTILS_WRITEDATAS);
- PUSH_FUNC(CDUTILS_WRITEFILE);
- PUSH_FUNC(CDUTILS_GETISOINFOS);
- PUSH_FUNC(CDUTILS_GETPTINFOS);
- PUSH_FUNC(CDUTILS_FINDPATH);
- PUSH_FUNC(CDUTILS_FINDPARENT);
- PUSH_FUNC(CDUTILS_FINDDIRENTRY);
+int sLua_cdfile::cdfile_proceed_statics(Lua * L, int n, int caller) {
+ int r = 0;
- L->push("MODE0");
- L->push((lua_Number) MODE0);
- L->settable(LUA_GLOBALSINDEX);
+ switch(caller) {
+ case CDFILE_NEWCDFILE:
+ /****TODO****/
+ break;
+ }
- L->push("MODE1");
- L->push((lua_Number) MODE1);
- L->settable(LUA_GLOBALSINDEX);
+ return r;
+}
- L->push("MODE2");
- L->push((lua_Number) MODE2);
- L->settable(LUA_GLOBALSINDEX);
- L->push("MODE2_FORM1");
- L->push((lua_Number) MODE2_FORM1);
- L->settable(LUA_GLOBALSINDEX);
- L->push("MODE2_FORM2");
- L->push((lua_Number) MODE2_FORM2);
- L->settable(LUA_GLOBALSINDEX);
+Luadirentry::Luadirentry(cdutils::DirEntry * _dir) : dir(_dir) { }
- L->push("MORE_RAW");
- L->push((lua_Number) MODE_RAW);
- L->settable(LUA_GLOBALSINDEX);
+typedef cdutils::DirEntry direntry;
- L->push("GUESS");
- L->push((lua_Number) GUESS);
- L->settable(LUA_GLOBALSINDEX);
-}
+enum direntry_methods_t {
+ DIRENTRY_INDEX = 0,
+};
+
+struct lua_functypes_t direntry_methods[] = {
+ { DIRENTRY_INDEX, "index", 2, 2, {LUA_OBJECT, LUA_STRING} },
+ { -1, 0, 0, 0, 0 }
+};
+
+class sLua_direntry : public Base {
+ public:
+ DECLARE_METHOD(direntry, DIRENTRY_INDEX);
+ private:
+ static int direntry_proceed(Lua * L, int n, direntry * obj, int caller);
+};
void Luadirentry::pushmembers(Lua * L) {
pushme(L, dir);
+
+ PUSH_METAMETHOD(direntry, DIRENTRY_INDEX);
+}
+
+int sLua_direntry::direntry_proceed(Lua * L, int n, direntry * dir, int caller) {
+ int r = 0;
+ String index;
+
+ switch (caller) {
+ 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;
+}
+
+const cdutils::DirEntry * Luadirentry::getdir() {
+ return dir;
}
|