syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
How to attach debugger to Lua script?

When I use an interpreted language I learn early on how to attach a debugger to a running script.

In Lua, a quick way to access something similar is to run a Lua script but then ask Lua to keep the interpreter active rather than return control to the shell.

I do this by supplying a -i command line option when I run the script.

Here is a screendump-demo of me running a script which sets 3 variables.

I use -i to keep the variables around when the script is finished so I can then interact with them:
dan@hp ~/ks/b/lua $ 
dan@hp ~/ks/b/lua $ cat debugme.lua 
-- ~/ks/b/lua/debugme.lua

-- Demo:
-- lua -i debugme.lua

a = 1
b = 2.2
c = 33.33
dan@hp ~/ks/b/lua $ 
dan@hp ~/ks/b/lua $ lua -i debugme.lua
Lua 5.3.0  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> c
33.33
> b
2.2
> a
1
> 
> os.exit()
dan@hp ~/ks/b/lua $ 
dan@hp ~/ks/b/lua $ 

syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me