Interactive REPL Guide

Master Hype's Interactive Development Environment

The REPL (Read-Eval-Print Loop) is your playground for rapid Lua development, API exploration, and interactive debugging. Available in both TUI and simple modes.

๐Ÿš€ Quick Start

Hype REPL v1.9.0
Type :help for commands
hype> 2 + 2
4
hype> user = {name = "Alice", role = "Developer"}
{ ["name"] = "Alice", ["role"] = "Developer" }
hype> crypto.sha256("hello")
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
hype> _
# Launch TUI REPL (default) ./hype repl # Launch simple REPL ./hype repl --simple # With plugins ./hype repl --plugins fs@1.0.0,json

โŒจ๏ธ Keyboard Shortcuts

Key Action Description
โ†‘ / โ†“ Navigate history Browse through previous commands
Ctrl + A Start of line Move cursor to beginning
Ctrl + E End of line Move cursor to end
Ctrl + U Clear line Delete current input
Ctrl + L Clear screen Clear output panel
Tab Auto-complete Complete function/variable names
PageUp / PageDown Scroll output Navigate through output history
Ctrl + D Exit REPL Quit the session

๐ŸŽฏ Special Commands

-- Show help
hype> :help
Available commands:
  :help, :h     - Show this help
  :clear, :c    - Clear output
  :exit, :q     - Exit REPL
  :history      - Show command history
  :h=N          - Recall command N

-- Clear the output panel
hype> :clear

-- Exit the REPL
hype> :exit
-- View command history
hype> :history
Command History:
  1: 2 + 2
  2: user = {name = "Alice"}
  3: crypto.sha256("test")
  4: http.get("https://api.example.com")

-- Recall command 2
hype> :h=2
Recalled: user = {name = "Alice"}

-- Modify and execute
hype> user = {name = "Alice", updated = os.time()}
-- Load and execute a file
hype> :load utils.lua
Loaded: utils.lua

-- Alternative method
hype> dofile("config.lua")

-- Load with error handling
hype> ok, err = pcall(dofile, "script.lua")
hype> if not ok then print("Error:", err) end

๐Ÿ”ง Working with Modules

๐Ÿ–ฅ๏ธ

TUI Module

-- Create app
app = tui.newApp()

-- Build interface
text = tui.newTextView("Hello")
text:SetBorder(true)

-- Run in background
go(function() 
    app:SetRoot(text, true)
    app:Run() 
end)
๐ŸŒ

HTTP Module

-- Make request
resp = http.get("https://api.github.com")
print(resp.status_code)

-- Start server
server = http.newServer()
server:handle("/", function(req, res)
    res:json({msg = "Hello"})
end)
go(function() server:listen(8080) end)
๐Ÿ—„๏ธ

Database Module

-- Open database
db = kv.open(":memory:")
db:open_db("test")

-- Store and retrieve
db:put("test", "key", "value")
result = db:get("test", "key")
print(result)
๐Ÿ”

Crypto Module

-- Generate hash
hash = crypto.sha256("secret")

-- Generate keys
key = crypto.generate_jwk("ES256")
pub = crypto.jwk_to_public(key)

-- Sign and verify
sig = crypto.sign(key, "data")
valid = crypto.verify(pub, "data", sig)

๐Ÿ’ก Advanced Techniques

Multi-line Input

-- Define complex functions
hype> function process_data(items)
    local results = {}
    for i, item in ipairs(items) do
        if item.active then
            table.insert(results, {
                id = item.id,
                processed = true,
                timestamp = os.time()
            })
        end
    end
    return results
end

-- Test the function
hype> data = {{id=1, active=true}, {id=2, active=false}}
hype> process_data(data)

Performance Testing

-- Benchmark function
function benchmark(fn, iterations)
    iterations = iterations or 1000
    local start = os.clock()
    for i = 1, iterations do
        fn()
    end
    local elapsed = os.clock() - start
    return string.format("%d ops in %.3fs (%.0f ops/sec)", 
        iterations, elapsed, iterations/elapsed)
end

-- Test performance
hype> benchmark(function() crypto.sha256("test") end, 10000)
"10000 ops in 0.125s (80000 ops/sec)"

Interactive Debugging

-- Create debug helper
function inspect(obj, depth)
    depth = depth or 0
    if depth > 3 then return "..." end
    
    if type(obj) ~= "table" then
        return tostring(obj)
    end
    
    local parts = {}
    for k, v in pairs(obj) do
        local key = tostring(k)
        local value = inspect(v, depth + 1)
        table.insert(parts, key .. " = " .. value)
    end
    
    return "{" .. table.concat(parts, ", ") .. "}"
end

-- Use it
hype> complex = {a = {b = {c = "deep"}}, x = 42}
hype> print(inspect(complex))

๐Ÿš€ Common Workflows

๐Ÿ”

API Exploration

  • Load module: server = http.newServer()
  • Explore methods: for k,v in pairs(getmetatable(server).__index) do print(k) end
  • Test functionality: server:handle("/", handler)
  • Run in background: go(function() server:listen(8080) end)
  • Verify: http.get("http://localhost:8080")
๐Ÿงช

Testing Code

  • Define test data
  • Write test function
  • Run multiple iterations
  • Check edge cases
  • Save working code
๐Ÿ”ง

Plugin Development

  • Create plugin table: plugin = {}
  • Add functions: function plugin.method() ... end
  • Test thoroughly in REPL
  • Save to file: save_plugin("myplugin.lua", plugin)
  • Load and verify: dofile("myplugin.lua")
๐Ÿ›

Debugging Scripts

  • Load problematic script
  • Add print statements
  • Inspect variables
  • Test functions individually
  • Fix and re-test

๐Ÿ”ง Troubleshooting

REPL Won't Start

# Check version (needs v1.9.0+)
./hype version

# Try simple mode
./hype repl --simple

# Check for errors
./hype repl 2>&1 | less

Memory Issues

-- Clear large variables
hype> bigdata = nil
hype> collectgarbage()

-- Check memory usage
hype> collectgarbage("count")
1234.56  -- KB used

-- Force full collection
hype> collectgarbage("collect")

Hanging Operations

-- Use Ctrl+C to interrupt

-- Or use timeout wrapper
function timeout(fn, seconds)
    local co = coroutine.create(fn)
    local start = os.time()
    while coroutine.status(co) ~= "dead" do
        if os.time() - start > seconds then
            error("Timeout after " .. seconds .. "s")
        end
        coroutine.resume(co)
    end
end

Output Not Visible

-- Clear output panel
hype> :clear

-- Check if output is being captured
hype> print("Test output")
hype> io.flush()

-- Try direct write
hype> io.write("Direct output\n")

๐Ÿ“š Additional Resources

๐Ÿ“–

Full Guide

Read the complete REPL documentation with all details and examples

View Markdown Guide
๐ŸŽฏ

API Reference

Explore all Hype modules and their methods in detail

Browse API Docs
๐Ÿ’ป

Examples

See real-world examples of Hype applications

View Examples
๐Ÿ”Œ

Plugins

Learn how to create and use plugins in the REPL

Plugin Guide