81

Croissant, a Lua REPL and Debugger

 5 years ago
source link: https://www.tuicool.com/articles/hit/RrMFz2V
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

AZ7N7ny.png!web

Croissant

A Lua REPL and debugger implemented in Lua

7n26N3Z.gif

Note:Croissant is in active development.

Croissant is based on sirocco .

Features

  • Syntax highlighting
  • Code parsed as you type
  • Persistent history
  • Multiline
  • Formatted returned values
  • Basic auto-completion
  • Contextual help ( C-h or M-h on an identifier)
  • Debugger

Planned

  • Customization: keybinding, theme, etc.
  • Multiple Lua versions support

Installation

Requirements:

  • Lua 5.3
  • luarocks >= 3.0 ( Note: hererocks -rlatest will install 2.4, you need to specify it with -r3.0 )
luarocks install croissant

Usage

# Make sure lua/luarocks binaries are in your $PATH (~/.luarocks/bin)
croissant [-h] [<input>] [<arguments>] [-d [<debugger>] ...]
  • <input> : a lua file to run or debug. If not provided, croissant will run the REPL.
  • <arguments> : arguments to pass to the <input> script
  • --debugger -d --break -b [file.lua:line] ... : runs croissant in debugger mode and optionally sets breakpoints
  • --help -h : shows help message

Debugger

BBRZjm2.gif

Using the cli

croissant filetodebug.lua -d

This will start croissant in debugger mode. You can then add some breakpoints with the breakpoint command and start your script with the run command.

In your code

Alternatively, you can require the debugger in your script where you want to break:

require "croissant.debugger"()

Commands

Croissant looks at the first word of your entry and runs any command it matches. It'll otherwise runs the entry as Lua code in the current frame context. If empty, croissant executes the previous repeatable command.

  • help [<command>] : prints general help or help about specified command
  • run : starts your script
  • args <argument> ... : set arguments to pass to your script
  • breakpoint <where> [<when>] : add a new breakpoint at <where> (can be line number in current file, file.lua:line or a function name) if <when> (lua code evaluated in the breakpoint context) is true or absent
  • condition <#id> <when> : change breaking condition of breakpoint #id
  • delete <#id> : delete breakpoint #id
  • enable <#id> : enable breakpoint #id
  • disable <#id> : disable breakpoint #id
  • clear : delete breakpoints
  • info <what> :
    breakpoints
    locals
    
  • step (repeatable): step in the code
  • next (repeatable): step in the code going over any function call
  • out (repeatable): will break after leaving the current function
  • up (repeatable): go up one frame
  • down (repeatable): go down one frame
  • continue (repeatable): continue until hitting a breakpoint. If no breakpoint are specified, clears debug hooks
  • eval <code> : runs code (useful to disambiguate from debugger commands)
  • exit : quit
  • where : prints code around the current line. Is ran for you each time you step in the code or change frame context

7juM7ny.png!web

  • trace : prints current stack trace and highlights current frame.

UVJj2iY.png!web

Configuration

You can customize some aspect of croissant by writing a ~/.croissantrc lua file. Here are the default values than you can overwrite:

return {
    -- Default prompt
    prompt = "→ ",
    -- Prompt used when editing multiple lines of code
    continuationPrompt = ".... ",

    -- Maximum amount of remembered lines
    -- Croissant manages two history file: one for the repl (~/.croissant_history),
    -- one for the debugger (~/.croissant_debugger_history)
    historyLimit = 1000,

    -- Syntax highlighting colors
    -- Available colors are: black, red, green, yellow, blue, magenta, cyan, white.
    -- They can also be combined with modifiers: bright, dim, underscore, blink, reverse, hidden
    syntaxColors = {
        constant   = { "bright", "yellow" },
        string     = { "green" },
        comment    = { "dim", "cyan" },
        number     = { "yellow" },
        operator   = { "yellow" },
        keywords   = { "bright", "magenta" },
        identifier = { "blue" },
    },

    -- Nesting limit at which croissant will stop when pretty printing a table
    dumpLimit = 5,
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK