Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/trepl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/th
diff options
context:
space:
mode:
authorClement Farabet <clement.farabet@gmail.com>2013-07-09 07:46:26 +0400
committerClement Farabet <clement.farabet@gmail.com>2013-07-09 07:46:26 +0400
commit1080f8f9d3f4482ee914606b4ebf3c01d0d95b7d (patch)
tree7ef63a35ed0c14aa662cf0cf9699745caac9a415 /th
parent2d2ddcfdcd4ba0028bdf3fc07854b077d850195b (diff)
Revamp of the repl.
Diffstat (limited to 'th')
-rw-r--r--th67
1 files changed, 67 insertions, 0 deletions
diff --git a/th b/th
new file mode 100644
index 0000000..d406a8f
--- /dev/null
+++ b/th
@@ -0,0 +1,67 @@
+#!/usr/bin/env torch-lua
+
+-- help
+local help = [==[
+Usage: th [options] [script.lua [arguments]]
+
+Options:
+ -lname load library name
+ -h,--help print this help
+ -i,--interactive enter the REPL after executing a script ]==]
+
+-- parse arguments
+local run,interactive,progargs
+for _,arg in ipairs(arg) do
+ -- load libraries
+ local _,_,lib = arg:find('^%-l(.*)')
+ if lib then
+ local ok = pcall(require,lib)
+ if not ok then
+ print('could not load ' .. lib .. ', skipping')
+ end
+ elseif progargs then
+ -- program args
+ table.insert(progargs,arg)
+ else
+ -- option?
+ local _,_,option = arg:find('^%-%-(.*)')
+ local shortopt
+ if not option then
+ _,_,shortopt = arg:find('^%-(.*)')
+ end
+ if option or shortopt then
+ -- help
+ if shortopt == 'h' or option == 'help' then
+ print(help)
+ os.exit()
+ elseif shortopt == 'i' or option == 'interactive' then
+ interactive = true
+ else
+ -- unknown
+ print('Error: unrecognized flag --' .. option)
+ print(help)
+ os.exit()
+ end
+ else
+ -- exec program
+ run = arg
+ progargs = {}
+ end
+ end
+end
+
+-- load repl
+local repl = require 'trepl'
+
+-- run program
+if run then
+ -- set prog args:
+ arg = progargs
+ -- run
+ dofile(run)
+ -- quit by default
+ if not interactive then os.exit() end
+end
+
+-- start repl
+repl()