Lua: movie.get_rom_info()

This commit is contained in:
Ilari Liusvaara 2015-02-13 22:49:43 +02:00
parent 4e70e95e7f
commit 19b12b1215
3 changed files with 90 additions and 0 deletions

42
lua.lyx
View file

@ -6804,6 +6804,48 @@ Syntax: boolean movie.rom_loaded()
Returns true if ROM is loaded, false otherwise.
\end_layout
\begin_layout Subsection
movie.get_rom_info: Get info about loaded ROM
\end_layout
\begin_layout Itemize
Syntax: Table movie.get_rom_info()
\end_layout
\begin_layout Standard
Returns a table of tables.
The outer table is indexed by ROM slot index.
The inner table has the following fields:
\end_layout
\begin_layout Itemize
filename: The name of file
\end_layout
\begin_layout Itemize
hint: File name hint
\end_layout
\begin_layout Itemize
sha256: SHA-256 hash of ROM.
\end_layout
\begin_layout Itemize
xml_filename: The name of file for markup
\end_layout
\begin_layout Itemize
xml_hint: File name hint for markup
\end_layout
\begin_layout Itemize
xml_sha256: SHA-256 hash of ROM markup.
\end_layout
\begin_layout Standard
If there is no markup, the xml_* fields are absent.
\end_layout
\begin_layout Subsection
INPUTFRAME::get_button: Get button
\end_layout

BIN
lua.pdf

Binary file not shown.

View file

@ -141,6 +141,53 @@ namespace
return 1;
}
int get_rom_info(lua::state& L, lua::parameters& P)
{
auto& core = CORE();
auto& rom = *(core.rom);
bool any_loaded = false;
L.newtable();
for(unsigned i = 0; i < ROM_SLOT_COUNT; i++) {
auto img = &(rom.romimg[i]);
auto xml = &(rom.romxml[i]);
if(img->sha_256.read() == "") img = NULL; //Trivial image.
if(xml->sha_256.read() == "") xml = NULL; //Trivial image.
if(!img && !xml) continue;
any_loaded = true;
L.pushnumber(i+1);
L.newtable();
if(img) {
L.pushstring("filename");
L.pushlstring(img->filename);
L.rawset(-3);
L.pushstring("hint");
L.pushlstring(img->namehint);
L.rawset(-3);
L.pushstring("sha256");
L.pushlstring(img->sha_256.read());
L.rawset(-3);
}
if(xml) {
L.pushstring("xml_filename");
L.pushlstring(xml->filename);
L.rawset(-3);
L.pushstring("xml_hint");
L.pushlstring(xml->namehint);
L.rawset(-3);
L.pushstring("xml_sha256");
L.pushlstring(xml->sha_256.read());
L.rawset(-3);
}
L.rawset(-3);
}
if(!any_loaded) {
L.pop(1);
return 0;
}
return 1;
}
lua::functions LUA_movie_fns(lua_func_misc, "movie", {
{"currentframe", currentframe},
{"lagcount", lagcounter},
@ -154,5 +201,6 @@ namespace
{"unsafe_rewind", unsafe_rewind},
{"to_rewind", to_rewind},
{"rom_loaded", rom_loaded},
{"get_rom_info", get_rom_info},
});
}