Lua: Use multiarg in some more files

This commit is contained in:
Ilari Liusvaara 2014-01-28 03:24:33 +02:00
parent a848e9d154
commit d4a7b65df8
2 changed files with 51 additions and 31 deletions

View file

@ -37,15 +37,20 @@ namespace
});
lua::fnptr2 mfs(lua_func_misc, "movie.frame_subframes", [](lua::state& L, lua::parameters& P) -> int {
uint64_t frame = L.get_numeric_argument<uint64_t>(1, "movie.frame_subframes");
uint64_t frame;
P(frame);
auto& m = get_movie();
L.pushnumber(m.frame_subframes(frame));
return 1;
});
lua::fnptr2 mrs(lua_func_misc, "movie.read_subframes", [](lua::state& L, lua::parameters& P) -> int {
uint64_t frame = L.get_numeric_argument<uint64_t>(1, "movie.frame_subframes");
uint64_t subframe = L.get_numeric_argument<uint64_t>(2, "movie.frame_subframes");
uint64_t frame, subframe;
P(frame, subframe);
auto& m = get_movie();
controller_frame r = m.read_subframe(frame, subframe);
L.newtable();
@ -70,16 +75,21 @@ namespace
mainloop_signal_need_rewind(NULL);
} else if(P.is<lua_unsaferewind>()) {
//Load the save.
lua::objpin<lua_unsaferewind>* u = new lua::objpin<lua_unsaferewind>(
P.arg<lua::objpin<lua_unsaferewind>>());
mainloop_signal_need_rewind(u);
lua::objpin<lua_unsaferewind> pin;
P(pin);
mainloop_signal_need_rewind(new lua::objpin<lua_unsaferewind>(pin));
} else
P.expected("UNSAFEREWIND or nil");
return 0;
});
lua::fnptr2 movie_to_rewind(lua_func_misc, "movie.to_rewind", [](lua::state& L, lua::parameters& P) -> int {
auto filename = P.arg<std::string>();
std::string filename;
P(filename);
moviefile mfile(filename, *our_rom.rtype);
if(!mfile.is_savestate)
throw std::runtime_error("movie.to_rewind only allows savestates");

View file

@ -1,4 +1,5 @@
#include "library/zip.hpp"
#include "library/minmax.hpp"
#include "lua/internal.hpp"
namespace
@ -13,19 +14,20 @@ namespace
}
static int create(lua::state& L, lua::parameters& P)
{
auto filename = P.arg<std::string>();
auto compression = P.arg_opt<unsigned>(9);
if(compression < 0)
compression = 0;
if(compression > 9)
compression = 9;
std::string filename;
unsigned compression;
P(filename, P.optional(compression, 9));
compression = clip(compression, 0U, 9U);
lua::_class<lua_zip_writer>::create(L, filename, compression);
return 1;
}
int commit(lua::state& L, const std::string& fname)
{
if(!w)
throw std::runtime_error("Zip writer already finished");
if(!w) throw std::runtime_error("Zip writer already finished");
if(file_open)
w->close_file();
file_open = NULL;
@ -35,25 +37,28 @@ namespace
}
int rollback(lua::state& L, const std::string& fname)
{
if(!w)
throw std::runtime_error("Zip writer already finished");
if(!w) throw std::runtime_error("Zip writer already finished");
delete w;
w = NULL;
}
int close_file(lua::state& L, const std::string& fname)
{
if(!w)
throw std::runtime_error("Zip writer already finished");
if(!file_open)
throw std::runtime_error("Zip writer doesn't have file open");
if(!w) throw std::runtime_error("Zip writer already finished");
if(!file_open) throw std::runtime_error("Zip writer doesn't have file open");
w->close_file();
file_open = NULL;
}
int create_file(lua::state& L, const std::string& fname)
{
if(!w)
throw std::runtime_error("Zip writer already finished");
std::string filename = L.get_string(2, "ZIPWRITER::create_file");
lua::parameters P(L, fname);
std::string filename;
if(!w) throw std::runtime_error("Zip writer already finished");
P(P.skipped(), filename);
if(file_open) {
w->close_file();
file_open = NULL;
@ -62,11 +67,14 @@ namespace
}
int write(lua::state& L, const std::string& fname)
{
if(!w)
throw std::runtime_error("Zip writer already finished");
if(!file_open)
throw std::runtime_error("Zip writer doesn't have file open");
std::string _data = L.get_string(2, "ZIPWRITER::write");
lua::parameters P(L, fname);
std::string _data;
if(!w) throw std::runtime_error("Zip writer already finished");
if(!file_open) throw std::runtime_error("Zip writer doesn't have file open");
P(P.skipped(), _data);
std::vector<char> data(_data.length());
std::copy(_data.begin(), _data.end(), data.begin());
file_open->write(&data[0], data.size());
@ -99,8 +107,10 @@ namespace
}
lua::fnptr2 lua_enumerate_zip(lua_func_zip, "zip.enumerate", [](lua::state& L, lua::parameters& P) -> int {
auto filename = P.arg<std::string>();
auto invert = P.arg_opt<bool>(false);
std::string filename;
bool invert;
P(filename, P.optional(invert, false));
zip::reader r(filename);
L.newtable();