add exists utility function
This commit is contained in:
parent
771650613c
commit
47eb173dac
2 changed files with 16 additions and 2 deletions
6
main.lua
6
main.lua
|
@ -96,6 +96,7 @@ local empty = util.empty
|
|||
local lerp = util.lerp
|
||||
local softchoice = util.softchoice
|
||||
local unperturbed_rank = util.unperturbed_rank
|
||||
local exists = util.exists
|
||||
|
||||
local game = require("smb")
|
||||
game.overlay = cfg.enable_overlay
|
||||
|
@ -446,8 +447,9 @@ local function init()
|
|||
loadlevel(cfg.starting_world, cfg.starting_level)
|
||||
end
|
||||
|
||||
local res, err = pcall(network.load, network, cfg.params_fn)
|
||||
if res == false then print(err) end
|
||||
if exists(cfg.params_fn) then
|
||||
network:load(cfg.params_fn)
|
||||
end
|
||||
|
||||
if cfg.es == 'xnes' then
|
||||
-- if you get an out of memory error, you can't use xNES. sorry!
|
||||
|
|
12
util.lua
12
util.lua
|
@ -5,6 +5,7 @@ local ipairs = ipairs
|
|||
local log = math.log
|
||||
local max = math.max
|
||||
local min = math.min
|
||||
local open = io.open
|
||||
local pairs = pairs
|
||||
local random = math.random
|
||||
local select = select
|
||||
|
@ -162,6 +163,16 @@ local function argsort(t, comp, out)
|
|||
return out
|
||||
end
|
||||
|
||||
local function exists(fn)
|
||||
local f = open(fn, "r")
|
||||
if f then
|
||||
f:close()
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
signbyte=signbyte,
|
||||
boolean_xor=boolean_xor,
|
||||
|
@ -183,4 +194,5 @@ return {
|
|||
rchoice2=rchoice2,
|
||||
rbool=rbool,
|
||||
argsort=argsort,
|
||||
exists=exists,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue