mirror of
https://github.com/holub/mame
synced 2025-06-10 06:47:18 +03:00
plugins: Replace environment variable substitution function with core version
This commit is contained in:
parent
6082c57817
commit
e70d4ebb34
@ -1,7 +1,7 @@
|
|||||||
local lib = {}
|
local lib = {}
|
||||||
|
|
||||||
local function get_settings_path()
|
local function get_settings_path()
|
||||||
return lfs.env_replace(manager:machine():options().entries.homepath:value():match('([^;]+)')) .. '/autofire/'
|
return emu.subst_env(manager:machine():options().entries.homepath:value():match('([^;]+)')) .. '/autofire/'
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_settings_filename()
|
local function get_settings_filename()
|
||||||
|
@ -2,29 +2,10 @@
|
|||||||
-- copyright-holders:Miodrag Milanovic
|
-- copyright-holders:Miodrag Milanovic
|
||||||
require('lfs')
|
require('lfs')
|
||||||
|
|
||||||
-- add helper to lfs for plugins to use
|
|
||||||
function lfs.env_replace(str)
|
|
||||||
local pathsep = package.config:sub(1,1)
|
|
||||||
local function dorep(val)
|
|
||||||
ret = os.getenv(val)
|
|
||||||
if ret then
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
return val
|
|
||||||
end
|
|
||||||
|
|
||||||
if pathsep == '\\' then
|
|
||||||
str = str:gsub("%%([%w_]+)%%", dorep)
|
|
||||||
else
|
|
||||||
str = str:gsub("%$([%w_]+)", dorep)
|
|
||||||
end
|
|
||||||
return str
|
|
||||||
end
|
|
||||||
|
|
||||||
_G._ = emu.lang_translate
|
_G._ = emu.lang_translate
|
||||||
_G.emu.plugin = {} -- table to contain plugin interfaces
|
_G.emu.plugin = {} -- table to contain plugin interfaces
|
||||||
-- substitute environment variables in the plugins path from options
|
-- substitute environment variables in the plugins path from options
|
||||||
local dirs = lfs.env_replace(manager:options().entries.pluginspath:value())
|
local dirs = emu.subst_env(manager:options().entries.pluginspath:value())
|
||||||
|
|
||||||
-- and split the paths apart and make them suitable for package.path
|
-- and split the paths apart and make them suitable for package.path
|
||||||
package.path = ""
|
package.path = ""
|
||||||
|
@ -134,7 +134,7 @@ function cheat.startplugin()
|
|||||||
|
|
||||||
local function load_hotkeys()
|
local function load_hotkeys()
|
||||||
local json = require("json")
|
local json = require("json")
|
||||||
local file = io.open(lfs.env_replace(manager:machine():options().entries.cheatpath:value():match("([^;]+)")) .. "/" .. cheatname .. "_hotkeys.json", "r")
|
local file = io.open(emu.subst_env(manager:machine():options().entries.cheatpath:value():match("([^;]+)")) .. "/" .. cheatname .. "_hotkeys.json", "r")
|
||||||
if not file then
|
if not file then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -160,7 +160,7 @@ function cheat.startplugin()
|
|||||||
end
|
end
|
||||||
if #hotkeys > 0 then
|
if #hotkeys > 0 then
|
||||||
local json = require("json")
|
local json = require("json")
|
||||||
local path = lfs.env_replace(manager:machine():options().entries.cheatpath:value():match("([^;]+)"))
|
local path = emu.subst_env(manager:machine():options().entries.cheatpath:value():match("([^;]+)"))
|
||||||
local attr = lfs.attributes(path)
|
local attr = lfs.attributes(path)
|
||||||
if not attr then
|
if not attr then
|
||||||
lfs.mkdir(path)
|
lfs.mkdir(path)
|
||||||
|
@ -959,8 +959,7 @@ function cheatfind.startplugin()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- lfs.env_replace is defined in boot.lua
|
cheat_save.path = emu.subst_env(manager:machine():options().entries.cheatpath:value()):match("([^;]+)")
|
||||||
cheat_save.path = lfs.env_replace(manager:machine():options().entries.cheatpath:value()):match("([^;]+)")
|
|
||||||
cheat_save.filename = string.format("%s/%s", cheat_save.path, setname)
|
cheat_save.filename = string.format("%s/%s", cheat_save.path, setname)
|
||||||
cheat_save.name = cheat.desc
|
cheat_save.name = cheat.desc
|
||||||
local json = require("json")
|
local json = require("json")
|
||||||
|
@ -9,7 +9,7 @@ local curset
|
|||||||
function env.open(file, size)
|
function env.open(file, size)
|
||||||
if file == ".hi" then
|
if file == ".hi" then
|
||||||
local path = "hi"
|
local path = "hi"
|
||||||
local ini = emu.file(lfs.env_replace(manager:options().entries.inipath:value()), 1)
|
local ini = emu.file(emu.subst_env(manager:options().entries.inipath:value()), 1)
|
||||||
local ret = ini:open("hiscore.ini")
|
local ret = ini:open("hiscore.ini")
|
||||||
if not ret then
|
if not ret then
|
||||||
local inifile = ini:read(ini:size())
|
local inifile = ini:read(ini:size())
|
||||||
@ -23,7 +23,7 @@ function env.open(file, size)
|
|||||||
end
|
end
|
||||||
file = path .. "/" .. curset .. ".hi"
|
file = path .. "/" .. curset .. ".hi"
|
||||||
else
|
else
|
||||||
file = lfs.env_replace(manager:options().entries.nvram_directory:value()) .. "/" .. curset .. "/" .. file
|
file = emu.subst_env(manager:options().entries.nvram_directory:value()) .. "/" .. curset .. "/" .. file
|
||||||
end
|
end
|
||||||
local f = io.open(file, "rb")
|
local f = io.open(file, "rb")
|
||||||
local content = f:read("*all")
|
local content = f:read("*all")
|
||||||
@ -789,12 +789,12 @@ function dat.check(set, softlist)
|
|||||||
output = nil
|
output = nil
|
||||||
curset = set
|
curset = set
|
||||||
|
|
||||||
local scrfile = emu.file(lfs.env_replace(mame_manager:ui():options().entries.historypath:value():gsub("([^;]+)", "%1/hi2txt")), 1)
|
local scrfile = emu.file(emu.subst_env(mame_manager:ui():options().entries.historypath:value():gsub("([^;]+)", "%1/hi2txt")), 1)
|
||||||
local ret = scrfile:open(set .. ".lua")
|
local ret = scrfile:open(set .. ".lua")
|
||||||
local script
|
local script
|
||||||
if ret then
|
if ret then
|
||||||
function get_xml_table(fileset)
|
function get_xml_table(fileset)
|
||||||
local file = emu.file(lfs.env_replace(mame_manager:ui():options().entries.historypath:value():gsub("([^;]+)", "%1/hi2txt")), 1)
|
local file = emu.file(emu.subst_env(mame_manager:ui():options().entries.historypath:value():gsub("([^;]+)", "%1/hi2txt")), 1)
|
||||||
local ret = file:open(fileset .. ".xml")
|
local ret = file:open(fileset .. ".xml")
|
||||||
if ret then
|
if ret then
|
||||||
return nil
|
return nil
|
||||||
|
@ -10,7 +10,7 @@ local function init()
|
|||||||
local file = "scores3.htm"
|
local file = "scores3.htm"
|
||||||
|
|
||||||
for path in mame_manager:ui():options().entries.historypath:value():gmatch("([^;]+)") do
|
for path in mame_manager:ui():options().entries.historypath:value():gmatch("([^;]+)") do
|
||||||
filepath = lfs.env_replace(path) .. "/" .. file
|
filepath = emu.subst_env(path) .. "/" .. file
|
||||||
fh = io.open(filepath, "r")
|
fh = io.open(filepath, "r")
|
||||||
if fh then
|
if fh then
|
||||||
break
|
break
|
||||||
|
@ -9,7 +9,7 @@ local function check_db(msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
local dbpath = lfs.env_replace(mame_manager:ui():options().entries.historypath:value():match("([^;]+)"))
|
local dbpath = emu.subst_env(mame_manager:ui():options().entries.historypath:value():match("([^;]+)"))
|
||||||
db = sql.open(dbpath .. "/history.db")
|
db = sql.open(dbpath .. "/history.db")
|
||||||
if not db then
|
if not db then
|
||||||
lfs.mkdir(dbpath)
|
lfs.mkdir(dbpath)
|
||||||
|
@ -27,7 +27,7 @@ function datfile.open(file, vertag, fixupcb)
|
|||||||
local fh
|
local fh
|
||||||
|
|
||||||
for path in mame_manager:ui():options().entries.historypath:value():gmatch("([^;]+)") do
|
for path in mame_manager:ui():options().entries.historypath:value():gmatch("([^;]+)") do
|
||||||
filepath = lfs.env_replace(path) .. "/" .. file
|
filepath = emu.subst_env(path) .. "/" .. file
|
||||||
fh = io.open(filepath, "r")
|
fh = io.open(filepath, "r")
|
||||||
if fh then
|
if fh then
|
||||||
break
|
break
|
||||||
|
@ -23,7 +23,7 @@ function hiscore.startplugin()
|
|||||||
|
|
||||||
local hiscoredata_path = "hiscore.dat";
|
local hiscoredata_path = "hiscore.dat";
|
||||||
local hiscore_path = "hi";
|
local hiscore_path = "hi";
|
||||||
local config_path = lfs.env_replace(manager:options().entries.inipath:value():match("[^;]+") .. "/hiscore.ini");
|
local config_path = emu.subst_env(manager:options().entries.inipath:value():match("[^;]+") .. "/hiscore.ini");
|
||||||
|
|
||||||
local current_checksum = 0;
|
local current_checksum = 0;
|
||||||
local default_checksum = 0;
|
local default_checksum = 0;
|
||||||
@ -51,7 +51,7 @@ function hiscore.startplugin()
|
|||||||
_conf[token] = value;
|
_conf[token] = value;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
hiscore_path = lfs.env_replace(_conf["hi_path"] or hiscore_path);
|
hiscore_path = emu.subst_env(_conf["hi_path"] or hiscore_path);
|
||||||
timed_save = _conf["only_save_at_exit"] ~= "1"
|
timed_save = _conf["only_save_at_exit"] ~= "1"
|
||||||
-- hiscoredata_path = _conf["dat_path"]; -- don't know if I should do it, but wathever
|
-- hiscoredata_path = _conf["dat_path"]; -- don't know if I should do it, but wathever
|
||||||
return true
|
return true
|
||||||
|
@ -28,7 +28,7 @@ local portname = exports
|
|||||||
|
|
||||||
function portname.startplugin()
|
function portname.startplugin()
|
||||||
local json = require("json")
|
local json = require("json")
|
||||||
local ctrlrpath = lfs.env_replace(manager:options().entries.ctrlrpath:value():match("([^;]+)"))
|
local ctrlrpath = lfs.subst_env(manager:options().entries.ctrlrpath:value():match("([^;]+)"))
|
||||||
local function get_filename(nosoft)
|
local function get_filename(nosoft)
|
||||||
local filename
|
local filename
|
||||||
if emu.softname() ~= "" and not nosoft then
|
if emu.softname() ~= "" and not nosoft then
|
||||||
|
@ -12,7 +12,7 @@ exports.author = { name = "Carl" }
|
|||||||
local timer = exports
|
local timer = exports
|
||||||
|
|
||||||
function timer.startplugin()
|
function timer.startplugin()
|
||||||
local dir = lfs.env_replace(manager:options().entries.homepath:value())
|
local dir = emu.subst_env(manager:options().entries.homepath:value())
|
||||||
local timer_db = dir .. "/timer/timer.db"
|
local timer_db = dir .. "/timer/timer.db"
|
||||||
local timer_started = false
|
local timer_started = false
|
||||||
local total_time = 0
|
local total_time = 0
|
||||||
|
@ -555,7 +555,7 @@ void lua_engine::initialize()
|
|||||||
* emu.keypost(keys) - post keys to natural keyboard
|
* emu.keypost(keys) - post keys to natural keyboard
|
||||||
* emu.wait(len) - wait for len within coroutine
|
* emu.wait(len) - wait for len within coroutine
|
||||||
* emu.lang_translate(str) - get translation for str if available
|
* emu.lang_translate(str) - get translation for str if available
|
||||||
* emu.subst_env(str) - substitute environment variables with values for str
|
* emu.subst_env(str) - substitute environment variables with values for str (semantics are OS-specific)
|
||||||
*
|
*
|
||||||
* emu.register_prestart(callback) - register callback before reset
|
* emu.register_prestart(callback) - register callback before reset
|
||||||
* emu.register_start(callback) - register callback after reset
|
* emu.register_start(callback) - register callback after reset
|
||||||
|
Loading…
Reference in New Issue
Block a user