Tool-assisted game movies
When human skills are just not enough

Lua Scripting

>> ES | Español
>> RU | Русский

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.

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):

  --Declarations here

  while true do


  --Declarations here
  function fn()
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[1] 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).


Using MHS for emulators without lua embedded

L. Spiro's Memory Hacking Software

More information

Site Links

External Links


Combined RSS Feed
LuaScripting last edited by ThunderAxe31 on 2017-09-18 16:55:30
Page info and history | Latest diff | List referrers | View Source