mirror of
https://github.com/holub/mame
synced 2025-07-05 01:48:29 +03:00
added print_verbose, print_info, print_debug and print_error to lua, and used it instead of print (nw)
This commit is contained in:
parent
816860f2d8
commit
fc48cb17f3
@ -19,7 +19,7 @@ for file in lfs.dir("plugins") do
|
|||||||
if (meta["plugin"]["type"]=="plugin") and (manager:plugins().entries[meta["plugin"]["name"]]~=nil) then
|
if (meta["plugin"]["type"]=="plugin") and (manager:plugins().entries[meta["plugin"]["name"]]~=nil) then
|
||||||
local entry = manager:plugins().entries[meta["plugin"]["name"]]
|
local entry = manager:plugins().entries[meta["plugin"]["name"]]
|
||||||
if (entry:value()==true) then
|
if (entry:value()==true) then
|
||||||
print("Starting plugin " .. meta["plugin"]["name"] .. "...")
|
emu.print_verbose("Starting plugin " .. meta["plugin"]["name"] .. "...")
|
||||||
plugin = require(meta["plugin"]["name"])
|
plugin = require(meta["plugin"]["name"])
|
||||||
if plugin.set_folder~=nil then plugin.set_folder("plugins/" .. file) end
|
if plugin.set_folder~=nil then plugin.set_folder("plugins/" .. file) end
|
||||||
plugin.startplugin();
|
plugin.startplugin();
|
||||||
|
@ -112,7 +112,7 @@ function cheat.startplugin()
|
|||||||
line = line + 1
|
line = line + 1
|
||||||
end
|
end
|
||||||
if not screen then
|
if not screen then
|
||||||
print("draw_text: invalid screen")
|
emu.print_verbose("draw_text: invalid screen")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if type(x) == "string" then
|
if type(x) == "string" then
|
||||||
@ -123,7 +123,7 @@ function cheat.startplugin()
|
|||||||
|
|
||||||
local function draw_line(screen, x1, y1, x2, y2, color)
|
local function draw_line(screen, x1, y1, x2, y2, color)
|
||||||
if not screen then
|
if not screen then
|
||||||
print("draw_line: invalid screen")
|
emu.print_verbose("draw_line: invalid screen")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
output[#output + 1] = { type = "line", scr = screen, x1 = x1, x2 = x2, y1 = y1, y2 = y2, color = color }
|
output[#output + 1] = { type = "line", scr = screen, x1 = x1, x2 = x2, y1 = y1, y2 = y2, color = color }
|
||||||
@ -131,7 +131,7 @@ function cheat.startplugin()
|
|||||||
|
|
||||||
local function draw_box(screen, x1, y1, x2, y2, bgcolor, linecolor)
|
local function draw_box(screen, x1, y1, x2, y2, bgcolor, linecolor)
|
||||||
if not screen then
|
if not screen then
|
||||||
print("draw_box: invalid screen")
|
emu.print_verbose("draw_box: invalid screen")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
output[#output + 1] = { type = "box", scr = screen, x1 = x1, x2 = x2, y1 = y1, y2 = y2, bgcolor = bgcolor, linecolor = linecolor }
|
output[#output + 1] = { type = "box", scr = screen, x1 = x1, x2 = x2, y1 = y1, y2 = y2, bgcolor = bgcolor, linecolor = linecolor }
|
||||||
@ -184,7 +184,7 @@ function cheat.startplugin()
|
|||||||
for name, script in pairs(cheat.script) do
|
for name, script in pairs(cheat.script) do
|
||||||
script, err = load(script, cheat.desc .. name, "t", cheat.cheat_env)
|
script, err = load(script, cheat.desc .. name, "t", cheat.cheat_env)
|
||||||
if not script then
|
if not script then
|
||||||
print("error loading cheat script: " .. cheat.desc .. " " .. err)
|
emu.print_verbose("error loading cheat script: " .. cheat.desc .. " " .. err)
|
||||||
cheat = { desc = cheat.desc .. " error" }
|
cheat = { desc = cheat.desc .. " error" }
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -199,7 +199,7 @@ function cheat.startplugin()
|
|||||||
local cpu, mem
|
local cpu, mem
|
||||||
cpu = manager:machine().devices[space.tag]
|
cpu = manager:machine().devices[space.tag]
|
||||||
if not cpu then
|
if not cpu then
|
||||||
print("error loading cheat script: " .. cheat.desc)
|
emu.print_verbose("error loading cheat script: " .. cheat.desc)
|
||||||
cheat = { desc = cheat.desc .. " error" }
|
cheat = { desc = cheat.desc .. " error" }
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -209,7 +209,7 @@ function cheat.startplugin()
|
|||||||
mem = cpu.spaces["program"]
|
mem = cpu.spaces["program"]
|
||||||
end
|
end
|
||||||
if not mem then
|
if not mem then
|
||||||
print("error loading cheat script: " .. cheat.desc)
|
emu.print_verbose("error loading cheat script: " .. cheat.desc)
|
||||||
cheat = { desc = cheat.desc .. " error" }
|
cheat = { desc = cheat.desc .. " error" }
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -232,7 +232,7 @@ function cheat.startplugin()
|
|||||||
local mem
|
local mem
|
||||||
mem = manager:machine():memory().regions[region]
|
mem = manager:machine():memory().regions[region]
|
||||||
if not mem then
|
if not mem then
|
||||||
print("error loading cheat script: " .. cheat.desc)
|
emu.print_verbose("error loading cheat script: " .. cheat.desc)
|
||||||
cheat = { desc = cheat.desc .. " error" }
|
cheat = { desc = cheat.desc .. " error" }
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -244,7 +244,7 @@ function cheat.startplugin()
|
|||||||
local ram
|
local ram
|
||||||
ram = manager:machine().devices[ram]
|
ram = manager:machine().devices[ram]
|
||||||
if not ram then
|
if not ram then
|
||||||
print("error loading cheat script: " .. cheat.desc)
|
emu.print_verbose("error loading cheat script: " .. cheat.desc)
|
||||||
cheat = { desc = cheat.desc .. " error" }
|
cheat = { desc = cheat.desc .. " error" }
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -531,14 +531,14 @@ function cheat.startplugin()
|
|||||||
cheat = cheats[index]
|
cheat = cheats[index]
|
||||||
if cheat then
|
if cheat then
|
||||||
for k, v in pairs(cheat.cheat_env) do
|
for k, v in pairs(cheat.cheat_env) do
|
||||||
print(k, v)
|
emu.print_verbose(k, v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ce.list()
|
function ce.list()
|
||||||
for num, cheat in pairs(cheats) do
|
for num, cheat in pairs(cheats) do
|
||||||
print(num, cheat.desc)
|
emu.print_verbose(num, cheat.desc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -11,11 +11,11 @@ local dummy = exports
|
|||||||
|
|
||||||
function dummy.startplugin()
|
function dummy.startplugin()
|
||||||
emu.register_start(function()
|
emu.register_start(function()
|
||||||
print("Starting " .. emu.gamename())
|
emu.print_verbose("Starting " .. emu.gamename())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
emu.register_stop(function()
|
emu.register_stop(function()
|
||||||
print("Exiting " .. emu.gamename())
|
emu.print_verbose("Exiting " .. emu.gamename())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function menu_populate()
|
local function menu_populate()
|
||||||
@ -23,7 +23,7 @@ function dummy.startplugin()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function menu_callback(index, event)
|
local function menu_callback(index, event)
|
||||||
print("index: " .. index .. " event: " .. event)
|
emu.print_verbose("index: " .. index .. " event: " .. event)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -129,14 +129,14 @@ function hiscore.startplugin()
|
|||||||
|
|
||||||
|
|
||||||
local function write_scores ( posdata )
|
local function write_scores ( posdata )
|
||||||
print("write_scores")
|
emu.print_verbose("write_scores")
|
||||||
local output = io.open(get_file_name(), "wb");
|
local output = io.open(get_file_name(), "wb");
|
||||||
if not output then
|
if not output then
|
||||||
-- attempt to create the directory, and try again
|
-- attempt to create the directory, and try again
|
||||||
lfs.mkdir( hiscore_path );
|
lfs.mkdir( hiscore_path );
|
||||||
output = io.open(get_file_name(), "wb");
|
output = io.open(get_file_name(), "wb");
|
||||||
end
|
end
|
||||||
print("write_scores output")
|
emu.print_verbose("write_scores output")
|
||||||
if output then
|
if output then
|
||||||
for ri,row in ipairs(posdata) do
|
for ri,row in ipairs(posdata) do
|
||||||
t = {};
|
t = {};
|
||||||
@ -147,7 +147,7 @@ function hiscore.startplugin()
|
|||||||
end
|
end
|
||||||
output:close();
|
output:close();
|
||||||
end
|
end
|
||||||
print("write_scores end")
|
emu.print_verbose("write_scores end")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -184,10 +184,10 @@ function hiscore.startplugin()
|
|||||||
if check_mem( positions ) then
|
if check_mem( positions ) then
|
||||||
default_checksum = check_scores( positions );
|
default_checksum = check_scores( positions );
|
||||||
if read_scores( positions ) then
|
if read_scores( positions ) then
|
||||||
print( "scores read", "OK" );
|
emu.print_verbose( "scores read", "OK" );
|
||||||
else
|
else
|
||||||
-- likely there simply isn't a .hi file around yet
|
-- likely there simply isn't a .hi file around yet
|
||||||
print( "scores read", "FAIL" );
|
emu.print_verbose( "scores read", "FAIL" );
|
||||||
end
|
end
|
||||||
scores_have_been_read = true;
|
scores_have_been_read = true;
|
||||||
current_checksum = check_scores( positions );
|
current_checksum = check_scores( positions );
|
||||||
@ -219,7 +219,7 @@ function hiscore.startplugin()
|
|||||||
write_scores( positions );
|
write_scores( positions );
|
||||||
current_checksum = checksum;
|
current_checksum = checksum;
|
||||||
last_write_time = emu.time();
|
last_write_time = emu.time();
|
||||||
-- print( "SAVE SCORES EVENT!", last_write_time );
|
-- emu.print_verbose( "SAVE SCORES EVENT!", last_write_time );
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -243,13 +243,13 @@ function hiscore.startplugin()
|
|||||||
mem_check_passed = false
|
mem_check_passed = false
|
||||||
scores_have_been_read = false;
|
scores_have_been_read = false;
|
||||||
last_write_time = -10
|
last_write_time = -10
|
||||||
print("Starting " .. emu.gamename())
|
emu.print_verbose("Starting " .. emu.gamename())
|
||||||
local dat = read_hiscore_dat()
|
local dat = read_hiscore_dat()
|
||||||
if dat and dat ~= "" then
|
if dat and dat ~= "" then
|
||||||
print( "found hiscore.dat entry for " .. emu.romname() );
|
emu.print_verbose( "found hiscore.dat entry for " .. emu.romname() );
|
||||||
positions = parse_table( dat );
|
positions = parse_table( dat );
|
||||||
if not positions then
|
if not positions then
|
||||||
print("hiscore.dat parse error");
|
emu.print_error("hiscore.dat parse error");
|
||||||
return;
|
return;
|
||||||
end
|
end
|
||||||
found_hiscore_entry = true
|
found_hiscore_entry = true
|
||||||
|
@ -2075,6 +2075,49 @@ int lua_engine::lua_machine::l_logerror(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string lua_engine::get_print_buffer(lua_State *L)
|
||||||
|
{
|
||||||
|
int nargs = lua_gettop(L);
|
||||||
|
|
||||||
|
const std::string sep = " ";
|
||||||
|
|
||||||
|
std::ostringstream ss;
|
||||||
|
bool first = true;
|
||||||
|
|
||||||
|
for (int i = 1; i <= nargs; i++) {
|
||||||
|
const char* c = lua_tostring(L, i);
|
||||||
|
const std::string str = c ? c : "<nil>";
|
||||||
|
if (first) first = false;
|
||||||
|
else ss << sep;
|
||||||
|
ss << str;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
int lua_engine::l_osd_printf_verbose(lua_State *L)
|
||||||
|
{
|
||||||
|
osd_printf_verbose("%s\n",get_print_buffer(L).c_str());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lua_engine::l_osd_printf_error(lua_State *L)
|
||||||
|
{
|
||||||
|
osd_printf_error("%s\n",get_print_buffer(L).c_str());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lua_engine::l_osd_printf_info(lua_State *L)
|
||||||
|
{
|
||||||
|
osd_printf_info("%s\n",get_print_buffer(L).c_str());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lua_engine::l_osd_printf_debug(lua_State *L)
|
||||||
|
{
|
||||||
|
osd_printf_debug("%s\n",get_print_buffer(L).c_str());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
// initialize - initialize lua hookup to emu engine
|
// initialize - initialize lua hookup to emu engine
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
@ -2106,6 +2149,10 @@ void lua_engine::initialize()
|
|||||||
.addCFunction ("register_frame", l_emu_register_frame )
|
.addCFunction ("register_frame", l_emu_register_frame )
|
||||||
.addCFunction ("register_frame_done", l_emu_register_frame_done )
|
.addCFunction ("register_frame_done", l_emu_register_frame_done )
|
||||||
.addCFunction ("register_menu", l_emu_register_menu )
|
.addCFunction ("register_menu", l_emu_register_menu )
|
||||||
|
.addCFunction ("print_verbose", l_osd_printf_verbose )
|
||||||
|
.addCFunction ("print_error", l_osd_printf_error )
|
||||||
|
.addCFunction ("print_info", l_osd_printf_info )
|
||||||
|
.addCFunction ("print_debug", l_osd_printf_debug )
|
||||||
.beginClass <machine_manager> ("manager")
|
.beginClass <machine_manager> ("manager")
|
||||||
.addFunction ("machine", &machine_manager::machine)
|
.addFunction ("machine", &machine_manager::machine)
|
||||||
.addFunction ("options", &machine_manager::options)
|
.addFunction ("options", &machine_manager::options)
|
||||||
|
@ -141,6 +141,11 @@ private:
|
|||||||
static int l_emu_register_frame(lua_State *L);
|
static int l_emu_register_frame(lua_State *L);
|
||||||
static int l_emu_register_frame_done(lua_State *L);
|
static int l_emu_register_frame_done(lua_State *L);
|
||||||
static int l_emu_register_menu(lua_State *L);
|
static int l_emu_register_menu(lua_State *L);
|
||||||
|
static std::string get_print_buffer(lua_State *L);
|
||||||
|
static int l_osd_printf_verbose(lua_State *L);
|
||||||
|
static int l_osd_printf_error(lua_State *L);
|
||||||
|
static int l_osd_printf_info(lua_State *L);
|
||||||
|
static int l_osd_printf_debug(lua_State *L);
|
||||||
static int register_function(lua_State *L, const char *id);
|
static int register_function(lua_State *L, const char *id);
|
||||||
|
|
||||||
// "emu.machine" namespace
|
// "emu.machine" namespace
|
||||||
|
Loading…
Reference in New Issue
Block a user