Lua scripting is an extremely useful tool when TASing. Although some programming knowledge is required, the user has power over things like game screen display, inputs, and memory. The following are some common applications, though the possibilities are endless.
- Displaying helpful information on screen.
- Eliminating tedious repetition.
- Creating specific circumstances for testing.
- Brute forcing a solution.
Snes9x was the first emulator modified to support Lua, back in 2008. Now, the following emulators support Lua: FCEU(X), BizHawk, lsnes, Snes9x, Gens, VBA, Final Burn Alpha, PCSX, DeSmuME, PCEjin, VBjin, and JPC-RR.
In order to integrate Lua, a number of emulator-specific functions were created, which form the emulator-specific Lua API, enabling control of the emulator. However, one is not limited only to emulator-specific Lua functions. Anyone can use any function in the main Lua API, including file I/O. Thus the emulator can be scripted to communicate with, say, text files!
How to run a Lua script
To run a Lua script, copy the code and place it in a text editor. Name the file as "file.lua" or anything ending in "lua". When saving from Notepad in Windows, you need to put quotes around the name "file.lua"
Then go to the emulator and run the Lua file. Some emulators have a Lua script window; the Lua script will automatically begin when you load it.
To become familiar with Lua, check out the Lua 5.1 manual
. It covers how the Lua language works, and the main Lua API.
In the emulator, it is desirable to have a main execution loop. The main execution loop can take one of two forms (-- means the rest of the line is a comment):
while true do
The second one is technically a function which is called whenever there is an update to the display (which is supposed to be every frame but is also called in some emulators
during when the display is paused). The second form is required for DeSmuME since the first form is working in a different way than most other emulators (see this topic
for more information).
- To be covered
- savestate.create , savestate.load , savestate.save
- io.write , io.output
Using MHS for emulators without lua embedded
LuaScripting last edited by Masterjun
on 2017-02-27 11:58:27Page info and history | Latest diff | List referrers | View Source