diff options
author | 2020-12-08 09:44:32 -0500 | |
---|---|---|
committer | 2020-12-08 09:44:32 -0500 | |
commit | e70d4ebb34be2bfbd9e93cf862d8d4d68ddf37cb (patch) | |
tree | a83af7d1cc8e19b49f1a82ede6dc346a548cef1f | |
parent | 6082c57817462f56ca4bfdfd1908c4498677c4b9 (diff) |
plugins: Replace environment variable substitution function with core version
-rw-r--r-- | plugins/autofire/autofire_save.lua | 2 | ||||
-rw-r--r-- | plugins/boot.lua | 21 | ||||
-rw-r--r-- | plugins/cheat/init.lua | 4 | ||||
-rw-r--r-- | plugins/cheatfind/init.lua | 3 | ||||
-rw-r--r-- | plugins/data/data_hiscore.lua | 8 | ||||
-rw-r--r-- | plugins/data/data_marp.lua | 2 | ||||
-rw-r--r-- | plugins/data/database.lua | 2 | ||||
-rw-r--r-- | plugins/data/load_dat.lua | 2 | ||||
-rw-r--r-- | plugins/hiscore/init.lua | 4 | ||||
-rw-r--r-- | plugins/portname/init.lua | 2 | ||||
-rw-r--r-- | plugins/timer/init.lua | 2 | ||||
-rw-r--r-- | src/frontend/mame/luaengine.cpp | 2 |
12 files changed, 17 insertions, 37 deletions
diff --git a/plugins/autofire/autofire_save.lua b/plugins/autofire/autofire_save.lua index 543b36ec7c8..07c4032b434 100644 --- a/plugins/autofire/autofire_save.lua +++ b/plugins/autofire/autofire_save.lua @@ -1,7 +1,7 @@ local lib = {} 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 local function get_settings_filename() diff --git a/plugins/boot.lua b/plugins/boot.lua index 09be30ee401..3a4de6fcc7c 100644 --- a/plugins/boot.lua +++ b/plugins/boot.lua @@ -2,29 +2,10 @@ -- copyright-holders:Miodrag Milanovic 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.plugin = {} -- table to contain plugin interfaces -- 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 package.path = "" diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua index 970e7f3a848..082864bb2fb 100644 --- a/plugins/cheat/init.lua +++ b/plugins/cheat/init.lua @@ -134,7 +134,7 @@ function cheat.startplugin() local function load_hotkeys() 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 return end @@ -160,7 +160,7 @@ function cheat.startplugin() end if #hotkeys > 0 then 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) if not attr then lfs.mkdir(path) diff --git a/plugins/cheatfind/init.lua b/plugins/cheatfind/init.lua index e6a359f6564..e540fe59fe6 100644 --- a/plugins/cheatfind/init.lua +++ b/plugins/cheatfind/init.lua @@ -959,8 +959,7 @@ function cheatfind.startplugin() end end end - -- lfs.env_replace is defined in boot.lua - cheat_save.path = lfs.env_replace(manager:machine():options().entries.cheatpath:value()):match("([^;]+)") + cheat_save.path = emu.subst_env(manager:machine():options().entries.cheatpath:value()):match("([^;]+)") cheat_save.filename = string.format("%s/%s", cheat_save.path, setname) cheat_save.name = cheat.desc local json = require("json") diff --git a/plugins/data/data_hiscore.lua b/plugins/data/data_hiscore.lua index 515b87a2302..867041a14cc 100644 --- a/plugins/data/data_hiscore.lua +++ b/plugins/data/data_hiscore.lua @@ -9,7 +9,7 @@ local curset function env.open(file, size) if file == ".hi" then 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") if not ret then local inifile = ini:read(ini:size()) @@ -23,7 +23,7 @@ function env.open(file, size) end file = path .. "/" .. curset .. ".hi" 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 local f = io.open(file, "rb") local content = f:read("*all") @@ -789,12 +789,12 @@ function dat.check(set, softlist) output = nil 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 script if ret then 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") if ret then return nil diff --git a/plugins/data/data_marp.lua b/plugins/data/data_marp.lua index 40db2daf366..5cb0bc3fb19 100644 --- a/plugins/data/data_marp.lua +++ b/plugins/data/data_marp.lua @@ -10,7 +10,7 @@ local function init() local file = "scores3.htm" 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") if fh then break diff --git a/plugins/data/database.lua b/plugins/data/database.lua index 6eda6ab1507..da1a2508cad 100644 --- a/plugins/data/database.lua +++ b/plugins/data/database.lua @@ -9,7 +9,7 @@ local function check_db(msg) end 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") if not db then lfs.mkdir(dbpath) diff --git a/plugins/data/load_dat.lua b/plugins/data/load_dat.lua index 024dbac0ad3..a21ae51aebe 100644 --- a/plugins/data/load_dat.lua +++ b/plugins/data/load_dat.lua @@ -27,7 +27,7 @@ function datfile.open(file, vertag, fixupcb) local fh 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") if fh then break diff --git a/plugins/hiscore/init.lua b/plugins/hiscore/init.lua index 9bd6ba2276c..e4da7cda4d6 100644 --- a/plugins/hiscore/init.lua +++ b/plugins/hiscore/init.lua @@ -23,7 +23,7 @@ function hiscore.startplugin() local hiscoredata_path = "hiscore.dat"; 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 default_checksum = 0; @@ -51,7 +51,7 @@ function hiscore.startplugin() _conf[token] = value; 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" -- hiscoredata_path = _conf["dat_path"]; -- don't know if I should do it, but wathever return true diff --git a/plugins/portname/init.lua b/plugins/portname/init.lua index 3c04d26f72a..538c3c6475d 100644 --- a/plugins/portname/init.lua +++ b/plugins/portname/init.lua @@ -28,7 +28,7 @@ local portname = exports function portname.startplugin() 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 filename if emu.softname() ~= "" and not nosoft then diff --git a/plugins/timer/init.lua b/plugins/timer/init.lua index 56ccd6b39ed..95601ac67f3 100644 --- a/plugins/timer/init.lua +++ b/plugins/timer/init.lua @@ -12,7 +12,7 @@ exports.author = { name = "Carl" } local timer = exports 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_started = false local total_time = 0 diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp index f069497bf6d..da7a6e9ea41 100644 --- a/src/frontend/mame/luaengine.cpp +++ b/src/frontend/mame/luaengine.cpp @@ -555,7 +555,7 @@ void lua_engine::initialize() * emu.keypost(keys) - post keys to natural keyboard * emu.wait(len) - wait for len within coroutine * 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_start(callback) - register callback after reset |