mirror of
https://github.com/holub/mame
synced 2025-04-20 15:32:45 +03:00
luaengine: add basic table return support (nw)
This commit is contained in:
parent
0aa29030da
commit
06363cf65a
@ -35,7 +35,7 @@ function data.startplugin()
|
||||
end
|
||||
end)
|
||||
emu.register_callback(function(set)
|
||||
local ret
|
||||
local ret = {}
|
||||
if set == "" then
|
||||
set = emu.romname()
|
||||
end
|
||||
@ -54,11 +54,7 @@ function data.startplugin()
|
||||
end
|
||||
local name = scr.check(setname, softname)
|
||||
if name then
|
||||
if not ret then
|
||||
ret = name
|
||||
else
|
||||
ret = ret .. "," .. name
|
||||
end
|
||||
ret[#ret + 1] = name
|
||||
valid_lst[#valid_lst + 1] = scr
|
||||
end
|
||||
end
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
void on_frame_done();
|
||||
|
||||
template<typename T, typename U>
|
||||
bool call_plugin(const std::string &name, T in, U& out)
|
||||
bool call_plugin(const std::string &name, const T in, U &out)
|
||||
{
|
||||
bool ret = false;
|
||||
sol::object outobj = call_plugin(name, sol::make_object(sol(), in));
|
||||
@ -71,17 +71,43 @@ public:
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
bool call_plugin_check(const std::string &name, U in)
|
||||
bool call_plugin(const std::string &name, const T in, std::vector<U> &out)
|
||||
{
|
||||
bool ret = false;
|
||||
sol::object outobj = call_plugin(name, sol::make_object(sol(), in));
|
||||
if(outobj.is<sol::table>())
|
||||
{
|
||||
for(auto &entry : outobj.as<sol::table>())
|
||||
{
|
||||
if(entry.second.template is<U>())
|
||||
{
|
||||
out.push_back(entry.second.template as<U>());
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// this will also check if a returned table contains type T
|
||||
template<typename T, typename U>
|
||||
bool call_plugin_check(const std::string &name, const U in)
|
||||
{
|
||||
bool ret = false;
|
||||
sol::object outobj = call_plugin(name, sol::make_object(sol(), in));
|
||||
if(outobj.is<T>())
|
||||
ret = true;
|
||||
else if(outobj.is<sol::table>())
|
||||
{
|
||||
// check just one entry, checking the whole thing shouldn't be necessary as this only supports homogeneous tables
|
||||
if(outobj.as<sol::table>().begin().operator*().second.template is<T>())
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void call_plugin_set(const std::string &name, T in)
|
||||
void call_plugin_set(const std::string &name, const T in)
|
||||
{
|
||||
call_plugin(name, sol::make_object(sol(), in));
|
||||
}
|
||||
|
@ -45,19 +45,16 @@ menu_dats_view::menu_dats_view(mame_ui_manager &mui, render_container &container
|
||||
m_parent = image.software_entry()->parentname();
|
||||
}
|
||||
}
|
||||
std::string lua_list;
|
||||
std::vector<std::string> lua_list;
|
||||
if(mame_machine_manager::instance()->lua()->call_plugin("data_list", driver ? driver->name : "", lua_list))
|
||||
{
|
||||
std::string list(lua_list);
|
||||
char *token = strtok((char *)list.c_str(), ",");
|
||||
int count = 0;
|
||||
while(token)
|
||||
for(std::string &item : lua_list)
|
||||
{
|
||||
std::string item;
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data_version", util::string_format("%d", count).c_str(), item);
|
||||
m_items_list.emplace_back(_(token), count, item);
|
||||
std::string version;
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data_version", count, version);
|
||||
m_items_list.emplace_back(_(item.c_str()), count, std::move(version));
|
||||
count++;
|
||||
token = strtok(nullptr, ",");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -80,19 +77,16 @@ menu_dats_view::menu_dats_view(mame_ui_manager &mui, render_container &container
|
||||
{
|
||||
if (swinfo != nullptr && !swinfo->usage.empty())
|
||||
m_items_list.emplace_back(_("Software Usage"), 0, "");
|
||||
std::string lua_list;
|
||||
std::vector<std::string> lua_list;
|
||||
if(mame_machine_manager::instance()->lua()->call_plugin("data_list", std::string(m_short).append(1, ',').append(m_list).c_str(), lua_list))
|
||||
{
|
||||
std::string list(lua_list);
|
||||
char *token = strtok((char *)list.c_str(), ",");
|
||||
int count = 1;
|
||||
while(token)
|
||||
for(std::string &item : lua_list)
|
||||
{
|
||||
std::string item;
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data_version", util::string_format("%d", count - 1).c_str(), item);
|
||||
m_items_list.emplace_back(_(token), count, item);
|
||||
std::string version;
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data_version", count - 1, version);
|
||||
m_items_list.emplace_back(_(item.c_str()), count, std::move(version));
|
||||
count++;
|
||||
token = strtok(nullptr, ",");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -395,7 +389,7 @@ void menu_dats_view::get_data()
|
||||
{
|
||||
std::vector<int> xstart, xend;
|
||||
std::string buffer;
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data", util::string_format("%d", m_items_list[m_actual].option).c_str(), buffer);
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data", m_items_list[m_actual].option, buffer);
|
||||
|
||||
|
||||
auto lines = ui().wrap_text(container(), buffer.c_str(), 0.0f, 0.0f, 1.0f - (4.0f * UI_BOX_LR_BORDER), xstart, xend);
|
||||
@ -414,7 +408,7 @@ void menu_dats_view::get_data_sw()
|
||||
if (m_items_list[m_actual].option == 0)
|
||||
buffer = m_swinfo->usage;
|
||||
else
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data", util::string_format("data", "%d", m_items_list[m_actual].option - 1).c_str(), buffer);
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data", m_items_list[m_actual].option - 1, buffer);
|
||||
|
||||
auto lines = ui().wrap_text(container(), buffer.c_str(), 0.0f, 0.0f, 1.0f - (4.0f * UI_BOX_LR_BORDER), xstart, xend);
|
||||
for (int x = 0; x < lines; ++x)
|
||||
|
@ -1911,21 +1911,10 @@ void menu_select_launch::infos_render(float origx1, float origy1, float origx2,
|
||||
m_info_view = 0;
|
||||
m_info_software = software;
|
||||
ui_globals::cur_sw_dats_view = 0;
|
||||
ui_globals::cur_sw_dats_total = 1;
|
||||
|
||||
std::string lua_list;
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data_list", std::string(software->shortname).append(1, ',').append(software->listname).c_str(), lua_list);
|
||||
m_items_list.clear();
|
||||
if(lua_list.length())
|
||||
{
|
||||
char *token = strtok((char *)lua_list.c_str(), ",");
|
||||
while(token)
|
||||
{
|
||||
ui_globals::cur_sw_dats_total++;
|
||||
m_items_list.emplace_back(token);
|
||||
token = strtok(nullptr, ",");
|
||||
}
|
||||
}
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data_list", std::string(software->shortname).append(1, ',').append(software->listname).c_str(), m_items_list);
|
||||
ui_globals::cur_sw_dats_total = m_items_list.size() + 1;
|
||||
}
|
||||
|
||||
if (m_info_view == 0)
|
||||
@ -1933,7 +1922,7 @@ void menu_select_launch::infos_render(float origx1, float origy1, float origx2,
|
||||
else
|
||||
{
|
||||
m_info_buffer = "";
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data", util::string_format("%d", m_info_view - 1).c_str(), m_info_buffer);
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data", m_info_view - 1, m_info_buffer);
|
||||
}
|
||||
}
|
||||
total = ui_globals::cur_sw_dats_total;
|
||||
@ -1955,21 +1944,10 @@ void menu_select_launch::infos_render(float origx1, float origy1, float origx2,
|
||||
m_info_driver = driver;
|
||||
m_info_view = 0;
|
||||
ui_globals::curdats_view = 0;
|
||||
ui_globals::curdats_total = 1;
|
||||
|
||||
std::string lua_list;
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data_list", driver->name, lua_list);
|
||||
m_items_list.clear();
|
||||
if(lua_list.length())
|
||||
{
|
||||
char *token = strtok((char *)lua_list.c_str(), ",");
|
||||
while(token)
|
||||
{
|
||||
ui_globals::curdats_total++;
|
||||
m_items_list.emplace_back(token);
|
||||
token = strtok(nullptr, ",");
|
||||
}
|
||||
}
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data_list", driver->name, m_items_list);
|
||||
ui_globals::curdats_total = m_items_list.size() + 1;
|
||||
}
|
||||
|
||||
if (m_info_view == 0)
|
||||
@ -1977,7 +1955,7 @@ void menu_select_launch::infos_render(float origx1, float origy1, float origx2,
|
||||
else
|
||||
{
|
||||
m_info_buffer = "";
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data", util::string_format("%d", m_info_view - 1).c_str(), m_info_buffer);
|
||||
mame_machine_manager::instance()->lua()->call_plugin("data", m_info_view - 1, m_info_buffer);
|
||||
}
|
||||
}
|
||||
total = ui_globals::curdats_total;
|
||||
|
Loading…
Reference in New Issue
Block a user