72 lines
2.0 KiB
Plaintext
72 lines
2.0 KiB
Plaintext
#!/usr/bin/env luash
|
|
-- REPL Demo: Showcasing interactive features
|
|
|
|
print("🎮 Luash Interactive Shell Demo")
|
|
print("===============================\n")
|
|
|
|
print("Luash now supports a full interactive REPL!")
|
|
print("Start it with: ./luash -i")
|
|
print()
|
|
|
|
print("🔥 REPL Features:")
|
|
print("✓ All luash preprocessing ($VAR, `commands`, #{interpolation})")
|
|
print("✓ Multiline input (functions, loops, if blocks)")
|
|
print("✓ Command history")
|
|
print("✓ Special dot commands (.help, .exit, .clear, .history)")
|
|
print("✓ Real-time expression evaluation")
|
|
print()
|
|
|
|
print("📝 Example REPL Session:")
|
|
examples = {
|
|
'print("Hello " .. $USER)',
|
|
'$GREETING = "Hello from REPL"',
|
|
'files = `ls *.luash | wc -l`',
|
|
'print("Found " .. files .. " luash files")',
|
|
'host = "google.com"',
|
|
'status = `ping -c 1 #{host} >/dev/null && echo "ok"`',
|
|
'print(host .. " is " .. status)',
|
|
'',
|
|
'-- Multiline example:',
|
|
'for i = 1, 3 do',
|
|
' print("Iteration: " .. i)',
|
|
'end',
|
|
'',
|
|
'-- Function definition:',
|
|
'function greet(name)',
|
|
' return "Hello, " .. name .. "!"',
|
|
'end',
|
|
'',
|
|
'print(greet($USER))'
|
|
}
|
|
|
|
for i, example in ipairs(examples) do
|
|
if example == "" then
|
|
print()
|
|
elseif example:match("^%-%-") then
|
|
print(example)
|
|
else
|
|
print("luash> " .. example)
|
|
end
|
|
end
|
|
|
|
print()
|
|
print("🚀 Try it now: ./luash -i")
|
|
print(" Or: ./luash --interactive")
|
|
print()
|
|
|
|
print("💡 The REPL supports:")
|
|
print(" • Environment variables: $HOME, $USER, etc.")
|
|
print(" • Shell commands: `ls`, `pwd`, `date`")
|
|
print(" • Variable interpolation: `echo #{variable}`")
|
|
print(" • Interactive commands: !git status")
|
|
print(" • Full Lua: functions, loops, tables, etc.")
|
|
print(" • Command history and editing")
|
|
print()
|
|
|
|
print("✨ Perfect for:")
|
|
print(" • Interactive system administration")
|
|
print(" • Exploring file systems and processes")
|
|
print(" • Quick shell command prototyping")
|
|
print(" • Learning luash syntax")
|
|
print(" • Debugging shell scripts")
|