From 5f2f8f86fb5b6ed6826dcdb1600acccd3fdfd5e8 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Thu, 19 Mar 2020 10:59:20 +0100 Subject: [PATCH] Add terminal calculator script --- bin/= | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 bin/= diff --git a/bin/= b/bin/= new file mode 100755 index 0000000..a702bb2 --- /dev/null +++ b/bin/= @@ -0,0 +1,31 @@ +#!/usr/bin/env luajit + +local moonscript = pcall(function() + require 'moonscript.base' +end) + +if moonscript then + parse = require('moonscript.base').to_lua +else + parse = function(...) return ... end +end + +local function run(line, name, addreturn, prefix) + if addreturn~=false then + line = "return ("..line..")" + end + if prefix then io.write(prefix, ' ') end + print(assert(load(parse(line), name, 't', math))()) +end + +local line = table.concat({...}, ' ') + +if line == '' then + for line in io.stdin:lines() do + run(line, "User Input", true, "=") + end +elseif line == '-' then + run(io.stdin:read("*a"), "User Input", false, "=") +else + run(line, "Commandline") +end