Post subject: lsnes: Input movies and save states within Lua
Joined: 4/16/2013
Posts: 8
The save state support in lsnes for Lua is a strange beast. The movie.* section has
Language: lua

movie.unsafe_rewind( movie.to_rewind(filename) )
to be able to load a save state, but nothing to save a save state. It has INPUTMOVIE to read/write/edit input movies, but you can't actually load them into the active state, as they are just input files. The UNSAFEREWIND class's only function appears to be sending it to unsafe_rewind. Funny, there's actually a ZIPWRITER class, but I don't think Lua has enough access to all of the save state files to roll your own state writer. Yes, I know about the
Language: lua

exec("save-state " .. filename)
command, which is what I'm using now, but that seems like an API of last resort. Are there plans to fill in these gaps? Am I missing some new functions or something obvious?
Editor, Skilled player (1537)
Joined: 7/9/2010
Posts: 1319
Use
exec("save-state movieslot<slot>.lsmv")
to save states and
exec("load-state movieslot<slot>.lsmv")
to load states.
Favorite animal: STOCK Gt(ROSA)26Sortm1.1(rtTA,EGFP)Nagy Grm7Tg(SMN2)89Ahmb Smn1tm1Msd Tg(SMN2*delta7)4299Ahmb Tg(tetO-SMN2,-luc)#aAhmb/J YouTube Twitch
Amaraticando
It/Its
Editor, Player (162)
Joined: 1/10/2012
Posts: 673
Location: Brazil
Beware that the whole unsafe rewind thing is to load states faster, without some sanity checks. Using this unproperly could result in a desync. Lua has no access to all the save states files because they can be saved on arbitrary places. The default place to save states is set under Config > Settings > Advanced > Path Save Slots. The prefix of movies and saves can be chosen while creating a new movie. Loading inputmovie object from lsmv file without loading the state: cannot yet. Hacky way that Ilari told me at #lsnes IRC: http://codepad.org/i4awK16k Saving non-current-inputmovie object to lsmv file: you can save the input member alone with movie.serialize. Maybe, you can save the complete lsmv with ZIPWRITER and this file. Saving/Loading a state:
Language: lua

local default_base = settings.get("slotpath") local slot = 1 -- save: local cmd = string.format([[save-state %s/movieslot%d.lsmv]], default_base, slot) -- hack local cmd = "save-state $SLOT:" .. slot -- better exec(cmd) -- load local cmd = string.format([[load-state %s/movieslot%d.lsmv]], default_base, slot) local cmd = "load-state $SLOT:" .. slot -- better exec(cmd)